wsl2子系統簡介
官方文檔:https://docs.microsoft.com/en-us/windows/wsl/
WSL(Windows Subsystem for Linux)使開發人員可以直接在未經修改的Windows上運行GNU / Linux環境-包括大多數命令行工具,實用程序和應用程序,而無需傳統虛擬機或雙啓動設置的開銷。
WSL 2是用於Linux的Windows子系統體系結構的新版本,WSL 2使用了全新的體系結構,該體系結構受益於運行真正的Linux內核。
wsl2安裝
官方文檔:https://docs.microsoft.com/en-us/windows/wsl/install-win10
安裝要求:Windows 10, updated to version 2004, Build 19041 or higher
PS C:\Users\Administrator> Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
WindowsProductName WindowsVersion OsHardwareAbstractionLayer
------------------ -------------- --------------------------
Windows 10 Pro 2004 10.0.19041.1
cmd中執行powershell命令,開啓Windows Subsystem for Linux特性
powershell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
開啓Virtual Machine Platform特性
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
重啓以更新到wsl2
restart-computer
設置WSL 2爲默認版本
wsl --set-default-version 2
首選需要更新 WSL 2 Linux 內核:https://docs.microsoft.com/zh-cn/windows/wsl/wsl2-kernel
然後重新設置WSL 2爲默認版本
wsl --set-default-version 2
應用商店搜索並安裝linux發行版本,以ubuntu爲例,安裝完成後可以以root登錄:
ubuntu@desktop:~$ sudo -i
[sudo] password for ubuntu:
Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.19.104-microsoft-standard x86_64)
確認wsl版本
wsl --list --verbose
關閉和開啓
#啓動默認的WSL2 和 Linux
$wsl
#關閉所有正在運行的 Linux 和 WSL 2
wsl --shutdown
問題排查
https://docs.microsoft.com/zh-cn/windows/wsl/wsl2-faq
當前vmware workstation 15.5.5以及virtualbox 6.0已經能夠兼容基於 Hyper-V的WSL2,但是當勾選虛擬化引擎相關功能時vmware依然無法與Hyper-V共存。提示vmware workstation 在此主機上不支持嵌套虛擬化。
vmware workstation does not support nested virtualization on this host. module ‘monitor mode’ power on failed
目前的解決方法只能是兩者選一,參考:https://communities.vmware.com/thread/634674
#如果使用vmware在powershell中執行以下命令然後重啓系統
bcdedit /set hypervisorlaunchtype off
#如果使用hyper-v執行以下命令開啓
bcdedit /set hypervisorlaunchtype auto