环境:
- cenos7(X86_64) + openssh
问题现象:
重新编译内容,使用linux调试工具后, 终端忽然中断, 再重启机器后。启动后显示。
Failed to switch root on boot
解决思路:
- 通过报错查找命令解决
搜索到一下链接 Problem with CentOS: Failed to switch root on boot
。。。
mount -o remount,rw /sysroot
cd /sysroot/etc
echo "" >os-release
mount -o remount,ro /sysroot
reboot
。。。
当时也没仔细看, 直接按照里面操作执行了下。
- 通过安装新操作系统挂载原有磁盘:
看了下简单操作无法回复,添加了一块硬盘,下载镜像安装,调整启动磁盘顺序
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdc2
VG Name centos00
PV Size <19.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4863
Free PE 1
Allocated PE 4862
PV UUID 。。。
--- Physical volume ---
PV Name /dev/sda3
VG Name centos
PV Size 59.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 15104
Free PE 0
Allocated PE 15104
PV UUID 。。。
看了之前的硬盘, 查看一下分区
[root@localhost ~]# lvscan
ACTIVE '/dev/centos00/swap' [1.00 GiB] inherit
ACTIVE '/dev/centos00/root' [17.99 GiB] inherit
ACTIVE '/dev/centos/root' [50.00 GiB] inherit
ACTIVE '/dev/centos/home' [5.00 GiB] inherit
ACTIVE '/dev/centos/swap' [4.00 GiB] inherit
进行挂载
[root@localhost ~]# mkdir /mnt/root
[root@localhost ~]# mkdir /mnt/home
[root@localhost ~]# mount /dev/centos/root /mnt/root
[root@localhost ~]# mount /dev//dev/centos/home /mnt/home
[root@localhost ~]# mount /dev/centos/home /mnt/home
[root@localhost ~]# cd /mnt
[root@localhost mnt]# cd home
[root@localhost home]# ls
agetest ftptest myquota myquota3 myquota5 pro1 pro3
checktimel lvm.dump myquota2 myquota4 myquotal pro2 weida
[root@localhost home]# cd ..
[root@localhost mnt]# cd root
[root@localhost root]# ls
etc lost+found
[root@localhost root]# cd etc
[root@localhost etc]# ls
os-release
[root@localhost etc]#
home下的文件找到了, root下的目前看来时丢失了, 应该是和之前执行操作有关, 可以看到里面的 os-release文件
上面链接里有一句
mount -o remount,rw /sysroot
是以可读写方式挂在分区, 这个操作很危险,
问题回顾:
- 出现问题后应先做备份处理,再进行操作, 针对这个场景就是先做一下镜像,这样如有问题能回复到之前的状态
- 对于挂在命令这个,rw 选项不是很熟悉导致直接使用使得磁盘数据丢失
- 网络的信息要先看清楚了再使用
- 有时候解决问题的方法就是绕开这个问题,比如第二种解决方案,通过新的系统进行挂载, 不是直接解决问题, 比起或者虚拟机我更关心里面的保存的数据。
参考及引用:
图片from twitter Ines B @moraimauy