How to boot system with systemd as init system (PID 1)

I am using a Ubuntu terminal environment installed with Windows Subsystem for Linux (WSL). The version is Ubuntu 20.04.1 LTS (GNU/Linux 4.4.0-18362-Microsoft x86_64). Following instructions from various sites to setup a Wireguard VPN server on my WIndows 10 PC, I issue the following commands:

systemctl enable [email protected]
systemctl start [email protected]

This results in the following error message:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down.

I have spent several days researching and am now thoroughly confused about how to proceed. Can anyone please help me.


Solution 1:

Late answer, I know, but the Community bot apparently selected this question to "bump" today since it didn't have an answer. I'm not sure how useful this is, since the OP hasn't been on the site in 8 months, so even with Community bumping it to solicit answers, it's still unlikely to get an accepted answer, at least not anytime soon.

There are really three separate, but related questions you are posing:

  1. How to run Wireguard VPN on WSL. To do that, you have tried to to start the service using a Systemd unit file and systemctl. Leading to the next question ...

  2. How to start Systemd services/unit files on WSL. When you attempt that, you are getting an error message, that leads you to the question in your title ...

  3. How to boot with systemd as PID 1.

Let me start with (3). There's currently no way to run WSL using Systemd as PID 1. WSL uses it's own, proprietary, closed-source init (found in the root directory of every WSL distribution (i.e. /init) as PID 1. This is essential to the operation of WSL. It performs a number of critical functions such as bringing up the virtual network stack and many others. Please see my answer here for more information.

As for (2), that's not to say that you can't use Systemd's systemctl, but it's pretty dang difficult. I've never done it, to be honest, but you can find some information in this answer, among others.

Ubuntu on WSL does provide some, older-style SysVInit scripts for certain packages in /etc/init.d. So certain services can be started using the older service command (e.g. service ssh start). I'm guessing that's not the case for Wireguard, though.

But there's another way to "use" the Systemd unit files, and that's to determine what they are doing and replicate it. For instance, if you were on a distribution without service support for sshd, then you could look at the /usr/lib/systemd/system/ssh.service and see (among other lines):

ExecStartPre=/usr/sbin/sshd -t
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS

... so systemctl start ssh will first check the config (the -t), then start the service via the /usr/sbin/sshd -D $SSHD_OPTS command.

So regarding question (3), it might be possible to read the Wireguard unit file to determine how it starts up.

BUT ... it's going to be challenging, to say the least. For starters, according to the this page, Wireguard runs as a kernel module. And ... WSL's default kernel doesn't support adding modules.

According to this answer, it would be possible to build your own kernel to allow that. And that's backed up by this post that I found discussing how to install Wireguard in WSL. I'd recommend working through that and coming back to ask any questions on things that might not work in those instructions.