五、模拟故障解决
1、grub-install方式解决
使用情况:1、grub被擦掉的时候。2、/boot/grub目录下的所有镜像文件都给删除时。 3、使用grub-install命令安装的grub并且boot/grub目录下stage2文件被误删除时(拷贝过去的stage2没有效果)。
[root@client ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 2.9G 1.6G 1.2G 56% /
tmpfs 246M 260K 246M 1% /dev/shm
/dev/sda1 97M 26M 67M 28% /boot
可以看出boot分区为独立分区,重新安装grub(系统默认为install方式)
[root@client ~]# grub-install hd0
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
# this device map was generated by anaconda
(hd0) /dev/sda
删除/boot/grub 下的stage2文件,或者移到其它目录下,然后重启
[root@client ~]# rm -f /boot/grub/stage2
[root@client ~]# reboot
这个时候我们只能进入linux rescue模式对系统进行修复了,而且只可以使用grub-install命令对系统进行修复。因为/boot/grub下的stage2文件已经被我们删掉了。原因是的安装源已被破坏。可以选择光盘安装,这里是pxe网络引导。局域网搭建见“pxe+kickstart搭建局域网环境”。
这里选择shell Start shell
然后重启,bios选择Hard Disk启动,可以看到启动成功了
2、setup方式解决
使用setup方式重装grub
[root@client ~]# grub
Probing devices to guess BIOS drives. This may take a long time.
GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
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
Running "embed /grub/e2fs_stage1_5 (hd0)"... 26 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+26 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> quit
[root@client ~]# rm -f /boot/grub/stage2
[root@client ~]# reboot
实验证明,当grub使用setup方式写入MBR中时,删除stage2之后,同样使用setup方式修复grub没有用,还得用grub-install?这是为什么,有清楚请告知一下。
当执行下面操作之后,只能使用grub-install方式修复了
[root@client grub]# shred -v stage2
shred: stage2: pass 1/3 (random)...
shred: stage2: pass 2/3 (random)...
shred: stage2: pass 3/3 (random)...
[root@client grub]# rm -fr stage2
[root@client grub]# reboot
3、install方式解决
[root@client ~]# grub
Probing devices to guess BIOS drives. This may take a long time.
GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
grub> install /grub/stage1 (hd0) /grub/stage2 p /grub/grub.conf
install /grub/stage1 (hd0) /grub/stage2 p /grub/grub.conf
grub> quit
[root@client ~]# rm -f /boot/grub/stage2
[root@client ~]# reboot
可以看到使用install安装的grub当删除stage2之后还能重启成功。
[root@client grub]# shred -v stage2
shred: stage2: pass 1/3 (random)...
shred: stage2: pass 2/3 (random)...
shred: stage2: pass 3/3 (random)...
[root@client grub]# reboot
这个时候系统不能再启动了,类似上面的用grub-install方式修复grub
4、删除grub.conf文件,修复系统
[root@client ~]# rm -f /boot/grub/grub.conf
[root@client ~]# reboot