安裝wsl
啟用適用于 Linux 的 Windows 子系統
以管理員身份打開 PowerShell (> PowerShell > 右鍵單擊 > 以管理員身份運行) 并輸入以下命令,然后重啟
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
啟用虛擬機功能
以管理員身份打開 PowerShell 并運行,然后重啟
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
下載 Linux 內核更新包
wsl_update_x64.msi
將 WSL 2 設置為默認版本
wsl --set-default-version 2
更新 WSL
wsl --update
wsl基本命令
關機
wsl --shutdown
終止
wsl --terminate
更新 WSL
wsl --update
關閉wsl
wsl --shutdown
導出wsl
wsl --export Ubuntu-20.04 G:\WSL\myUbuntu.tar
注銷原來的wsl
wsl --unregister Ubuntu-20.04
列出已安裝的 Linux 分發版
wsl --list --verbose
wsl -l -v
恢復原來的用戶名
myUsername=bo
echo -e “[user]\ndefault=$myUsername” >> /etc/wsl.conf
導入已有vhdx文件
wsl --import-in-place
wsl --import-in-place Ubuntu20.04 D:\wslubuntu\backup\ext4.vhdx
導入新的wsl
wsl --import WSL名稱 安裝目錄 WSL壓縮包文件地址
wsl --import Ubuntu-20.04 D:\wslubuntu\ D:\wslubuntu\ubuntu.tar --version 2
wsl config配置
Windows 文件資源管理器并在地址欄中輸入 %UserProfile%
。 該目錄路徑應類似于: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# Specify the modules VHD for the custum Linux kernel to use with your installed distros.
kernelModules=C:\\temp\\modules.vhdx# 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 on default connection to bind WSL 2 localhost to Windows localhost. Setting is ignored when networkingMode=mirrored
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# Enable experimental features
[experimental]
sparseVhd=true