Virtual WSL in Windows 11

This tutorial covered a lot of ground and is longer than normal. The end goal was to learn how to make Windows 10/11 Windows subsystem for Linux (WSL2) more functional. We achieved this goal by implementing a Github project called Distrod.

Distrod created a simple container that runs systemd as an init process and therefore allows typical Linux services to be controlled by systemctl. This container then runs the WSL virtualization which allows your selected Linux distro to access many typical Linux services.

We started by learning that my previous video entitled “Secure Shell (ssh) From Windows” was actually conducted inside of a QEMU Virtual Machine instance of Windows 11. We used that as a starting point and reviewed how to install WSL2 in Wndows 11.

The QEMU commands I used to manage snapshots of my Windows 11 instance are:

virsh snapshot-list win11-qemu
virsh snapshot-create-as --domain win11-qemu --name "Final"
virsh snapshot-revert win11-qemu 1657958902

The Distrod installer script is downloaded and run from inside of WSL with the following commands:

curl -L -O "https://raw.githubusercontent.com/nullpo-head/wsl-distrod/main/install.sh"
chmod +x install.sh
sudo ./install.sh install

In order to enable Distrod on reboot, execute the following command in WSL after Distrod is installed:

sudo /opt/distrod/bin/distrod enable --start-on-windows-boot

To update Distrod inthe future:

curl -L -O "https://raw.githubusercontent.com/nullpo-head/wsl-distrod/main/install.sh"
chmod +x install.sh
sudo ./install.sh update

After Distrod is installed and you open a new WSL shell, you can execute commands that rely on Linux services. In our example, we configured LXD and added user "scott to the LXD group.

sudo init lxd
sudo usermod -aG lxd scott`Preformatted text`
newgrp lxd
groups

We created a LXD container in WSL.

lxc list
lxc launch ubuntu:20.04 test --profile default -c boot.autostart=true 

Sadly, our LXD container did not have a bridge on which to communicate.

We did change the Windows network card to be bridged in order to provide a LAN address for WSL.
To do that, install Hyper-V in Windows as an optional feature.
Run the Hyper-V Manager.
Execute the Virtual Switch Manager in Hyper-V.
Change the WSL instance to “External”.

In WSL to change network address after adapter is bridged:

sudo ip addr flush dev eth0
sudo dhclient eth0

Note that the Hyper-V switch setting for WSL and the two commands above must be run each time Windows is booted.

You must also remove “Hyper-V” from your ethernet device after a reboot in order for the Hyper-V switch setting to work after a reboot.

Assuming that you get this far, you can create a bridge inside of WSL for LXD to use. In the demo, that did not work. However it has worked for me. Perhaps if my Windows was not also virtual, my results may have been more consistent.

To create the bridge inside of WSL:

sudo nano /etc/netplan/01-network.yaml

Put the following data in the Netplan file:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0: {dhcp4: true}
  bridges:
    br0:
      interfaces: [eth0]
      dhcp4: true

To change the network configuration in WSL to add the “br0” bridge device:

sudo netplan apply

To see how bridging works in LXD, watch my other videos.