Announcing built-in SystemD support in Fedora Remix for WSL

SystemD is not supported officially in WSL and the lack of it imposes the following limits:

  • Services cannot be started using the familiar systemctl and the daemons must be started manually.

  • For RedHat and SUSE like distros, neither the service command can be used to start services.

  • Use snaps

  • Run Gnome desktop

Fedora Remix WSL 35.13.5 includes SystemD support

Traditionally bringing SystemD to WSL implied using workarounds or scripts to be able to start the systemd daemon with a process id 0. We based our implementation on one of them, the one-script-wsl2-systemd by Dani Llewellyn. Upon updating to the 35.13.5 version you’ll see the following changes:

  • A new start menu entry called Fedora Remix for WSL

 
 
  • A new menu entry in Windows Terminal

 
 
  • New options for run at Windows login

 
 

Starting SystemD

The SystemD support is completely optional and you can start it or not depending on what you need to do. You can use Start Menu shortcut, the Windows Terminal profile, via command line execute: fedoraremix -s, or inside a running instance sudo start-systemd

NOTE: You don’t need to wipe your actual installation, when you start SystemD for the first time it will update and everything for you into your existing instance.

Some examples

Ok, I have SystemD, now what? Let’s see some useful use cases:

The SSH server is started automatically

First, let’s get the IP address with ip address show dev eth0

And ssh into it

Sadly the WSL2 IP address changes on every restart. Let’s use hostnames instead:

  • Edit the /etc/wsl.conf to establish a custom hostname. Add a hostname entry in the [network] section with the hostname that you like

  • Install avahi with sudo dnf -y install avahi and enable it with sudo systemctl enable avahi-daemon

  • Stop Fedora Remix with wsl.exe --terminate fedoraremix

  • Start it again with SystemD.

  • Now connect using ssh but using the hostname

 

Install GNOME desktop

Let’s level it up and install a full desktop. First, edit the /etc/wsl.conf to establish a custom hostname. Add a hostname entry in the [network] section with the hostname that you like as we did in the previous example:

Now install Gnome using sudo dnf -y groupinstall 'Basic Desktop' GNOME. You can use also the Fedora Workstation group but it will install many things that probably you won’t need.

When it finish you’ll need to configure the locale with: localectl set-locale LANG="en_US.UTF-8"
The last step is to install the remote desktop support xrdp: sudo dnf -y install xrdp and enable it with sudo systemctl enable xrdp
Terminate fedoraremix and start it again with SystemD

If the terminate command fails, run it from PowerShell. Start Fedora Remix again with SystemD

Now open Remote Desktop Connection or Remote Desktop app from the store (recommended) and put the hostname that you defined in the Computer or PC name field. Also you can specify the username and if you want it to save the password

And here is

Install and run Snaps

Once you started with SystemD, you can install SnapD using the standard steps for Fedora:

  • Be sure that you started Fedora Remix with SystemD.

  • Run: sudo dnf -y install snapd

  • Create the symbolic link for the classic mode: sudo ln -s /var/lib/snapd/snap /snap

  • Check if everything is ok with: snap version

  • Install an example snap: sudo snap install hello-world

  • And run it: hello-world

If you see a bash: hello-world: command not found... start Fedora Remix again in SystemD mode

Installing a snap with GUI suppport

What about a graphical application? Let’s try with IntelliJ IDEA. sudo snap install intellij-idea-community --classic

IntelliJ IDEA installed as a snap in Fedora Remix for WSL

Note that for Windows 10 you’ll need a running X Server in Windows such as X410 or VcXsrv

Starting your services at Windows log-in

You can instruct Fedora Remix to run at Windows startup with SystemD thus starting your services. Just go to the App Settings and activate the preferred option. The No Window option won’t show any console upon start.

 
 

Starting services in Fedora Remix for WSL without using SystemD, also available for WSL1

Many services like SSH, Avahi, and XRDP don’t require SystemD in order to be run. But starting them manually can be tedious. This is why this update to Fedora Remix includes a script that can be used to start services using the systemctl syntax. We called it wslsystemctl and it is based on a solution made to start services in a docker container in an easy way. For more information on the source check: Docker SystemD Replacement

Starting SSH

  • Run sudo wslsystemctl start sshd-keygen@ecdsa.service only the first time to generate the key

  • Run sudo wslsystemctl start sshd

Starting your services at Fedora Remix start without SystemD

You can add the command sudo wslsystemctl default to your .bashrc so your services will be started.

echo "%wheel ALL=NOPASSWD: /usr/local/bin/wslsystemctl default" | sudo EDITOR="visudo" tee /etc/sudoers.d/start-services echo "sudo wslsystemctl default 2>/dev/null">> $HOME/.bashrc

Known issues

The SystemD integration is a work in progress and some things don’t run well or are incompatible. Our piece of advice is that use SystemD only when you really need it. Let’s see some of them and workarounds.

WSL Store edition

You may experience crashes or wsl shutdowns when using Remote Desktop and a desktop environment served via XRDP. Also, the interoperability between WSL and Windows begins to fail. The advice is if you experience stability problems uninstall the Store version.

WSLg and Qt applications

Out of the box, Qt applications will be rendered as black boxes in WSLg if Fedora Remix is started with SystemD, we are still working on that. The situation is worse if the application is packed as a snap. Some workarounds:

  • The best way is to bypass WSLg completely and use an X Server in Windows as we do in Windows 10. With the following command, WSLg will be disabled just for Fedora Remix: echo "unset DISPLAY" | sudo tee /etc/profile.d/00-no-wslg.sh

  • Another way is to use Wayland instead of XWayland; it won’t work with snaps unless the Wayland plugin is packed into the snap itself. For it, we need to install the Wayland plugin and define some environment variables

 
sudo dnf -y install qt5-qtwayland
export QT_QPA_PLATFORM=wayland
export XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir
  • if you installed any desktop environment like in the previous examples, the Qt applications will run perfectly inside of it.

Start menu shortcuts won’t be generated for snap applications

We are working to bring an alternative for this, because SystemD must be started before trying to use the snaped application.

Acknowledgments 

🏆 Dani Llewellyn - for her hard work making it possible to have SystemD and Snaps together with WSLg with a single and easy-to-use script.

🏆 Guido U. Draheim - for creating a script that allows WSL users to start services without having to start SystemD, also helping WSL1 users.

🏆 carrizo - for integrating both scripts into the image and the update.sh script, and making it possible to call them transparently from the launcher.

Conclusion

There is still work to do but we want to know what you do with it, please share your impressions and use cases in the comments.

Enjoy it!!