服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Linux - 报错:System has not been booted with systemd as init system

报错:System has not been booted with systemd as init system

2023-05-08 17:12未知服务器之家 Linux

很多朋友在网上某些教程中学习了 systemd,然后实际练习的时候,使用 systemd 命令(比如 sudo systemctl start),可能会遇到一个报错信息: System has not been booted with systemd as init system (PID 1 ). Can 't operate. 这是什么意思呢?翻译过来就是

报错:System has not been booted with systemd as init system

很多朋友在网上某些教程中学习了 systemd,然后实际练习的时候,使用 systemd 命令(比如 sudo systemctl start),可能会遇到一个报错信息:

System has not been booted with systemd as init system (PID 1). Can't operate.

这是什么意思呢?翻译过来就是:“系统尚未以systemd作为初始系统启动”。

为什么会出现这样的报错信息呢?

原因是当你尝试使用 systemd 命令来管理 Linux 系统上的服务的时候,但是系统中根本就没有使用 systemd,而是(很可能)使用的 SysV init (sysvinit)

这是怎么回事呢?

如果你是在 windows 中通过 WSL 使用的 Ubuntu,默认情况下系统使用的是 SysV 而不是 systemd。当你使用 systemctl 命令(适用于有 systemd init 的系统)的时候,系统自然会报错。

那么怎样查看到底用的是哪个 init 系统呢?可以使用如下命令来检查 PID 为 1 的进程(即系统运行的第一个进程)名称:

ps -p 1 -o comm=

它应该在输出中显示 init 或 sysv(或类似的东西)。如果你看到的是 init,那么你的系统就没有使用 systemd,应该使用 init 命令。

如何修复 System has not been booted with systemd 报错信息?

最简单的方式就是不使用 systemctl 命令,而是使用 sysvinit 命令。

sysvinit 也不复杂,它与 systemctl 命令的语法相似。如下表格为两个命令的对比:

Systemd command

Sysvinit command

systemctl start service_name

service service_name start

systemctl stop service_name

service service_name stop

systemctl restart service_name

service service_name restart

systemctl status service_name

service service_name status

systemctl enable service_name

chkconfig service_name on

systemctl disable service_name

chkconfig service_name off

大家在初始学习的时候,如果遇到类似的错误,可以尝试使用上面表格中等效的命令,就不会看到 "System has not been booted with systemd as init system" 这样的报错信息了。

延伸 · 阅读

精彩推荐