Loading

Windows 平台 WSL1/WSL2、Hyper-V、虚拟机平台与 VMware Workstation 的关系及冲突处理

Windows 平台 WSL1/WSL2、Hyper-V、虚拟机平台与 VMware Workstation 的关系及冲突处理

一、涉及组件说明

Windows 上和虚拟化相关的可选功能有以下几个,名称接近但作用不同:

组件名 英文名 作用
Hyper-V Hyper-V 完整的微软虚拟化平台,含管理工具与虚拟交换机
虚拟机平台 Virtual Machine Platform(VMP) Hyper-V 的运行时子集,WSL2、WSA、Windows 沙盒依赖它
Windows 虚拟机监控程序平台 Windows Hypervisor Platform(WHP) 面向第三方虚拟化产品(VMware、VirtualBox、QEMU 等)的 API
适用于 Linux 的 Windows 子系统 Windows Subsystem for Linux(WSL) WSL 主体,控制 wsl.exe、发行版管理等

关键点:只要启用了「虚拟机平台」,Hyper-V 的底层 Hypervisor 就已经加载并接管了 CPU 虚拟化指令,无论「Hyper-V」这一项是否勾选。

二、WSL1 与 WSL2 的实现差异

  • WSL1:系统调用翻译层,不使用虚拟化技术,不依赖虚拟机平台。
  • WSL2:在轻量级实用工具虚拟机(LCOW)中运行完整 Linux 内核,依赖虚拟机平台,因而依赖 Hyper-V 底层 Hypervisor。

因此从功能开关角度看:

  • 只使用 WSL1,最小依赖只需要 Microsoft-Windows-Subsystem-Linux
  • 使用 WSL2,必须启用 Microsoft-Windows-Subsystem-LinuxVirtualMachinePlatform

三、VMware Workstation 与 Hyper-V 的关系

VMware Workstation 传统上直接调用 CPU 的 VT-x/AMD-V 指令执行虚拟化。当 Hyper-V 底层 Hypervisor 已加载(即 hypervisorlaunchtype=Auto 且相关功能启用),VT-x/AMD-V 已被占用,VMware 无法直接使用,会出现启动虚拟机时的报错。

VMware Workstation 从 15.5.5 起支持通过 Windows Hypervisor Platform(WHP)与 Hyper-V 共存运行;Workstation 16、17 完善了该支持。共存运行时存在以下限制:

  • 虚拟机性能低于原生 VT-x 直接调用模式;
  • 部分嵌套虚拟化功能受限;
  • 早期版本对某些客户机操作系统兼容性下降;
  • 对于旧版本 VMware Workstation(15.5.5 之前)无法共存。

四、常见冲突现象与对应场景

场景 1:仅启用 WSL1,未启用 Hyper-V,但勾选了「虚拟机平台」

现象:VMware Workstation Pro 中已安装并最小化配置的 CentOS 虚拟机启动时报错,常见提示包括:

VMware Workstation and Device/Credential Guard are not compatible.
VMware Workstation can be run after disabling Device/Credential Guard.

或:

This host supports Intel VT-x, but Intel VT-x is disabled.
Intel VT-x might be disabled if it has been disabled in the BIOS/firmware settings
or the host has not been power-cycled since changing this setting.

原因:虽然只勾选了「虚拟机平台」而未勾选「Hyper-V」,但 VMP 已经使 Hyper-V 底层 Hypervisor 在启动阶段加载,hypervisorlaunchtype 处于 Auto 状态,VT-x 被占用。

场景 2:启用 WSL2

现象等同于场景 1,因为 WSL2 强制依赖 VMP。

场景 3:安装 Docker Desktop(WSL2 后端)

Docker Desktop 会在安装过程中启用「虚拟机平台」和「适用于 Linux 的 Windows 子系统」。安装完成后 VMware 虚拟机可能出现相同报错。

场景 4:启用 Windows 沙盒或 WSA

同样依赖虚拟机平台,会产生相同的冲突表现。

五、检查当前状态

管理员权限的 PowerShell 中执行以下命令进行确认。

查看 Hypervisor 启动配置:

bcdedit /enum {current}

关注 hypervisorlaunchtype 一行:

  • Auto:开机即加载 Hypervisor;
  • Off:不加载 Hypervisor。

查看相关可选功能状态:

Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Get-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

查看 WSL 版本:

wsl -l -v

六、解决方案

以下方案按场景选择使用,任一方案执行后均需重启系统生效。

方案 A:升级 VMware Workstation,保持 WSL/WSL2 可用

适用条件:希望同时使用 WSL2(或 WSL1 但保留虚拟机平台)与 VMware。

步骤:

  1. 将 VMware Workstation 升级到 17.x(Pro 或 Player 均可)。

  2. 启用 Windows Hypervisor Platform:

    dism.exe /online /enable-feature /featurename:HypervisorPlatform /all /norestart
    
  3. 重启系统。

  4. 打开虚拟机进行验证。VMware 会自动识别 Hyper-V 环境并通过 WHP 运行。

代价:虚拟机性能有一定折损;部分嵌套虚拟化功能受限。

方案 B:关闭 Hypervisor,恢复 VMware 原生性能

适用条件:不需要 WSL2,只使用 WSL1 或不使用 WSL;对 VMware 性能敏感。

步骤:

  1. 关闭虚拟机平台与 Hyper-V:

    dism.exe /online /disable-feature /featurename:VirtualMachinePlatform /norestart
    dism.exe /online /disable-feature /featurename:Microsoft-Hyper-V-All /norestart
    
  2. 关闭 Hypervisor 启动:

    bcdedit /set hypervisorlaunchtype off
    
  3. 若之前使用过 WSL2,将发行版切回 WSL1:

    wsl --set-version <发行版名> 1
    wsl --set-default-version 1
    
  4. 重启系统。

方案 C:使用启动项在两种模式间切换

适用条件:日常两种场景都会使用,希望通过重启在「WSL2 模式」和「VMware 原生模式」之间切换,不必频繁开关功能。

创建两个启动项:

# 复制当前启动项,命名为 "Windows 10 - No Hypervisor"
bcdedit /copy {current} /d "Windows 10 - No Hypervisor"

命令输出会返回一个 GUID,例如 {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}。将该 GUID 用于下一步:

bcdedit /set {上一步返回的GUID} hypervisorlaunchtype off

设置默认引导等待时间(可选):

bcdedit /timeout 5

之后每次开机可选择进入哪种模式:默认项保留 WSL2 环境,新建项用于 VMware 原生虚拟化。

方案 D:临时切换 Hypervisor 状态

适用条件:偶尔需要切换。

切换到 VMware 模式:

bcdedit /set hypervisorlaunchtype off

切换回 WSL2 模式:

bcdedit /set hypervisorlaunchtype auto

修改后需要重启。此方法不需要卸载功能,但每次切换都需要一次完整重启。

七、组合场景对照表

使用需求 Microsoft-Windows-Subsystem-Linux VirtualMachinePlatform HypervisorPlatform Microsoft-Hyper-V-All hypervisorlaunchtype VMware 兼容性
仅 WSL1 启用 关闭 关闭 关闭 off 原生性能
WSL2,不使用 VMware 启用 启用 关闭 可选 auto 不适用
WSL2 + VMware 17 启用 启用 启用 可选 auto 通过 WHP 运行,性能有折损
仅 VMware 原生性能 关闭 关闭 关闭 关闭 off 原生性能
Docker Desktop(WSL2 后端) 启用 启用 启用(如需 VMware 同用) 可选 auto 依 VMware 版本

八、注意事项

  1. VMP 和 Hyper-V 是两个不同的勾选项,但底层都会加载 Hypervisor。仅关闭 Hyper-V 而保留 VMP,VMware 冲突现象依旧存在。

  2. bcdedit /set hypervisorlaunchtype off 是判断 Hypervisor 是否加载的最终开关;即便功能被启用,只要该值为 off,Hypervisor 也不会加载,VMware 可以正常使用(此时 WSL2、Docker Desktop 等会失效)。

  3. Windows 更新、Docker Desktop 安装或升级、启用 Windows 沙盒、启用 WSA(Windows Subsystem for Android)都可能自动启用虚拟机平台,导致原本正常的 VMware 环境出现启动报错。

  4. VMware Workstation Player 与 Pro 在共存机制上一致,均需 15.5.5 及以上版本。

  5. Credential Guard、Device Guard、Memory Integrity(内核隔离)等安全功能同样会占用 VT-x,报错信息类似,排查时需要一并检查。可通过组策略或以下命令关闭内核隔离状态:

    reg query "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity"
    

九、命令参考

启用相关功能:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism.exe /online /enable-feature /featurename:HypervisorPlatform /all /norestart
dism.exe /online /enable-feature /featurename:Microsoft-Hyper-V-All /all /norestart

关闭相关功能:

dism.exe /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux /norestart
dism.exe /online /disable-feature /featurename:VirtualMachinePlatform /norestart
dism.exe /online /disable-feature /featurename:HypervisorPlatform /norestart
dism.exe /online /disable-feature /featurename:Microsoft-Hyper-V-All /norestart

Hypervisor 启动控制:

bcdedit /set hypervisorlaunchtype off
bcdedit /set hypervisorlaunchtype auto

WSL 版本控制:

wsl -l -v
wsl --set-version <发行版名> 1
wsl --set-version <发行版名> 2
wsl --set-default-version 1
wsl --set-default-version 2
posted @ 2026-07-06 23:18  夷某蓁  阅读(77)  评论(0)    收藏  举报