Skip to content

Map HCS_E_HYPERV_NOT_INSTALLED to an actionable 'install Virtual Machine Platform' error#40723

Open
benhillis wants to merge 1 commit into
microsoft:masterfrom
benhillis:user/benhillis/setversion-vmp-preflight
Open

Map HCS_E_HYPERV_NOT_INSTALLED to an actionable 'install Virtual Machine Platform' error#40723
benhillis wants to merge 1 commit into
microsoft:masterfrom
benhillis:user/benhillis/setversion-vmp-preflight

Conversation

@benhillis
Copy link
Copy Markdown
Member

@benhillis benhillis commented Jun 5, 2026

Problem

Any op that needs the WSL2 VM (launch, --set-version 2, --import, disk mount) goes through _CreateVm() -> WslCoreVm::Create() -> hcs::CreateComputeSystem(). Without the Virtual Machine Platform optional component, HCS throws HCS_E_HYPERV_NOT_INSTALLED, which maps to "virtualization is not enabled on this machine" — pointing users at their BIOS instead of the real cause (missing optional component). Especially confusing mid --set-version conversion (internal Sev1).

Fix

Catch HCS_E_HYPERV_NOT_INSTALLED at the Create() call in _CreateVm() and remap to WSL_E_VIRTUAL_MACHINE_PLATFORM_REQUIRED (already defined + mapped to "install Virtual Machine Platform via wsl.exe --install --no-distribution", just never thrown). One chokepoint fixes every VM-creation path. Keying off the actual failure means the partial-VMP case (vmcompute up, HNS/vfpext missing) still starts with degraded networking as before — no collateral.

Notes

  • Reuses MessageVirtualMachinePlatformNotInstalled; its "Failed to start virtual networking" prefix is slightly off here — can add a dedicated string if preferred.
  • Couldn't build WSL locally; uses only symbols already in this TU, so CI is the real check.

@benhillis benhillis requested a review from a team as a code owner June 5, 2026 21:53
Copilot AI review requested due to automatic review settings June 5, 2026 21:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the WSL service’s WSL1→WSL2 conversion path by adding an early pre-flight check for the Virtual Machine Platform optional component, so the conversion fails with a WSL-defined error and actionable guidance instead of surfacing a low-level HCS failure mid-conversion.

Changes:

  • Add a pre-flight IsVirtualMachinePlatformInstalled() check in LxssUserSessionImpl::SetVersion (WSL1→WSL2 branch).
  • Throw WSL_E_VIRTUAL_MACHINE_PLATFORM_REQUIRED with a user-facing error message when the optional component is missing.

Comment on lines +2028 to +2031
THROW_HR_WITH_USER_ERROR_IF(
WSL_E_VIRTUAL_MACHINE_PLATFORM_REQUIRED,
wsl::shared::Localization::MessageVirtualMachinePlatformNotInstalled(),
!wsl::windows::common::wslutil::IsVirtualMachinePlatformInstalled());
// installed before creating the utility VM; otherwise VM creation fails deep in HCS with a raw
// HCS_E_HYPERV_NOT_INSTALLED, which surfaces as a confusing error mid-conversion. Failing here is
// safe because no distribution artifacts have been modified yet (deleteFlags is still 0).
THROW_HR_WITH_USER_ERROR_IF(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm maybe this should just be in _CreateVm?

@benhillis benhillis force-pushed the user/benhillis/setversion-vmp-preflight branch from 4ff0457 to a9a0f67 Compare June 5, 2026 21:59
…achine Platform

Any operation that needs the WSL2 utility VM (launch, 'wsl --set-version <distro> 2'
conversion, 'wsl --import', disk mount, ...) funnels through
LxssUserSessionImpl::_CreateVm() -> WslCoreVm::Create() -> hcs::CreateComputeSystem().
On a machine without the Virtual Machine Platform optional component, HCS throws
HCS_E_HYPERV_NOT_INSTALLED there. That HRESULT is mapped (wslutil.cpp) to
MessageEnableVirtualization() - 'WSL2 is unable to start since virtualization is not
enabled on this machine' - which points the user at their BIOS instead of the actual
cause: the missing optional component. This is especially confusing during a WSL1->WSL2
conversion (internal Sev1 customer report).

Catch HCS_E_HYPERV_NOT_INSTALLED at the WslCoreVm::Create() call site in _CreateVm() and
remap it to the existing (previously unused) WSL_E_VIRTUAL_MACHINE_PLATFORM_REQUIRED,
which is already mapped to an actionable 'install Virtual Machine Platform via
wsl.exe --install --no-distribution' message. Handling it at this single chokepoint fixes
every VM-creation path uniformly and gives callers/telemetry a meaningful WSL error code
instead of a raw HCS code.

Keying off the actual creation failure (rather than a pre-flight service-presence check)
deliberately leaves other cases untouched: when the Virtual Machine Platform is only
partially present (e.g. vmcompute up but HNS/vfpext missing) CreateComputeSystem() still
succeeds and the VM starts, and WslCoreVm's existing networking fallback continues to warn
and degrade to no-networking as before. All other Create() failures are rethrown unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 5, 2026 22:05
@benhillis benhillis force-pushed the user/benhillis/setversion-vmp-preflight branch from a9a0f67 to 0a3cb4f Compare June 5, 2026 22:05
@benhillis benhillis changed the title Fail WSL1->WSL2 conversion early when Virtual Machine Platform is missing Map HCS_E_HYPERV_NOT_INSTALLED to an actionable 'install Virtual Machine Platform' error Jun 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/exe/LxssUserSession.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants