Linux基础知识

Grub文件的破坏与修复

2020-04-09  本文已影响0人  Stone_説

1. grub第1阶段

1.1 破坏BootLoader

[root@centos6 ~]# cd /boot/grub/
[root@centos6 grub]# ls
device.map     ffs_stage1_5      jfs_stage1_5    reiserfs_stage1_5  stage2           xfs_stage1_5
e2fs_stage1_5  grub.conf         menu.lst        splash.xpm.gz      ufs2_stage1_5
fat_stage1_5   iso9660_stage1_5  minix_stage1_5  stage1             vstafs_stage1_5
[root@centos6 grub]# hexdump -C /dev/sda -n 512
00000000  eb 48 90 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |.H..............|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..<.u...........|
000001b0  00 00 00 00 00 00 00 00  8a c7 0c 00 00 00 80 20  |............... |
000001c0  21 00 83 aa 28 82 00 08  00 00 00 00 20 00 00 aa  |!...(....... ...|
000001d0  29 82 83 fe ff ff 00 08  20 00 00 80 1a 06 00 fe  |)....... .......|
000001e0  ff ff 83 fe ff ff 00 88  3a 06 00 00 71 02 00 fe  |........:...q...|
000001f0  ff ff 05 fe ff ff 00 88  ab 08 00 78 54 10 55 aa  |...........xT.U.|
00000200
[root@centos6 grub]# dd if=/dev/zero of=/dev/sda bs=1 count=446
446+0 records in
446+0 records out
446 bytes (446 B) copied, 0.000783816 s, 569 kB/s
[root@centos6 grub]# hexdump -C /dev/sda -n 512
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 80 20  |............... |
000001c0  21 00 83 aa 28 82 00 08  00 00 00 00 20 00 00 aa  |!...(....... ...|
000001d0  29 82 83 fe ff ff 00 08  20 00 00 80 1a 06 00 fe  |)....... .......|
000001e0  ff ff 83 fe ff ff 00 88  3a 06 00 00 71 02 00 fe  |........:...q...|
000001f0  ff ff 05 fe ff ff 00 88  ab 08 00 78 54 10 55 aa  |...........xT.U.|
00000200
[root@centos6 grub]# hexdump -C /dev/sda -n 512 -v
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001d0  29 82 83 fe ff ff 00 08  20 00 00 80 1a 06 00 fe  |)....... .......|
000001e0  ff ff 83 fe ff ff 00 88  3a 06 00 00 71 02 00 fe  |........:...q...|
000001f0  ff ff 05 fe ff ff 00 88  ab 08 00 78 54 10 55 aa  |...........xT.U.|
00000200

1.2 重启并查看错误状态

开机画面.png
进入救援模式.png

1.3 进入救援模式

修复.png
查看结果.png

1.4 修复成功

修复成功.png
NOTE:用上述方式修复,具有一定的局限性,就是/boot/grub中的文件一定要在文件夹中,如下所示:
[root@localhost ~]# cd /boot/grub
[root@localhost grub]# ls
device.map     ffs_stage1_5      jfs_stage1_5    reiserfs_stage1_5  stage2           xfs_stage1_5
e2fs_stage1_5  grub.conf         menu.lst        splash.xpm.gz      ufs2_stage1_5
fat_stage1_5   iso9660_stage1_5  minix_stage1_5  stage1             vstafs_stage1_5

如果grub文件被整体移除,则需要使用以下方法进行修复。

2. grub第1.5阶段

2.1 破环分区(修复方法二)

[root@localhost ~]# cd /boot/grub
[root@localhost grub]# ls
device.map     ffs_stage1_5      jfs_stage1_5    reiserfs_stage1_5  stage2           xfs_stage1_5
e2fs_stage1_5  grub.conf         menu.lst        splash.xpm.gz      ufs2_stage1_5
fat_stage1_5   iso9660_stage1_5  minix_stage1_5  stage1             vstafs_stage1_5
[root@localhost grub]# mv * /data/
[root@localhost grub]# pwd
/boot/grub
[root@localhost grub]# ls
[root@localhost grub]# dd if=/dev/zero of=/dev/sda bs=1 count=446
446+0 records in
446+0 records out
446 bytes (446 B) copied, 0.00132816 s, 336 kB/s
[root@localhost grub]# hexdump -C -n 512 /dev/sda
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 80 20  |............... |
000001c0  21 00 83 aa 28 82 00 08  00 00 00 00 20 00 00 aa  |!...(....... ...|
000001d0  29 82 83 fe ff ff 00 08  20 00 00 80 1a 06 00 fe  |)....... .......|
000001e0  ff ff 83 fe ff ff 00 88  3a 06 00 00 71 02 00 fe  |........:...q...|
000001f0  ff ff 05 fe ff ff 00 88  ab 08 00 78 54 10 55 aa  |...........xT.U.|
00000200

2.2 尝试用第一种方法修复

[root@localhost grub]# 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... no

Error 15t: File not found
grub> quit
quit

使用第一种方法进行修复,发现不可行

2.3 使用grub-install命令修复

[root@localhost grub]# grub-install /dev/sda
Probing devices to guess BIOS drives. This may take a long time.
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'.

(fd0)   /dev/fd0
(hd0)   /dev/sda
[root@localhost grub]# hexdump -C -n 512 /dev/sda
00000000  eb 48 90 00 00 00 00 00  00 00 00 00 00 00 00 00  |.H..............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 03 02  |................|
00000040  ff 00 00 20 01 00 00 00  00 02 fa 90 90 f6 c2 80  |... ............|
00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 f6 c2 80  |. ..@|<.t...R...|
00000070  74 54 b4 41 bb aa 55 cd  13 5a 52 72 49 81 fb 55  |tT.A..U..ZRrI..U|
00000080  aa 75 43 a0 41 7c 84 c0  75 05 83 e1 01 74 37 66  |.uC.A|..u....t7f|
00000090  8b 4c 10 be 05 7c c6 44  ff 01 66 8b 1e 44 7c c7  |.L...|.D..f..D|.|
000000a0  04 10 00 c7 44 02 01 00  66 89 5c 08 c7 44 06 00  |....D...f.\..D..|
000000b0  70 66 31 c0 89 44 04 66  89 44 0c b4 42 cd 13 72  |pf1..D.f.D..B..r|
000000c0  05 bb 00 70 eb 7d b4 08  cd 13 73 0a f6 c2 80 0f  |...p.}....s.....|
000000d0  84 f0 00 e9 8d 00 be 05  7c c6 44 ff 00 66 31 c0  |........|.D..f1.|
000000e0  88 f0 40 66 89 44 04 31  d2 88 ca c1 e2 02 88 e8  |..@f.D.1........|
000000f0  88 f4 40 89 44 08 31 c0  88 d0 c0 e8 02 66 89 04  |..@.D.1......f..|
00000100  66 a1 44 7c 66 31 d2 66  f7 34 88 54 0a 66 31 d2  |f.D|f1.f.4.T.f1.|
00000110  66 f7 74 04 88 54 0b 89  44 0c 3b 44 08 7d 3c 8a  |f.t..T..D.;D.}<.|
00000120  54 0d c0 e2 06 8a 4c 0a  fe c1 08 d1 8a 6c 0c 5a  |T.....L......l.Z|
00000130  8a 74 0b bb 00 70 8e c3  31 db b8 01 02 cd 13 72  |.t...p..1......r|
00000140  2a 8c c3 8e 06 48 7c 60  1e b9 00 01 8e db 31 f6  |*....H|`......1.|
00000150  31 ff fc f3 a5 1f 61 ff  26 42 7c be 7f 7d e8 40  |1.....a.&B|..}.@|
00000160  00 eb 0e be 84 7d e8 38  00 eb 06 be 8e 7d e8 30  |.....}.8.....}.0|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..<.u...........|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 80 20  |............... |
000001c0  21 00 83 aa 28 82 00 08  00 00 00 00 20 00 00 aa  |!...(....... ...|
000001d0  29 82 83 fe ff ff 00 08  20 00 00 80 1a 06 00 fe  |)....... .......|
000001e0  ff ff 83 fe ff ff 00 88  3a 06 00 00 71 02 00 fe  |........:...q...|
000001f0  ff ff 05 fe ff ff 00 88  ab 08 00 78 54 10 55 aa  |...........xT.U.|
00000200

NOTE:修复成功

2.4 破坏1.5阶段

[root@localhost grub]# dd if=/dev/zero of=/dev/sda bs=1 count=10240 seek=512
10240+0 records in
10240+0 records out
10240 bytes (10 kB) copied, 0.0157677 s, 649 kB/s
[root@localhost grub]# hexdump -C -n 10240 /dev/sda
00000000  eb 48 90 00 00 00 00 00  00 00 00 00 00 00 00 00  |.H..............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 03 02  |................|
00000040  ff 00 00 20 01 00 00 00  00 02 fa 90 90 f6 c2 80  |... ............|
00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 f6 c2 80  |. ..@|<.t...R...|
00000070  74 54 b4 41 bb aa 55 cd  13 5a 52 72 49 81 fb 55  |tT.A..U..ZRrI..U|
00000080  aa 75 43 a0 41 7c 84 c0  75 05 83 e1 01 74 37 66  |.uC.A|..u....t7f|
00000090  8b 4c 10 be 05 7c c6 44  ff 01 66 8b 1e 44 7c c7  |.L...|.D..f..D|.|
000000a0  04 10 00 c7 44 02 01 00  66 89 5c 08 c7 44 06 00  |....D...f.\..D..|
000000b0  70 66 31 c0 89 44 04 66  89 44 0c b4 42 cd 13 72  |pf1..D.f.D..B..r|
000000c0  05 bb 00 70 eb 7d b4 08  cd 13 73 0a f6 c2 80 0f  |...p.}....s.....|
000000d0  84 f0 00 e9 8d 00 be 05  7c c6 44 ff 00 66 31 c0  |........|.D..f1.|
000000e0  88 f0 40 66 89 44 04 31  d2 88 ca c1 e2 02 88 e8  |..@f.D.1........|
000000f0  88 f4 40 89 44 08 31 c0  88 d0 c0 e8 02 66 89 04  |..@.D.1......f..|
00000100  66 a1 44 7c 66 31 d2 66  f7 34 88 54 0a 66 31 d2  |f.D|f1.f.4.T.f1.|
00000110  66 f7 74 04 88 54 0b 89  44 0c 3b 44 08 7d 3c 8a  |f.t..T..D.;D.}<.|
00000120  54 0d c0 e2 06 8a 4c 0a  fe c1 08 d1 8a 6c 0c 5a  |T.....L......l.Z|
00000130  8a 74 0b bb 00 70 8e c3  31 db b8 01 02 cd 13 72  |.t...p..1......r|
00000140  2a 8c c3 8e 06 48 7c 60  1e b9 00 01 8e db 31 f6  |*....H|`......1.|
00000150  31 ff fc f3 a5 1f 61 ff  26 42 7c be 7f 7d e8 40  |1.....a.&B|..}.@|
00000160  00 eb 0e be 84 7d e8 38  00 eb 06 be 8e 7d e8 30  |.....}.8.....}.0|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..<.u...........|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 80 20  |............... |
000001c0  21 00 83 aa 28 82 00 08  00 00 00 00 20 00 00 aa  |!...(....... ...|
000001d0  29 82 83 fe ff ff 00 08  20 00 00 80 1a 06 00 fe  |)....... .......|
000001e0  ff ff 83 fe ff ff 00 88  3a 06 00 00 71 02 00 fe  |........:...q...|
000001f0  ff ff 05 fe ff ff 00 88  ab 08 00 78 54 10 55 aa  |...........xT.U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002800

2.5 进入救援模式

救援模式.png
设置启动项.png

2.6 将conf文件补齐

[root@localhost ~]# cd /boot/grub/
[root@localhost grub]# ls
device.map     fat_stage1_5  grub.conf         jfs_stage1_5    reiserfs_stage1_5  stage2         vstafs_stage1_5
e2fs_stage1_5  ffs_stage1_5  iso9660_stage1_5  minix_stage1_5  stage1             ufs2_stage1_5  xfs_stage1_5
[root@localhost grub]# vim grub.conf ^C
[root@localhost grub]# cat grub.conf 
default=0
timeout=5
title test linux
kernel /vmlinuz-2.6.32-754.el6.x86_64 root=/dev/sda2 
initrd /initramfs-2.6.32-754.el6.x86_64.img

2.7 重启,修复成功

image.png
image.png
上一篇下一篇

猜你喜欢

热点阅读