Awesome
WSL2 Systemd by changing the user's shell
About
This repository includes the files to set-up WSL2 distro to run systemd.
What does it do?
- Disables a few Systemd units that aren't required for WSL2 or might cause issues
- Creates a minimal script called
/etc/profile.d/00-wsl2-systemd.sh
that sets up some WSL2-specific environment that cannot be carried into the Systemd namespace easily. At the moment this is only thePATH
variable - Creates a file called
/usr/sbin/start-systemd-namespace
that is used to start Systemd inside a PID namespace so that Systemd is PID 1 - Creates a file called
/usr/bin/namespaced-shell-wrapper.sh
that will callstart-systemd-namespace
to enter the systemd namespace. It will then execute your shell - Symlinks
namespaced-shell-wrapper.sh
alongside your current user shell's executable. For example, if you are running BASH with executable/bin/bash
then it will create the symlink as/bin/namespaced-bash
- Modifies
/etc/pam.d/runuser
to allow the usage of a user-specific environment override file that is enforced by the PAM subsystem. The file,$HOME/.pam_environment
is written by/usr/bin/namespaced-shell-wrapper.sh
and contains variables that should not change often - Finally, changes your user's configured shell with
chsh
to point to the symlink to the shell wrapper, e.g./bin/namespaced-bash
.
Installing
- Clone the repository, or download the three scripts via a browser
- Execute either
install-all.sh
orinstall-systemd.sh
.- The
install-all.sh
script will execute bothinstall-systemd.sh
andinstall-gui-support.sh
to perform a complete install install-systemd.sh
will install just enough to get systemd operational, but will not enable GUI support via X11- If you install the GUI support by running
install-all.sh
(orinstall-gui-support.sh
after runninginstall-systemd.sh
) it is advisable to ensure that you have an X11 server on your Windows system that is listening for connections while using your WSL2 distro, else you might find some Linux commands stall or fail
- The
- Restart your WSL2 session