默認情況下在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