本文最后更新于 2025年11月4日
引言:
在Windows 11中运行各种虚拟化软件时,经常会遇到虚拟化冲突的问题,这篇文章咱们就来分析一下原因。我的系统是Windows 11 24H2专业版,可能在有些地方与你们有所不同。
冲突原因:
我们首先要明白,Windows自带的虚拟化环境—— Hyper-V 和WSL 2是有关系的,WSL 2 是基于 Hyper-V 技术实现的。而 VMware 和 Oracle VirtualBox 依赖于CPU的硬件虚拟化技术,英特尔的叫Intel VT-x,AMD的叫AMD-V。这两个软件是不依赖于Windows 自带的Hyper-V组件的。
并且由于 Intel VT-x/AMD-V 技术在同一时间只能被一个 Hypervisor(虚拟化内核)使用,若开启了 Windows 的 Hyper-V,VMware 和 VirtualBox 可能无法正常启动虚拟机,或只能以 “兼容模式” 运行(性能下降)。
也就是说:
CPU 的硬件虚拟化扩展(VT-x / AMD-V)在同一时刻只能被一个 Hypervisor 独占使用。
当Hyper-V被启用后,硬件虚拟化即被它占用,此时VMware Workstation / VirtualBox再尝试访问硬件虚拟化时就会被拦截,因此只能使用 软件虚拟化或兼容模式 运行,从而导致性能下降。虚拟机卡断处了分配的硬件资源不够外,很可能就是你同时启用了Hyper-V
解决方案:
明白了原理解决起来就很简单了,我这里提供两个脚本,Windows 11使用应该都没问题(家庭中文版可能会提示功能不存在,忽略即可),在桌面上新建txt文件,复制下面的代码粘贴进去,重命名为bat格式的文件,以管理员身份运行后重启电脑
也可以直接到Github下载:项目地址
适用于 Docker Desktop(WSL2)/WSL2
docker_wsl2_mode.bat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| @echo off chcp 65001 >nul echo === 启用 Docker + WSL2 模式 === echo. echo 适用软件: echo - Docker Desktop (WSL2) echo - WSL2 (Ubuntu / Debian / Kali 等子系统) echo - Visual Studio Code Remote - WSL echo. echo 正在启用虚拟化相关功能...
dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /norestart dism /online /enable-feature /featurename:VirtualMachinePlatform /norestart dism /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /norestart dism /online /enable-feature /featurename:HypervisorPlatform /norestart
bcdedit /set hypervisorlaunchtype auto
echo. echo ✅ 已启用 Docker + WSL2 模式,请重启系统生效。 pause
|
适用于 VMware / VirtualBox / 雷电模拟器 / 腾讯应用宝
vm_emulator_mode.bat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| @echo off chcp 65001 >nul echo === 启用 VMware / VirtualBox / 模拟器 模式 === echo. echo 适用软件: echo - VMware Workstation echo - VirtualBox echo - 雷电模拟器 echo - 腾讯应用宝 echo. echo 正在禁用与 Hyper-V 相关的功能...
dism /online /disable-feature /featurename:Microsoft-Hyper-V-All /norestart dism /online /disable-feature /featurename:VirtualMachinePlatform /norestart dism /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux /norestart dism /online /disable-feature /featurename:HypervisorPlatform /norestart dism /online /disable-feature /featurename:Windows-Hypervisor-Platform /norestart
bcdedit /set hypervisorlaunchtype off
echo. echo ✅ 已启用 VMware / VirtualBox / 模拟器 模式,请重启系统生效。 pause
|