Jump to content
Microsoft Windows Bulletin Board

Systemd support is now available in WSL!


Recommended Posts

Guest Craig Loewen
Posted

[HEADING=1]Systemd support is now available in WSL![/HEADING]

 

The Windows Subsystem for Linux (WSL) can now run systemd inside of your WSL distros, empowering you to do more with your Linux workflows on your Windows machine.

 

This post will cover:

 

  • What is systemd? What can you do with it?
  • How is this change possible in WSL?
  • How can you get systemd on your machine?

 

For a summary, check out

below:

 

 

[HEADING=1]What is systemd? What can you do with it?[/HEADING]

 

From systemd.io :

 

 

Systemd is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system.

 

 

Many popular distributions run systemd by default, such as Ubuntu, Debian and more. This change means that WSL will be even more similar to using your favorite Linux distros on a bare metal machine, and will let you use software that depends on systemd support.

 

A few examples of Linux applications that depend on systemd are:

 

  • snap
    • A handy binary that allows you to install and manage software inside Ubuntu.
    • Try running: [iCODE]snap install spotify[/iCODE] or [iCODE]snap install postman[/iCODE]

    [*]microk8s

    [*]systemctl

    • A tool that’s part of systemd, interact with services on your Linux machine
    • Try [iCODE]systemctl list-units --type=service[/iCODE] to see which services are available and their status

[HEADING=1]How is this change possible in WSL?[/HEADING]

 

Supporting systemd required changes to the WSL architecture. As systemd requires PID 1, the WSL init process started within the Linux distribution becomes a child process of the systemd. Because the WSL init process is responsible for providing the infrastructure for communication between the Linux and Windows components, changing this hierarchy required rethinking some of the assumptions made with the WSL init process. Additional modifications had to be made to ensure a clean shutdown (as that shutdown is controlled by systemd now) and to have compatibility with WSLg, It is also important to note that with these change, systemd services will NOT keep your WSL instance alive. Your WSL instance will stay alive in the same way it did before, which you can read more about here.

 

Given that this changes how WSL behaves when booting up, we wanted to be careful about applying this to user’s already existing WSL distros. So currently you need to opt-in to enable systemd for a specific WSL distro, and we will monitor feedback and investigate making this behavior by default in the future.

 

[HEADING=1]How can you get systemd on your machine?[/HEADING]

 

To get started, you will need to do these two things: – Ensure you are running the right version of WSL: Version 0.67.6 and above – Set the systemd flag set in your WSL distro settings

 

[HEADING=2]Ensuring you are on the right WSL version[/HEADING]

 

This change is only available in the Microsoft Store version of WSL version 0.67.6 and higher. You can check your version number by running [iCODE]wsl --version[/iCODE]. If that command fails then you are running the in-Windows version of WSL and need to upgrade to the Store version.

 

This version of WSL is now available in the Microsoft Store to users on Windows Insiders build for initial testing, and then after a few weeks we will make it available to all users to ensure quality. You can run [iCODE]wsl --update[/iCODE] to check for any WSL updates.

 

If you are not on Windows Insiders and want to use it immediately, you can download the latest release from the WSL release page.

 

[HEADING=2]Set the systemd flag set in your WSL distro settings[/HEADING]

 

You will need to edit the wsl.conf file to ensure systemd starts up on boot.

 

Add these lines to the [iCODE]/etc/wsl.conf[/iCODE] (note you will need to run your editor with sudo privileges, e.g: [iCODE]sudo nano /etc/wsl.conf[/iCODE]):

 

[boot]
systemd=true

 

And close out of the nano editor using [iCODE]CTRL+O[/iCODE] to save and [iCODE]CTRL+X[/iCODE] to exit.

 

[HEADING=2]Final steps[/HEADING]

 

With the above steps done, close your WSL distro Windows and run [iCODE]wsl.exe --shutdown[/iCODE] from PowerShell to restart your WSL instances. Upon launch you should have systemd running. You can check this with the command [iCODE]systemctl list-unit-files --type=service[/iCODE] which should show your services’ status.

 

[HEADING=1]Acknowledgements and Feedback![/HEADING]

 

Thank you to the Canonical team for working with us to deliver this feature! Check out Canonical’s blog post here. For any technical issues please file them on the Microsoft/WSL Github repo. You can follow up with WSL team members, or with me on Twitter. Lastly, learn more about WSL, including how to set up common development tools like Git, VS Code, Docker containers, databases, GPU acceleration for machine learning, and more, by visiting the WSL documentation.

 

The post Systemd support is now available in WSL! appeared first on Windows Command Line.

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...