DISCLAIMER: This can corrupt your WSL or whatever, so no guarantees this works and does what your want. Use at your own risk.
Prereqs:
- Windows 10 pro/enterprise (in win11 it should work by default)
- Install WinDbg Preview from the Microsoft store.
- You might have to build a custom WSL kernel with KVM support. This seems to be unnecessary if your kernel is >=v4.19.104.
To check this, open your wsl2 distro and run
uname -r
, it should show the current kernel version, for example:5.10.60.1-microsoft-standard-WSL2
. If it's >=v4.19.104 skip to step 2. Building the kernel in WSL:
# before starting, check other guides too (https://boxofcables.dev/accelerated-kvm-guests-on-wsl-2/)
# dependencies
sudo apt install build-essential flex bison libssl-dev libelf-dev
# get the kernel
git clone https://github.com/microsoft/WSL2-Linux-Kernel.git
cd WSL2-Linux-Kernel
make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl
# now you need to enable:
# Virtualization -> KVM & Intel KVM (or AMD, not both, depending on your CPU)
# Processor type Features -> /dev/cpu/* /msr support
# build it (it could take a while)
make -j8 KCONFIG_CONFIG=Microsoft/config-wsl
# copy the kernel to your user profile folder
cp vmlinux /mnt/c/Users/<YOUR_USER>/
# now
- Copy
enable-kvm.bat
andscript.js
(below) to an empty folder. Runnet stop LxssManager
as an admin and check that it stopped successfully. You may need to restart your PC if it doesn't stop or find out why it doesn't before continuing.
- Optional: If you're using a custom kernel, edit it in your wsl config or uncomment the LinuxKernelDirect line in
script.js
and set the correct path to your kernel. Thanks to @offlinehacker, who increased automatization of this part!