8

I'm trying to follow this tutorial to run KVM nested in WSL 2, but after following the directions through compiling the kernel and loading it, the test kvm-ok reports that KVM is not supported.

I've tried multiple options: enabling hyper-v, disabling it, verifying BIOS/CPU support, enabling/disabling Device Guard, other steps in some vmware docs (bcdedit /set hypervisorlaunchtype, suboptions under gpedit/DeviceGuard).

When I do disable hyper-v, set hypervisorlaunchtype off, and disable Device Guard, then I get the following options in system info, but then wsl2 fails to launch at all, saying "Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS."

system info enter image description here Any other configuration I try, sys info says that a hypervisor is running and won't show the hyper-v values, but I end up running into the initial problem of KVM not being supported in WSL2. Also if I try enabling "Virtualize Intel VT-x/EPT" in VMWare Player, that fails to launch as well.

Stepping back, ultimately what I'm trying to do is run the firecracker demo on my windows laptop. So if there's an easier way to do this then lmk.

Update

I noticed it works in VMWare Player with an Ubuntu image. Or at least, kvm-ok reports that it's enabled, /dev/kvm exists. I'd still rather use WSL2. But it's refusing to load.

Dax Fohl
  • 283
  • 1
  • 2
  • 7

4 Answers4

6

On WSL2 (Windows 11), nested virtualization is supported but not enabled by default. To enable it, you must:

  1. Add yourself to the kvm group
  2. Change the default group of /dev/kvm
  3. Enable nested virtualization in /etc/wsl.conf
  4. Restart WSL

1. Adding yourself to the kvm group:

This one is easy:

sudo usermod -a -G kvm ${USER}

2. Change the default group of /dev/kvm

This is also easy, but to make it stick across reboots and upgrades, add this section to your /etc/wsl.conf file:

[boot]
command = /bin/bash -c 'chown -v root:kvm /dev/kvm && chmod 660 /dev/kvm'

3. Enable nested virtualization

You don’t need to recompile your WSL distribution to enable nested virtualization, just add this section to your /etc/wsl.conf:

[wsl2]
nestedVirtualization=true

4. Restart WSL

You can either restart Windows, or close all of your WSL terminal windows and issue this command in Powershell, CMD, or Windows Run menu (Windows+R)

wsl.exe --shutdown

The next time you open a terminal, WSL will start with the new options and nested virtualization will work. More details about enabling nested virtualization can be found here:

ixe013
  • 1,018
  • 2
  • 10
  • 26
2

Top line of the screenshot, and first line of the linked article. It requires an insider dev build of Windows. Mine was running the GA version. Enrolling in the insider program and downloading latest worked.

All the settings in the screenshots are correct, and it should be bcdedit /set hypervisorlaunchtype auto.

I got 400 KVM VM's launched from WSL on my laptop in under 60s! (First 200 in under 15s).

Also note I got KVM working in VMWare Player, but the firecracker test never quite worked. It launched the VM's but they didn't do anything. Apparently VMWare is type-2 and would be slower even if it does work, so I gave up on that approach.

Dax Fohl
  • 283
  • 1
  • 2
  • 7
1

I have taken the same steps as you and got

[    0.330695] kvm: no hardware support
[    0.330696] kvm: no hardware support

in dmesg Hyper-V is enabled and in BIOS Virtualization Technology and VT-d Features are enabled.

After I enabled Windows Hypervisor Platform I finally had

[    0.193019] KVM: vmx: using Hyper-V Enlightened VMCS
[    0.195115] kvm: already loaded the other module

In a lot of guides I read WSL requires Virtual Machine Platform. But that alone wasn't sufficient for me. For some reason it only worked when I ticked Hyper-V, Virtual Machine Platform and Windows Hypervisor Platform.

Tin Nguyen
  • 111
  • 2
0

You can try the following guide to enable WSL2 nested virtualization in win10 pro/enterprise (note the disclaimer, you should maybe backup your distros with wsl --export):

https://gist.github.com/xtrnc/496da9243bab29629bc0461562bff458

It worked on my win10 (build 19043.1348). You probably won't need to compile the kernel if you've updated Windows (which is how the Linux kernel is updated now).

If you can upgrade your OS, you can also try that. It should be enabled by default in win11 (along with WSLg).

Note: if you follow the guide it will be necessary to run the script at every restart; also it's necessary to add your user to the kvm group for permissions (on ubuntu usermod -a -G kvm <USER>)

xqer
  • 1
  • 1