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
-
upgrade to Windows 11.
-
Install Windows Terminal
-
Install Ubuntu 20.04 LTS.
-
Install Genie by first running
sudo bash
, and then running the following commands:# Add Microsoft Ubuntu repository wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -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 https://arkane-systems.github.io/wsl-transdebian/apt/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 https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main EOF # 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 multi-user.target 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
-
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.
-
As described above, lack of Systemd support remains my biggest gripe, but for now there are adequate hacks to make this work.
-
Displays do not go to sleep when WSLg is enabled. In my opinion, makes WSLg suitable for demos, and for briefly running Linux GUI applications, as long as they are shut down promptly. So no terminals, browsers, mail clients, etc. Thankfully, these all run on Windows and interact seemlessly, so this isn't a big problem for me.
-
No NIC Bridge mode means that the applications I run on Linux are not visible outside my laptop. That issue describes a workaround that could be used, but in practice I avoid it. This means that while I'm happy with Windows plus WSL as a developer machine, I would never consider it for use as a server.