Window’s Subsystem for Linux doesn’t load Systemd by default, here’s how to turn it on.
I had read an article about running Ollama on a Raspberry Pi 5, and first wanted to try it on a WSL version of Debian (my distro of choice). The installation went fine, but I couldn’t get the damned thing to run. A quick Google search showed that installing Ollama also installs a Systemd service file, but when you run sudo systemctl start ollama
you get:
output: System has not been booted with systemd as init system (PID 1). Can't operate.
Which is annoying because so many applications rely on Systemd to start them running in the background when the system boots up. Another quick Google search shows how to enable it in WSL, although I’m at a loss for why it isn’t enabled by default. So here’s how you enable Systemd:
First update your installation of WSL:wsl --update
Your version of WSL must be 0.67.6 or newer, so check it:wsl --version
You also must also be using WSL 2, so type:wsl --set-default-version 2
wsl --set-version <DISTRO> 2
if everything went ok, then typing wsl --list --verbose
would give you something similar to this:
NAME STATE VERSION
* Debian Stopped 2
Now load up the distro you want to enable Systemd, and type nano /etc/wsl.conf
and enter the following:
[boot]
systemd=true
Now save your work (Ctrl + X, select Y to save your change), and then exit
your distro.
Type wsl.exe --shutdown
to restart WSL and all your distros. The next time you login to linux, type systemctl list-unit-files — type=service
to get a list of Systemd sevice files and their current state. Congrats! Systemd is working on your WSL distro.
Please note!
Apparently on Windows 10, you will need to have Windows Update KB5020030 or higher, for this to work. You can use windows update to install it or manually install it from here.