WSL中无法使用systemctl命令

发布时间 2023-09-03 18:04:45作者: Noncoretime

WSL使用system报错"System has not been booted with systemd as init system"


(原文链接)[https://linuxhandbook.com/system-has-not-been-booted-with-systemd/]

原因

The reason is that you are trying to use systemd command to manage services on Linux but your system doesn't use systemd and (most likely) using the classic SysV init (sysvinit) system.
大概原因是在一个无法在不适用systemd管理服务的系统(classic SysV)中使用systemctl
If you are using Ubuntu inside Windows using WSL, you will have SysV instead of systemd and your system will complain when you run the systemctl command (intended for Linux systems with systemd init system).
如果你在Windows电脑中使用Ubuntu系统(WSL),那么你应该使用的是SysV管理,而非systemctl。

如何查询当前机器的服务管理器

You may use this command to know the process name associated with PID 1 (the first process that runs on your system):
输入如下命令来查询当前PID为1的初始化系统(init system)

ps -p 1 -o comm=

替代方案

Systemd command Sysvinit command
systemctl start service_name service service_name start
systemctl restart service_name service service_name restart
systemctl stop service_name service service_name stop
systemctl status service_name service service_name status
systemctl enable service_name chkconfig service_name on
systemctl disable service_name chkconfig service_name off