Whitewater Foundry

View Original

Announcing built-in SystemD support in Pengwin Enterprise

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

Pengwin Enterprise 7.9.1 and 8.6.1 include 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 7.9.1 or 8.6.1 versions, you’ll see the following changes:

  • A new start menu entry called Pengwin Enterprise 7/8 (SystemD)

  • A new menu entry in Windows Terminal

  • New options for run at Windows login

Starting SystemD

The SystemD support is entirely optional, and you can start it or not, depending on what you need to do. You can use the Start Menu shortcut, the Windows Terminal profile, via command line, execute: wle -s / pengwinenterprise8 -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 everything for you into your existing instance.

Some examples

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

The SSH server is started automatically

First, install prerequisites sudo yum -y install iproute openssh-server openssh-clients

And enable ssh sudo systemctl enable --now sshd

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 yum -y install avahi and enable it with sudo systemctl enable --now avahi-daemon

  • Terminate Pengwin Enterprise (wsl.exe --terminate pengwinenterprise8 or wle) and start it again with SystemD.

  • Now connect using ssh but using the hostname.

  • In RHEL you may also need to open the port in Firewall: sudo firewall-cmd --permanent --add-port=5353/udp and sudo firewall-cmd --reload

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:

  • Pengwin Enterprise 8: sudo yum group install -y Workstation

  • Pengwin Enterprise 7: sudo yum group install 'GNOME Desktop'

  • RHEL7: sudo yum group install 'Server with GUI'

When it finishes, 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

  • First, install the EPEL repository: sudo yum -y install epel-release or sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm for RHEL

  • Then XRDP: sudo yum -y install tigervnc-server xrdp and enable it with sudo systemctl enable --now xrdp

  • In RHEL you may also need to open the port in Firewall: sudo firewall-cmd --permanent --add-port=3389/tcp and sudo firewall-cmd --reload

  • Terminate Pengwin Enterprise (wsl.exe --terminate pengwinenterprise8 or wle) and start it again with SystemD

Now open the Remote Desktop Connection or Remote Desktop app from the store (recommended) and put the hostname 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 RHEL:

  • 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: snap run hello-world

Installing a snap with GUI suppport

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

Note for Windows 11 users. GUI support with snaps is not currently supported on WSLg in Pengwin Enterprise 7-8. You’ll need to disable WSLg editing winhome/.wslconfig, /etc/wsl.conf or creating a startup file (recommended) with: echo 'unset DISPLAY' | sudo tee /etc/profile.d/00-nowslg.sh and use the traditional methods used in Windows 10 installing an X Server like VcXSrv or X410, Pengwin Enterprise will be configured automatically to use it.

Windows 10, you’ll need a running X Server in Windows such as X410 or VcXsrv.

IntelliJ IDEA installed as a snap in Pengwin Enterprise

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 Pengwin Enterprise 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 Pengwin Enterprise 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 Pengwin Enterprise 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 (sudo wslsystemctl start sshd-keygen in Pengwin Enterprise 7) only the first time to generate the key.

  • Run sudo wslsystemctl start sshd

Starting your services at Pengwin Enterprise 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/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; some things don’t run well or are incompatible. Our piece of advice is that use SystemD only when you 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

Out of the box, GUI applications won’t work in WSLg if Pengwin Enterprise 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 entirely and use an X Server in Windows as we do in Windows 10. With the following command, WSLg will be disabled just for Pengwin Enterprise: echo "unset DISPLAY" | sudo tee /etc/profile.d/00-nowslg.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. For it, we need to install the Wayland plugin and define some environment variables.

sudo yum -y install qt5-qtwayland 
export QT_QPA_PLATFORM=wayland 
export XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir
  • if you installed any desktop environment like the previous examples, the GUI applications would run perfectly inside.

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!!