e42.uk Circle Device

 

Techie Stuff

Projects

Quick Reference

Will be moved to Quick Reference soon

QEMU Nested Virtualisation

QEMU Nested Virtualisation

Using WSL2 on a Windows Machine requires virtualisation, nested virtualisation should allow WSL2 to work fine with Windows 10 (and probably 11) then it will be possible to run Alpine Linux on Windows on Alpine Linux... why do we do this to ourselves.

Nested Virtualisation Steps

Verify that nested virtualisation is possible, first check for the CPU flags:

$ grep -E "(vmx|svm)" /proc/cpuinfo | wc -l
8

The resulting number may not be 8, that is a reflection of the logical number of CPUs in the machine.

Next check that the kernel module has been configured:

$ cat /sys/module/kvm_intel/parameters/nested
Y

or for AMD:

$ cat /sys/module/kvm_amd/parameters/nested
1

If not then the module may be removed an re-inserted:

# rmmod kvm_intel
# modprobe kvm_intel nested=1

... and for AMD change to kvm_amd of course.

Ensure that the appropriate KVM switch is added to the VM:

qemu-system-x86_64 -accel kvm -cpu Haswell-noTSX-IBRS,vmx=on

or:

qemu-system-x86_64 -enable-kvm -cpu host

In Windows

First try the wsl command from the command prompt:

C:\Users\User>wsl --status
Default Version: 2
WSL1 is not supported with your current machine configuration.
Please enable the "Windows Subsystem for Linux" optional component to use WSL1.

Installing WSL2 without a Distribution

This does work but one must follow the steps carefully. When I tried it the kernel update package did not work properly but everything else seems fine.

Some further detail was found here:

Commands

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart Machine

Try and install somwthing into WSL (see below)

Installing Alpine WSL

Then create a directory for your distribution:

C:\Users\User>mkdir Alpine3_18_2WSL

Download alpine-minirootfs-3.18.2-x86_64.tar or whatever version you like, no kernel is included so WSL will provide a kernel. Then import the file and create a distribution:

wsl --import Alpine3_18_2 C:\Users\User\Alpine3_18_2WSL alpine-minirootfs-3.18.2-x86_64.tar.gz

Try and execute the distribution:

wsl --distribution Alpine3_18_2

This will provide a root prompt, exit with Ctrl-D and add a user:

wsl --distribution Alpine3_18_2 /usr/sbin/adduser -g users -D user

Then execute a shell as user:

wsl --distribution Alpine3_18_2 --user user

It is possible the following error may be displayed:

Error code: Wsl/Service/0x80040326

I don't know what is wrong but performing an update like this:

wsl --update

Fixed the problem... finally:

User-PC:/mnt/c/Users/User$ uname -a
Linux User-PC 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 Linux

Yippee!

References

Quick Links: Techie Stuff | General | Personal | Quick Reference