目录
1.下载后切换到root
2.关机命令使用出现:System has not been booted with systemd as init system (PID 1). Can't operate.
使用场景描述:
心血来潮使用windows下的wsl进行使用练习,随便玩玩;安装了ubuntu
1.下载后切换到root
“ubuntu 默认的 root 用户是没有固定密码的,它的密码是随机产生并且动态改变的,即每次开机都有一个新的 root 密码,如果想查看 root 密码,那么直接设置的 root 密码即可。”
所以:刚下载的ubuntu是没有root密码的,而且是随机的。。。
1. sudo passwd
2.su root
hml@LAPTOP-9M23AK3R:/$ sudo passwd
[sudo] password for hml:
New password:
Retype new password:
passwd: password updated successfully
hml@LAPTOP-9M23AK3R:/$ su root
Password:
root@LAPTOP-9M23AK3R:/#
2.关机命令使用出现:System has not been booted with systemd as init system (PID 1). Can't operate.
使用描述:poweroff ,shutdown都尝试无效,切换到root下也无效
root@LAPTOP-9M23AK3R:/# shutdown
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 operate.
Failed to connect to bus: Host is down
Failed to talk to init daemon.
root@LAPTOP-9M23AK3R:/# poweroff
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Failed to talk to init daemon.
root@LAPTOP-9M23AK3R:/# logout
bash: logout: not login shell: use `exit'
root@LAPTOP-9M23AK3R:/# reboot
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Failed to talk to init daemon.
解决方案:翻译错误描述:systemd作为init系统(PID 1),系统尚未启动,无法操作。
猜测:shutdown,poweroff,reboot命令使用需要安装并启动systemd
1.什么是systemd(看看就行)
systemd即为system daemon,是linux下的一种init软件,由Lennart Poettering带头开发,并在LGPL 2.1及其后续版本许可证下开源发布,开发目标是提供更优秀的框架以表示系统服务间的依赖关系,并依此实现系统初始化时服务的并行启动,同时达到降低Shell的系统开销的效果,最终代替常用的System V与BSD风格init程序。
与多数发行版使用的System V风格init相比,systemd采用了以下新技术: (1) 采用Socket激活式与总线激活式服务,以提高相互依赖的各服务的并行运行性能; (2) 用Cgroups代替PID来追踪进程,因此即使是两次fork之后生成的守护进程也不会脱离systemd的控。
别人的解释:
systemd是一个跟随开发板的系统预装工具,用来管理软件启动和停止,一般来说ubuntu16以及以上的版本基本都有这个预装工具。如果系统已经预装了systemd,那么就可以用它来管理进程,反之如果没有,即使安装了,也不会被默认配置为系统管理工具。
2.确定是否安装,最好在root下,或者命令前面加sudo
systemctl --version 或者 systemd --version
systemd --version
root@LAPTOP-9M23AK3R:/# systemd --version
systemd 245 (245.4-4ubuntu3)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid
root@LAPTOP-9M23AK3R:/# systemctl --version
systemd 245 (245.4-4ubuntu3)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid
3.查看systemd服务运行状态
systemctl
是最核心的命令,用于系统管理。
查看系统状态:systemctl status
root@LAPTOP-9M23AK3R:/# systemctl status
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
重启系统:systemctl reboot
关机:systemctl poweroff
停止cpu命令:systemctl halt
哪天有空了再写一篇关于这个命令的博客//TODO
启动,停止,重启服务:
systemctl start myservice.service
systemctl stop myservice.service
systemctl restart myservice.service
root@LAPTOP-9M23AK3R:/# systemctl start myservice.service
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
root@LAPTOP-9M23AK3R:/# hostnamectl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
root@LAPTOP-9M23AK3R:/# service start
start: unrecognized service
root@LAPTOP-9M23AK3R:/# service start myservice.service
start: unrecognized service
root@LAPTOP-9M23AK3R:/# service httpd start
httpd: unrecognized service
报错了,所以这个不对;而且参考百度说的是wsl2使用需要更换命令,用SysV init
的命令代替systemd,
就是这个,失败了可能我是用的方式不太对,希望大佬指出;
//这不他妈的又能写一篇SysV init 巨复杂TODO;
3.这个时候想起了初衷,安装的systemd在 /etc下
或者直接找 find / -name 'systemd'
root@LAPTOP-9M23AK3R:/etc/init.d# find / -name 'systemd'
/etc/systemd
/etc/xdg/systemd
进入里面发现自启动方式过于复杂,下载的版本缺少wifi执行脚本
可以参考一下:
docs/0007_Systemd进程启动.md · LowLevelOfLogic/RaspberryPi - Gitee.com
用上面的方法没成功,太菜了,理解不了,来个大佬教教我
最后解决方法:
由于是在windows商店直接下载的ubuntu,可能版本原因没有与wsl2对应的支持systemd启动脚本
所以直接在百度上下载一个支持的脚本即可;
1.首先安装git
sudo apt install git
2.获得脚本并运行
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
3.重新启动ubuntu,关闭powershell即可(一定要在上面的执行成功后)
4.重新进入powershell ,进入ubuntu,执行systemctl
5.测试poweroff命令使用完成
不支持ifconfig
下载一波就完事了,提示人家都给
hml@LAPTOP-9M23AK3R:/$ ifconfig
Command 'ifconfig' not found, but can be installed with:
sudo apt install net-tools
hml@LAPTOP-9M23AK3R:/$ sudo apt install net-tools
[sudo] password for hml:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
net-tools
0 upgraded, 1 newly installed, 0 to remove and 261 not upgraded.
Need to get 196 kB of archives.
After this operation, 864 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Fetched 196 kB in 3s (62.9 kB/s)
Selecting previously unselected package net-tools.
(Reading database ... 31871 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
hml@LAPTOP-9M23AK3R:/$
hml@LAPTOP-9M23AK3R:/$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.28.11.48 netmask 255.255.240.0 broadcast 172.28.15.255
inet6 fe80::215:5dff:fe35:9a22 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:35:9a:22 txqueuelen 1000 (Ethernet)
RX packets 498 bytes 244166 (244.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 244 bytes 18968 (18.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)