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
1 2 3 4 5 | 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特性
1 2 | powershell dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart |
开启Virtual Machine Platform特性
1 | dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart |
重启以更新到wsl2
1 | restart-computer |
设置WSL 2为默认版本
1 | wsl --set-default-version 2 |
首选需要更新 WSL 2 Linux 内核:https://docs.microsoft.com/zh-cn/windows/wsl/wsl2-kernel
然后重新设置WSL 2为默认版本
1 | wsl --set-default-version 2 |
应用商店搜索并安装linux发行版本,以ubuntu为例,安装完成后可以以root登录:
1 2 3 | ubuntu@desktop:~$ sudo -i [sudo] password for ubuntu: Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.19.104-microsoft-standard x86_64) |
确认wsl版本
1 | wsl --list --verbose |
关闭和开启
1 2 3 4 5 | #启动默认的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 在此主机上不支持嵌套虚拟化。
1 | vmware workstation does not support nested virtualization on this host. module ‘monitor mode’ power on failed |
目前的解决方法只能是两者选一,参考:https://communities.vmware.com/thread/634674
1 2 3 4 5 | #如果使用vmware在powershell中执行以下命令然后重启系统 bcdedit /set hypervisorlaunchtype off #如果使用hyper-v执行以下命令开启 bcdedit /set hypervisorlaunchtype auto |