默认情况下在wsl2中使用systemctl命令会报错
$ sudo systemctl status cron.service
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
解决办法:
-
安装daemonize
sudo apt-get install daemonize
-
执行以下两句命令开启
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME