实例二:
破坏本机grub stage1,在不重启的情况下修复号grub。
用dd命令破坏grub:
[root@localhost ~]# dd if=/dev/sda of=/tmp/mbr.bak count=1 bs=512 //先备份MBR;1+0 records in1+0 records out512 bytes (512 B) copied, 0.000376481 s, 1.4 MB/s[root@localhost ~]# [root@localhost ~]# dd if=/dev/zero of=/dev/sda count=1 bs=100 //开始执行破坏操作;1+0 records in1+0 records out100 bytes (100 B) copied, 0.0010733 s, 93.2 kB/s//注意:破坏其前446Bytes即可。修复grub:
方式一:[root@localhost ~]# grub-install --root-directory=/ /dev/sda方式二:[root@localhost ~]# dd if=/dev/zero of=/dev/sda count=1 bs=1001+0 records in1+0 records out100 bytes (100 B) copied, 0.000691542 s, 145 kB/s[root@localhost ~]# grub.....(中间省略).....grub> grub> root (hd0,0) //查看设备;root (hd0,0) Filesystem type is ext2fs, partition type 0x83grub> grub> setup (hd0) //安装grub;setup (hd0) Checking if "/boot/grub/stage1" exists... no Checking if "/grub/stage1" exists... yes Checking if "/grub/stage2" exists... yes Checking if "/grub/e2fs_stage1_5" exists... yes //这里只安装对应文件系统的stage1.5文件(当前为ext4文件系统); Running "embed /grub/e2fs_stage1_5 (hd0)"... 27 sectors are embedded.succeeded Running "install /grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeededDone.grub> grub> quitquit[root@localhost ~]#//注意:在grub命令行之下执行setup安装时,它会自动去读取指定设备的/boot/grub目录下的stage1、stage1.5以及stage2文件,如果被破坏或者不存在则重新安装。实例三:
破坏本机grub stage1,而后在救援模式下修复之。
破坏grub:
[root@localhost ~]# dd if=/dev/zero of=/dev/sda count=1 bs=1001+0 records in1+0 records out100 bytes (100 B) copied, 0.000432857 s, 231 kB/s重新启动,因为硬盘上的grub程序被破坏,这时第一个被扫描到有bootloader的是光盘,所以直接进入光盘,看到如下界面,这里选择进入救援模式:

系统提示会将原有的根文件系统挂载至光盘系统的/mnt/sysimage目录下,选择"Continue"。



点击"OK"进入光盘的shell:

执行根切换,并安装grub,而后重新启动:

这样就可以正常启动系统了。
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141971.htm
