Run a hypervisor inside a machine
WSL2 runs in a Windows machine, and KVM with the containers that use it runs in a Linux machine.
Requires a Mac with an M3 chip or later. Apple offers no nested virtualization for macOS machines.
Turn on nested virtualization
A nested guest's CPUs and memory come out of the machine's, so give the machine enough memory for both.
- Shut the machine down.
- Select it, choose Machine > Machine Settings, then click Hardware.
- Turn on Nested Virtualization.
- Start the machine.
osmates vm stop dev
osmates vm set dev --nested-virtualization
osmates vm start dev
New machines have the setting off. To turn it off again, shut the machine down and run osmates vm set dev --no-nested-virtualization. A snapshot with memory keeps the setting it was taken with, and reverting to it puts that setting back.
Run KVM in Linux
With the setting on, Linux has /dev/kvm. To check:
osmates vm exec dev -- ls -l /dev/kvm
QEMU then starts Arm64 guests with -accel kvm. A container gets the device with docker run --device /dev/kvm.
Install WSL2 in Windows
- In the machine, open PowerShell as an administrator.
- Run
wsl --install. - Restart Windows to finish the install.
Limits
- Programs in a nested guest run slower than programs in the machine itself.
- A machine with the setting on doesn't start on a Mac without an M3 chip or later. Turn the setting off to start it there.