It’s just data

Genie WSLg

For those who have not used WSL yet, it is frankly amazing, to this long time Linux user.

An example of my workflow. This blog entry was created in vim running in Ubuntu 20.04, which I access through Windows Terminal. I build my site using 11ty, and serve the statically generated HTML using Apache HTTP which is automatically started using systemd. I view the results using Microsoft Edge (running on Windows), which I access by pointing my browser to http://localhost/blog.

I also develop node/express applications using Visual Studio Code - equally as seamlessly.

Ditto for Rails applications.

At no time am I thinking: this is a Windows application, that is a Linux application. For all practical purposes, I have a Linux laptop running a Windows display manager, one that is capable of side-loading windows applications.

Time for an update

Windows 11 is out and it turns out that the marquee feature of the latest version of WSL, namely WSLg, poses even more problems for those that wish to run with Systemd. Systemd is the standard way to start and orchestrate background processes (like web servers and databases), and is necessary for a variety of other things like logging and snaps.

Unfortunately, most of the scripts (generally self described as hacks) out there that configure your system to launch systemd have not been updated. The two that are are Genie and one-script-wsl2-systemd.

Most are recommending Genie, and I'm more comfortable with its approach - in particular, it is easy to uninstall. It is well documented, but unfortunately as it supports a large number of distributions, the documentation is mostly of the form "if you hit this problem, here are some things to try". In my opinion, what it lacks is a tried but true set of instructions for the what for most WSL users is the default choice in operating systems, namely Ubuntu 20.04. Without further ado...

Quick Start

  1. upgrade to Windows 11.

  2. Install Windows Terminal

  3. Install Ubuntu 20.04 LTS.

  4. Install Genie by first running sudo bash, and then running the following commands:

     # Add Microsoft Ubuntu repository
     wget -O packages-microsoft-prod.deb
     dpkg -i packages-microsoft-prod.deb
     rm packages-microsoft-prod.deb
     # Add Arkane Systems repository
     wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg
     chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg
     cat << EOF > /etc/apt/sources.list.d/wsl-transdebian.list
     deb $(lsb_release -cs) main
     deb-src $(lsb_release -cs) main
     # Install dotnet runtime and systemd genie
     apt update
     apt -y dist-upgrade
     apt install -y dotnet-runtime-5.0 systemd-genie
     # Configure systemd units for WSLg
     systemctl set-default
     sed -i -e 's|LABEL=cloudimg-rootfs\t|/dev/sdb\t|' /etc/fstab
     (cd /etc/ssh; ssh-keygen -A)
     systemctl enable wslg-xwayland.socket
     systemctl disable multipathd.socket
  5. Add a Windows Terminal profile specifying the following command

     wsl.exe -d Ubuntu-20.04 genie -s

The problem in a nutshell

Oversimplifying, Windows 11 ships Hyper-V which is capable of running both Windows and a Linux kernel side by side. On the Linux kernel, WSL2 runs what effectively are mutable containers containing Linux distributions like Ubuntu, Debian, CentOS, etc. Containers are very powerful, and the net of what I have described so far is that your application will run essentially natively on the distribution of your choice on top of a real Linux kernel.

The one key difference is the boot process. Specifically, there is no systemd involved. Generally, you don't need to interact with systemd directly, and in many cases you can get along without it, but if, for example, you install a database it generally will also install startup and maintenance instructions which are executed automatically for you by systemd. And there are other things, like installing snaps that won't work at all without systemd.

Getting systemd to run is possible with PID namespaces and there are a few scripts out there that help with this. This brings us to the next problem: the configuration files that ship not only with the operating system distribution but also with various applications may not work perfectly under WSL.

Remaining issues

While this setup works well for my workflow, there remain significant impediments to other workflows.