Wslconfig 的配置设置
Wslconfig 文件为以 WSL 2 运行的所有 Linux 分发全局配置设置。 (,请参阅 wsl) 。
有关在何处存储 wslconfig 文件的信息,请参阅 wslconfig 。
备注
使用 .wslconfig
的全局配置选项仅适用于在 Windows 版本19041及更高版本中作为 WSL 2 运行的分发。 请记住,可能需要运行 wsl --shutdown
来关闭 WSL 2 VM,然后重启 WSL 实例以使这些更改生效。
此文件可以包含以下选项,这些选项会影响可 WSL 2 分发的 VM:
节标签:[wsl2]
钥匙 | 值 | 默认 | 说明 |
---|---|---|---|
内核 (kernel) | 细绳 | Microsoft 内置内核提供的收件箱 | 自定义 Linux 内核的绝对 Windows 路径。 |
内存 | 大小 | Windows 上总内存的 50% 或 8GB,以较小者为准;在 20175 之前的版本上:Windows 上总内存的 80% | 要分配给 WSL 2 VM 的内存量。 |
处理器 | 数字 | Windows 上相同数量的处理器 | 要分配给 WSL 2 VM 的处理器数量。 |
localhost转发 | 布尔值 | true | 一个布尔值,用于指定绑定到 WSL 2 VM 中的通配符或 localhost 的端口是否应可通过 localhost:port 从主机连接。 |
内核命令行 | 字符串 | 空白 | 其他内核命令行参数。 |
交换 | 大小 | Windows 上 25% 的内存大小四舍五入到最接近的 GB | 要向 WSL 2 VM 添加的交换空间量,0 表示无交换文件。 交换存储是内存需求超过硬件设备限制时使用的基于磁盘的 RAM。 |
交换文件 | 字符串 | %USERPROFILE%\AppData\Local\Temp\swap.vhdx | 交换虚拟硬盘的绝对 Windows 路径。 |
页面报告 | 布尔值 | true | 默认设置true 允许Windows回收分配给 WSL 2 虚拟机的未使用内存。 |
gui应用程序 | 布尔* | true | 一个布尔值,用于在 WSL 中打开或关闭对 GUI 应用程序 (WSLg) 的支持。 仅适用于Windows 11。 |
调试控制台 | 布尔* | false | 一个布尔值,用于在 WSL 2 发行版实例启动时打开显示 dmesg 内容的输出控制台窗口。 仅适用于Windows 11。 |
嵌套虚拟化 | 布尔* | true | 启用或关闭嵌套虚拟化的布尔值,使其他嵌套 VM 在 WSL 2 中运行。 仅适用于Windows 11。 |
vmIdleTimeout | 数字* | 60000 | VM 在关闭之前处于空闲状态的毫秒数。 仅适用于Windows 11。 |
具有 path
值的条目必须是带有转义反斜杠的 Windows 路径,例如:C:\\Temp\\myCustomKernel
具有 size
值的条目必须是后跟单位的大小,例如 8GB
或 512MB
。
值类型后 * 的条目仅在 Windows 11。
示例 .wslconfig 文件
下面的示例 .wslconfig
文件演示了一些可用的配置选项。 此示例中的文件路径为 C:\Users\<UserName>\.wslconfig
。
# Settings apply across all Linux distros running on WSL 2 [wsl2] # Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB memory=4GB # Sets the VM to use two virtual processors processors=2 # Specify a custom Linux kernel to use with your installed distros. The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel kernel=C:\\temp\\myCustomKernel # Sets additional kernel parameters, in this case enabling older Linux base images such as Centos 6 kernelCommandLine = vsyscall=emulate # Sets amount of swap storage space to 8GB, default is 25% of available RAM swap=8GB # Sets swapfile path location, default is %USERPROFILE%\AppData\Local\Temp\swap.vhdx swapfile=C:\\temp\\wsl-swap.vhdx # Disable page reporting so WSL retains all allocated memory claimed from Windows and releases none back when free pageReporting=false # Turn off default connection to bind WSL 2 localhost to Windows localhost localhostforwarding=true # Disables nested virtualization nestedVirtualization=false # Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging debugConsole=true