Windows11 WSL中Llinux报错:System has not been booted with systemd as init system (PID 1). Can‘t operate

这篇具有很好参考价值的文章主要介绍了Windows11 WSL中Llinux报错:System has not been booted with systemd as init system (PID 1). Can‘t operate。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1.序

在Windows11中安装Ubuntu,运行docker报错,安装步骤如下

Windows11 微软商店安装ubuntu子系统
Linux Ubuntu安装Docker

在Windows中使用WSL的Ubuntu时,使用systemctl命令报错:

hh@LAPTOP-O6A604DC:~$ systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl

2.问题分析

可能是因为这个Ubuntu系统并没有使用systemd,可能使用的是SysV init(sysvinit)初始化系统。
可以通过如下命令查看:

 ps -p 1

system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl
system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl

果真如此,CMD 列,显示 init,可以确定使用的是SysV init初始化系统。

SysV init:如果您的系统使用 SysVinit 作为 init 系统,您可以使用 service 命令来管理和检查服务状态。例如,要检查 Docker 服务状态,可以运行:

sudo service docker status

什么是Systemd?
Systemd是Linux系统的一套基本构建模块。它提供了一个系统和服务管理器,作为PID 1运行并启动系统的其余部分。
systemctl作为systemd的一个工具,提供与Linux机器上的服务交互

3.问题解决

3.1.方案1:

还是想要使用systemd,在WSL中启用systemd
先决条件:确保运行的是来自 Microsoft Store 且版本号为0.67.6及以上版本的WSL
更新WSL到最新版

wsl --update

查看版本

wsl --version

system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl

将 WSL 2 设置为默认版本 如果是WSL1,也是默认有wls.conf文件,但是就是不支持systemtcl命令,必须设置成WLS

wsl --set-default-version 2

运行命令查看版本

wsl -l -v

system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl
在Ubuntu实例中,打开或者添加/etc/wsl.conf文件(我这里已经安装这个了,没有的话手动添加),并编辑内容如下:

[boot]
systemd=true

system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl
system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl

然后使用wsl --shutdown命令,将运行中的Linux发行版关闭。
重新运行Ubuntu。
再次查看初始化信息,可以看出已经使用了systemd,

运行查询systemctl版本,非常完美,已经可以用了
system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl
已启动成功,查询正常
system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl

3.2.方案2:

这个错误表明系统没有以 systemd 作为 init 系统来引导(PID 1)。这可能是因为系统正在使用其他 init 系统(如 Upstart 或 SysVinit)。因此,在尝试使用 systemctl 命令时会出现问题,因为该命令是与 systemd 相关的。

如果系统没有使用 systemd 作为 init 系统,需要使用适合你的 init 系统的命令来检查服务状态。以下是一些常见 init 系统的示例:

Upstart:如果您的系统使用 Upstart 作为 init 系统,您可以使用 initctl 命令来检查服务状态。例如,要检查 Docker 服务状态,可以运行:

sudo initctl status docker

SysVinit:如果您的系统使用 SysVinit 作为 init 系统,您可以使用 service 命令来管理和检查服务状态。例如,要检查 Docker 服务状态,可以运行:

sudo service docker status

结果可用生效
system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl
已启动成功,查询正常
system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl

4.验证两种命令都可查询使用,完美

system has not been booted with systemd as init system (pid 1). can't operat,应用部署,Windows子系统,ubuntu,wsl

官方文档:
https://learn.microsoft.com/zh-cn/windows/wsl/install-manual
参考帖子:
https://blog.csdn.net/B11050729/article/details/132498547
https://blog.csdn.net/m0_68736501/article/details/130289727
https://blog.csdn.net/qq_44610529/article/details/126488898
https://blog.csdn.net/weixin_41982608/article/details/132310451文章来源地址https://www.toymoban.com/news/detail-774088.html

到了这里,关于Windows11 WSL中Llinux报错:System has not been booted with systemd as init system (PID 1). Can‘t operate的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包