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模板网!

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

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

相关文章

  • 小程序报错:Page “pages/index/index“ has not been registered yet

    提示:这里简述项目相关背景: 例如:项目场景:通过复制粘贴小程序页面时,微信开发者工具展示页面没有显示。 提示:这里描述项目中遇到的问题: 例如:在VSCode中复制粘贴Page里面的内容,撤回后小程序的内容没有展示。: 提示:这里填写问题的分析: 例如:暂时看

    2024年02月12日
    浏览(26)
  • webpack.config.js配置文件报错:The ‘mode‘ option has not been set

    报错 WARNING in configuration The \\\'mode\\\' option has not been set, webpack will fallback to \\\'production\\\' for this value. Set \\\'mode\\\' option to \\\'development\\\' or \\\'production\\\' to enable defaults for each environment. You can also set it to \\\'none\\\' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/ 解决: 在package.json文件

    2024年01月20日
    浏览(45)
  • 报错:CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘. 问题解决

    今天在VS code里跑一个小网络,想先切换conda环境,发现无法切换了,并提示报错为: 查了下原因,大概意思是初次使用Anaconda时,没有预先对命令行进行预载。解决办法非常简单,在上文报错的提示中也说明了,根据提示运行对应的命令即可 即,在windows下,终端中输入 在

    2024年02月11日
    浏览(37)
  • 服务器报错解决:CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘.T

           在一个新的服务器端口创建完虚拟环境后,显示报错信息 CommandNotFoundError: Your shell has not been properly configured to use \\\'conda activate\\\'. To initialize your shell, run $ conda init SHELL_NAME Currently supported shells are: - bash - fish - tcsh - xonsh - zsh - powershell See \\\'conda init --help\\\' for more information and

    2024年02月04日
    浏览(33)
  • detectron2报错解决方案 RuntimeError: Default process group has not been initialized, please make sure to c

    问题:RuntimeError: Default process group has not been initialized, please make sure to call init_process_group. 解决 : github503问题,解决方案,windows环境使用detectron2 # 503

    2024年02月12日
    浏览(37)
  • windows11启动docker报错:Docker Desktop - Unexpected WSL error

    问题描述 windows11启动docker(版本为4.26.1)报错: Docker Desktop - Unexpected WSL error An unexpected error was encountered while executing a WSL command. Common causes include access rights issues, which occur after waking the computer or not being connected to your domain/active directory. Please try shutting WSL down (wsl -shutdown) and/or

    2024年04月12日
    浏览(32)
  • LateInitializationError: Field ‘data‘ has not been initialized.

    问题描述: LateInitializationError: Field \\\'data\\\' has not been initialized. 后期初始化错误:字段“数据”尚未初始化。  解决办法: 给data定义为空即可。 源代码: 修改后的代码: 参考链接:[Solved] LateInitializationError: Field has not been initialized 感谢群里的大佬提供的帮助!

    2024年02月13日
    浏览(27)
  • lateinit property has not been initialized加载失败Android

    本来我是想在onCreate之外使用swipeRefresh全局变量的,后面在调试的时候就出现了上述问题。 重新看一了一遍,发现是用错语法了,lateinit是用在var修饰变量的,对val变量应该使用by lazy,所以对于控件类的变量应该使用by lazy并且是不可变的,下面这张图就是错误用法了: 正确

    2024年02月16日
    浏览(32)
  • ERROR: your rosdep installation has not been initialized yet

    这个错误表示你的 rosdep 还没有初始化。rosdep 是一个 ROS 中的系统依赖管理工具,用于安装和配置需要的系统依赖包。在使用 rosdep 之前,需要先通过  rosdep update  命令初始化它。这个命令会连接远程服务器来更新 rosdep 的数据源,以获取所有支持的 ROS 版本和平台的依赖信息。所

    2024年02月09日
    浏览(32)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包