# 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.

1. Shut the machine down.
2. Select it, choose **Machine > Machine Settings**, then click **Hardware**.
3. Turn on **Nested Virtualization**.
4. Start the machine.

```sh
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:

```sh
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

1. In the machine, open PowerShell as an administrator.
2. Run `wsl --install`.
3. 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.
