在windows 11中的Ubuntu里使用systemctl时遇到了这样的错误:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
在Ubuntu里,systemctl常常用于启用一个服务,但在WSL中常使用的应是:
sudo service <servicename> start
这个问题的主要原因是WSL不使用Systemd,如何它使用呢?在/etc/下加个配置文件wsl.conf,如果已经存在,编辑这个文件。
在里面添加两行:
[boot]
systemd=true
保存之后,使用exit退出Ubuntu(直到命令窗口自己关闭),打开windows的cmd命令窗口输入:wsl --shutdown,然后再启动Ubuntu,这个时候,systemctl已经可以使用了。
sudo systemctl status
