ubuntu踩坑

目录

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执行脚本

可以参考一下:

systemd启动流程分析_程序猿Ricky的日常干货的博客-CSDN博客_systemd启动顺序

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)

安装opencv的过程可能会遇到一些问题,下面是一些在Ubuntu 18.04上安装opencv时可能会遇到的常见问题及解决方法的指南。 1. 缺少依赖项:在安装opencv之前,确保已经安装了必需的依赖项。这包括cmake、build-essential、libgtk2.0-dev、pkg-config和python3-dev等。可以使用以下命令安装它们: ``` sudo apt-get install cmake build-essential libgtk2.0-dev pkg-config python3-dev ``` 2. 版本冲突:如果你的系统中已经安装了ROS-melodic,并且ROS-melodic中已经自带了opencv-3.2.0版本,你可能需要手动编译和安装opencv-3.2.0来覆盖ROS-melodic中的版本。首先下载opencv-3.2.0和opencv_contrib-3.2.0的源代码,并切换到opencv-3.2.0/build目录。然后使用make和make install命令进行编译和安装: ``` cd ~/Downloads/opencv_install/opencv-3.2.0/build/ make sudo make install ``` 3. 其他问题:在安装过程中可能会遇到其他问题,例如编译错误或链接错误。这些问题通常可以通过在安装过程中查找错误消息并搜索解决方案来解决。可以查看相关的安装教程、论坛或社区提供的文档以获取更多帮助。 总结起来,安装opencv的过程可能会因为缺少依赖项或版本冲突而出现问题。确保安装了必需的依赖项,并根据需要手动编译和安装适当的版本来解决版本冲突。在遇到其他问题时,可以查找相关的资源以获取更多帮助和解决方案。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Ubuntu18.04安装opencv 3.2.0的解决方法](https://download.csdn.net/download/weixin_38637983/12842575)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [在ubuntu18.04中安装opencv_contrib-3.2.0采教程](https://blog.csdn.net/hiram_zhang/article/details/103467737)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值