KVM On WSL2
Replacing VirtualBox with KVM inside of WSL2.
Compile a new Kernel.
KVM needs to be enabled in the WSL kernel variant.
This post gives the details:
A few key points:
- Microsoft’s kernel is here: https://github.com/microsoft/WSL2-Linux-Kernel/.
- The default config is in Microsoft/config-wsl
- You update the config to enable KVM and paravirtualization options (e.g. with menuconfig), compile this in WSL, The kernel image is copied to the windows file system.
- The global WSL config file selects the kernel image and nested virtualization. See https://docs.microsoft.com/en-us/windows/wsl/wsl-config.
- KVM works fine with Windows 11 support for Linux GUI - A third party X server is not needed.
e.g. New global WSL config file: c:\home\<user>\.wslconfig
[wsl2]
nestedVirtualization=true
kernel=C:\\Users\\Phil\\bzImage
Enable KVM.
KVM can be run as a user, but permissions must be set.
sudo chmod g+wrx /dev/kvm
sudo chgrp kvm /dev/kvm
The KVM parameters should also be set:
sudo echo Y > /sys/module/kvm_intel/parameters/nested
sudo echo Y > /sys/module/kvm_intel/parameters/enable_shadow_vmcs
sudo echo Y > /sys/module/kvm_intel/parameters/enable_apicv
sudo echo Y > /sys/module/kvm_intel/parameters/ept
Setup MacOS
This repo https://github.com/foxlet/macOS-Simple-KVM has scripts to do it all. OSX on KVM is much faster than OSX on VirtualBox.
The mouse does not work to well in KVM + WSL. Changing basic.sh
to use tablet seems to solve this issue:
-usb -device usb-kbd -device usb-tablet
An alternative option is to use docker + kvm in WSL: https://github.com/sickcodes/Docker-OSX
Setup Android
I’m using Bliss OS x86 Android: https://sourceforge.net/projects/blissos-x86/.
qemu-img create -f qcow2 android.img 16G
Run first with the cdrom install media attached, e.g.
ISO=Bliss-v11.13--OFFICIAL-20201113-1525_x86_64_k-k4.19.122-ax86-ga-rmi_m-20.1.0-llvm90_dgc-t3_gms_intelhd.iso
qemu-system-x86_64 \
... options below ...
-cdrom ${ISO}\
To run Android these options work for me:
#!/bin/sh
sudo chmod g+wrx /dev/kvm
sudo chgrp kvm /dev/kvm
sudo echo Y > /sys/module/kvm_intel/parameters/nested
sudo echo Y > /sys/module/kvm_intel/parameters/enable_shadow_vmcs
sudo echo Y > /sys/module/kvm_intel/parameters/enable_apicv
sudo echo Y > /sys/module/kvm_intel/parameters/ept
qemu-system-x86_64 \
-enable-kvm \
-m 2G \
-machine q35,accel=kvm \
-smp 4,cores=2 \
-cpu host \
-device ES1370 \
-hda android.img \
-boot menu=on \
-serial mon:stdio \
-net nic \
-net user,hostfwd=tcp::5555-:22 \
-vga qxl \
-usb -device usb-tablet \
Subscribe via RSS