WSL2 Systemd by changing the user's shell
September 3, 2020 ยท View on GitHub
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.shthat sets up some WSL2-specific environment that cannot be carried into the Systemd namespace easily. At the moment this is only thePATHvariable - Creates a file called
/usr/sbin/start-systemd-namespacethat is used to start Systemd inside a PID namespace so that Systemd is PID 1 - Creates a file called
/usr/bin/namespaced-shell-wrapper.shthat will callstart-systemd-namespaceto enter the systemd namespace. It will then execute your shell - Symlinks
namespaced-shell-wrapper.shalongside your current user shell's executable. For example, if you are running BASH with executable/bin/bashthen it will create the symlink as/bin/namespaced-bash - Modifies
/etc/pam.d/runuserto allow the usage of a user-specific environment override file that is enforced by the PAM subsystem. The file,$HOME/.pam_environmentis written by/usr/bin/namespaced-shell-wrapper.shand contains variables that should not change often - Finally, changes your user's configured shell with
chshto 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.shorinstall-systemd.sh.- The
install-all.shscript will execute bothinstall-systemd.shandinstall-gui-support.shto perform a complete install install-systemd.shwill 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.shafter 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