If you just running LXC/LXD containers, the default settings for WSL2 (both Windows 10 and Windows 11) should be adequate.
However, if trying something like lxc launch images:alpine/3.18 --vm, LXC will complain that
vhost_vsock module is not loaded.
Here's how I configure WSL2 so I can run VM with LXC/LXD.
LXC/LXD uses QEMU under the hood with kvm as requirement for virtual machines.
Windows 10 does not support nested virtualization for WSL2. Setting nestedVirtualization=true
in .wslconfig will report wsl: Nested virtualization is not supported on this machine.
This article will only work on Windows 11 or later machines.
That being said, Windows 10 can still run LXC/LXD container without kernel modification.
I'm using Debian 11. Ubuntu or any Debian/Ubuntu based WSL image should have similar dependencies.
sudo apt update
sudo apt install git bc build-essential flex bison libssl-dev libelf-dev dwarvesIn theory, using newer kernel with the same major version should work fine. But I don't want to take my time to verify whole kernel feature for just a minor change.
I'll use the same kernel version as what Microsoft came with. uname -r gives me
5.15.120-microsoft-standard-WSL2. The kernel version to use here will be 5.15.120.
Now download kernel source from kernel.org:
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.120.tar.xz
tar xf linux-5.15.120.tar.xzpushd linux-5.15.120
wget -O arch/x86/configs/config-wsl https://raw.githubusercontent.com/microsoft/WSL2-Linux-Kernel/linux-msft-wsl-5.15.y/arch/x86/configs/config-wsl
# Create a duplicate to modify
cp arch/x86/configs/config-wsl arch/x86/configs/config-wsl-custom
popdTo prevent human error, it is highly suggested use menuconfig to modify the kernel compile configuration.
pushd linux-5.15.120
make KCONFIG_CONFIG=arch/x86/configs/config-wsl-custom menuconfig
popdInside the config UI:
- Use <Up> and <Down> key to navigate through options.
- Use <Left> and <Right> key to select action at the bottom when <Enter> key is pressed.
- Use <Space> to change the compile mode.
- An option with
--->indicates it has submenu, chooseSelectaction and press <Enter> key to get inside the submenu.
The target is to compile vhost_vsock as an kernel module, which should be marked as <M>.
The compile option is at Device Drivers -> [*] VHOST drivers ->
<M> vhost virtio-vsock driver.
After vhost virtio-vsock driver is marked as compile as module <M>, save the config file.
To make the changes being obvious, you can change the kernel version suffix in
General Setup -> Local version
I'm changing it to -microsoft-custom-WSL2 so I can verify the corrent kernel has been loaded.
pushd linux-5.15.120
make KCONFIG_CONFIG=arch/x86/configs/config-wsl-custom -j$(nproc)
sudo make KCONFIG_CONFIG=arch/x86/configs/config-wsl-custom modules_install
mkdir -p /mnt/c/Users/user/wsl2-kernel
cp arch/x86/boot/bzImage /mnt/c/Users/user/wsl2-kernel/bzImage-5.15.120-WSL2-custom
# WSL2 seems not to load the module without some easy configuration.
echo vhost_vsock | sudo tee -a /etc/modules
# If you already have .wslconfig setup, the following lines will remove what has been done.
# Modify the file manually if required.
cat << EOF > /mnt/c/Users/user/.wslconfig
[wsl2]
kernel=C:\\\\Users\\\\user\\\\wsl2-kernel\\\\bzImage-5.15.120-WSL2-custom
EOF
popdwsl --shutdown
wslAt this moment, uname -r should give us 5.15.120-microsoft-custom-WSL2.
If vhost_vsock not in the result of lsmod, try load the module manually:
sudo modprobe vhost_vsockIf vhost_vsock is still not loaded, the system may have some other issue.
I'm not sure if LXC needs virtualization support or not, as Windows 11 already support
this feature and I've seen /dev/kvm since upgraded to Windows 11.
nice step-by-step explanation, working fine after second times compile,
the problem is virtual disk where before about 1gb in size but after all this taking more than 12gb

is this have simplify method just copy and paste bzImage kernel and just enable vhost_vsock mod?
after all, thanks for solution ๐๐. I do my best testing for that later