背景
在 Windows 10 专业版上安装 Docker Desktop 时,执行 wsl --set-version Ubuntu-24.04 2 报错:
请启用虚拟机平台 Windows 功能并确保在 BIOS 中启用虚拟化
本文记录了完整的排查与解决过程,适用于 Windows 10/11 安装 WSL2 时遇到类似问题的用户。
一、系统现状检查
1.1 检查 WSL 安装状态
powershell
wsl --status
wsl --list --verbose
结果:
- WSL 已安装,Ubuntu-24.04 存在
- 当前版本为 WSL 1
- Docker Desktop 需要 WSL 2
1.2 检查操作系统
OS Name: Microsoft Windows 10 专业版
OS Version: 10.0.19043 N/A Build 19043
✅ Windows 10 专业版,支持 WSL2
二、问题排查过程
2.1 检查虚拟化相关功能
powershell
# 检查 Hyper-V
systeminfo | findstr /C:"Hyper-V"
# 检查虚拟机平台是否启用
dism.exe /online /get-features | findstr /C:"VirtualMachinePlatform"
排查结果:
| 检查项 | 状态 | 说明 |
|---|---|---|
| BIOS 虚拟化 | ✅ 已在固件中启用 | Virtualization Enabled In Firmware: Yes |
| Hyper-V | ✅ 已启用 | State: Enabled |
| WSL 功能 | ✅ 已启用 | Microsoft-Windows-Subsystem-Linux |
| 虚拟机平台 | ✅ 已启用 | VirtualMachinePlatform |
所有功能都已开启,但仍然报错。
2.2 检查 Hypervisor 启动类型
powershell
bcdedit | findstr /C:"hypervisorlaunchtype"
发现根本原因:
hypervisorlaunchtype Off
这就是问题所在! hypervisor 被设置为 Off,导致 WSL2 无法启动虚拟机。
三、解决方案
3.1 开启 Hypervisor
以管理员身份运行 PowerShell,执行:
powershell
bcdedit /set hypervisorlaunchtype auto
执行结果:
The operation completed successfully.
3.2 开启虚拟机平台功能
如果上述命令无效,还需要确保虚拟机平台功能已开启:
powershell
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
执行结果:
操作成功完成。
3.3 重启电脑
必须重启! 设置才能生效。
3.4 转换 WSL 到版本 2
重启后执行:
powershell
wsl --set-version Ubuntu-24.04 2
等待几分钟完成转换。
四、完整流程回顾
1. wsl --status # 检查 WSL 状态
2. wsl --list --verbose # 查看各发行版版本
3. systeminfo | findstr "Hyper-V" # 检查虚拟化
4. bcdedit | findstr hypervisorlaunchtype # 检查 hypervisor ← 关键步骤!
5. bcdedit /set hypervisorlaunchtype auto # 开启 hypervisor
6. 重启电脑
7. wsl --set-version Ubuntu-24.04 2 # 转换到 WSL 2
五、排查工具速查
| 命令 | 作用 |
|---|---|
wsl --status |
查看 WSL 状态和默认版本 |
wsl --list --verbose |
查看所有发行版的 WSL 版本 |
wsl --update |
更新 WSL 内核 |
| `systeminfo | findstr "Hyper-V"` |
| `bcdedit | findstr hypervisorlaunchtype` |
dism.exe /online /get-features |
查看所有 Windows 可选功能 |
bcdedit /set hypervisorlaunchtype auto |
强制开启 hypervisor |
六、可能的其他干扰因素
6.1 VirtualBox 与 Hyper-V 共存
本系统同时安装了 VirtualBox 和 Hyper-V,两者理论上存在冲突。但 Hyper-V 优先级更高,WSL2 仍可正常运行。
如果遇到 VirtualBox 无法使用的问题,可考虑:
- 卸载 VirtualBox,使用 Hyper-V 替代
- 或使用 VMware Workstation Pro(支持 Hyper-V 共存)
6.2 Windows 家庭版用户
Windows 10 家庭版没有 Hyper-V,但支持 WSL2。安装流程相同,同样需要开启虚拟机平台。
七、总结
本次问题的根本原因: hypervisorlaunchtype 被设置为 Off,导致 Windows 无法启动虚拟机平台,WSL2 无法运行。
解决核心命令:
powershell
bcdedit /set hypervisorlaunchtype auto
此命令将 Hyper-V 的虚拟机监控程序启动类型设置为 Auto,从而允许 WSL2 使用虚拟化功能。