救援模式,是一种在紧急情况下使用的系统救援方式,可以对系统中因意外丢失或被意外删除的系统文件 (是系统文件,非系统文件通过此模式是无法找回的)进行修复找回 。
       Linux系统的救援模式是一种特殊的系统模式,该模式是以光盘形式载入启动的,它也是一个独立的“简略”系 统,仍然具有正常系统的大部分功能,可以执行正常系统的绝大部分命令 。

救援模式应用(Centos7):

1.忘记、破解root口令

操作步骤:

开机启动,在出现内核选项时按"键盘e键"进行编辑;找到linux16行并在行尾添加内核参数 rd.break;并按ctrl+x进入单用户模式 
mount –o remount,rw /sysroot 
chroot /sysroot 
passwd root 
touch /.autorelabel 
exit 
reboot

#######或者
开机启动,在出现内核选项时按"键盘e键"进行编辑;找到linux16行将 rd 改成 rw ,并在行尾添加内核参数 rd.break;并按ctrl+x进入单用户模式 
chroot /sysroot 
passwd root 
touch /.autorelabel 
exit 
reboot

具体操作:

1.此时按下 e ,进入编辑模式

centos6救援 centos7救援_忘记密码


找到linux16行并在行尾添加内核参数 rd.break

centos6救援 centos7救援_忘记密码_02


按ctrl+x进入单用户模式

centos6救援 centos7救援_紧急救援_03


2.重新挂载 mount -o remount

centos6救援 centos7救援_修复_04


3.切换

centos6救援 centos7救援_紧急救援_05


4.重新设置root用户的密码,要设置成功才行

centos6救援 centos7救援_忘记密码_06


5.创建一个文件

centos6救援 centos7救援_重启_07


6.然后退出,重启,登录时输入新设置的密码即可。

2.grub破坏的修复

删除/boot/grub2后,重启页面出现的画面为

centos6救援 centos7救援_紧急救援_08

操作步骤:
 1. cd /boot/ 
 2. rm -rf grub*     #手动删除grub下的所有文件 
 3. 以光盘启动引导系统 (在进入虚拟机的瞬间按下F2)
 4. chroot /mnt/sysimage 
 5. ls /boot 
 6.mkdir /boot/grub2
 7.grub2-mkconfig -o /boot/grub2/grub.cfg 
 8.grub2-install /dev/sda
 9. exit 
 10. reboot
 11. 以光盘启动引导系统 (在进入虚拟机的瞬间按下F2,将修改的还原)
 12.重启即可

删除grub2

centos6救援 centos7救援_重启_09


以光盘启动引导系统 ,保存退出

centos6救援 centos7救援_重启_10


选择第三项

centos6救援 centos7救援_忘记密码_11


选择第二项,进入救援模式

centos6救援 centos7救援_紧急救援_12


进入救援模式操作

centos6救援 centos7救援_紧急救援_13


恢复以硬盘启动,保存退出

centos6救援 centos7救援_紧急救援_14


然后就可以正常启动虚拟机了

centos6救援 centos7救援_修复_15

3.破坏/boot目录,并修复

删除/boot/*后,重启页面为:

centos6救援 centos7救援_修复_16

操作步骤:
1. rm -rf /boot/* 
 2.reboot
 3. 以光盘启动引导系统 (在进入虚拟机的瞬间按下F2)
 4. chroot /mnt/sysimage 
 5. mount /dev/sr0 /mnt 
 6. rpm -ivh /mnt/Packages/kernel-3.10.0-693.e17.x86_64.rpm.rpm --force
 7. ls /boot 
 8. grub2-install /dev/sda 
 9. grub2-mkconfig -o /boot/grub2/grub.cfg 
 10. exit
 11.reboot
 12. 以光盘启动引导系统 (在进入虚拟机的瞬间按下F2,将修改的还原)
 13.重启即可

删除/boot/目录下的所有文件和目录

centos6救援 centos7救援_修复_17


以光盘模式启动(此步骤已在2中讲过,这里就不重复了)

进入救援模式操作

centos6救援 centos7救援_忘记密码_18


恢复以硬盘启动,保存退出(上面讲过)

然后就可以正常启动了。

centos6救援 centos7救援_重启_19

4.破坏grub2下的grub.cfg并修复

操作步骤:
1. cp /boot/grub2/grub.cfg grub.cfg.bak 
 2. rm -rf /boot/grub2/grub.cfg 
 3. init 6(重启)
 4. grub>insmod xfs  
     grub>set root=(hd0,1)
     grub>linux16 /vmlinuz-xxxxx root=/dev/mapper/centos-root
     grub>initrd16 /initramfs-.xxxxx.img   
     grub>boot   
 5. mv /root/grub2/grub.cfg.bak /boot/grub2/grub.cfg 
 6. init 6

删除/boot/grub2/grub.cfg

centos6救援 centos7救援_重启_20


重启后自动进入

centos6救援 centos7救援_修复_21


在此模式下进行以下操作

centos6救援 centos7救援_破坏grub_22


重启后进行以下操作

centos6救援 centos7救援_修复_23

然后再重新启动即可。