Centos修复boot分区

1,对比boot分区: 完整的/损坏的

[root@localhost ~]# lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  1024M  0 rom  
sda      8:0    0    48G  0 disk 
├─sda1   8:1    0   200M  0 part /boot
├─sda2   8:2    0     5G  0 part /
└─sda3   8:3    0     1G  0 part [SWAP]
sdb      8:16   0    28G  0 disk 
├─sdb1   8:17   0 305.9M  0 part 
├─sdb2   8:18   0    25G  0 part 
└─sdb3   8:19   0   2.7G  0 part 

#1,查看完整的boot分区数据
[root@localhost ~]# dd if=/dev/sda of=mr.bak count=1 bs=512
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000209593 s, 2.4 MB/s
[root@localhost ~]# sync
[root@localhost ~]# file mr.bak
mr.bak: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x62bc, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 409600 sectors; partition 2: ID=0x83, starthead 159, startsector 411648, 10485760 sectors; partition 3: ID=0x82, starthead 84, startsector 10897408, 2097152 sectors, code offset 0x48

#2,查看损坏的boot分区数据
[root@localhost ~]# dd if=/dev/zero of=/dev/sda count=1 bs=300
1+0 records in
1+0 records out
300 bytes (300 B) copied, 0.00140651 s, 213 kB/s
[root@localhost ~]# sync
[root@localhost ~]# dd if=/dev/sda of=mr.bak.break count=1 bs=512
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000219264 s, 2.3 MB/s
[root@localhost ~]# file mr.bak.break 
mr.bak.break: x86 boot sector; partition 1: ID=0x83, active, starthead 32, startsector 2048, 409600 sectors; partition 2: ID=0x83, starthead 159, startsector 411648, 10485760 sectors; partition 3: ID=0x82, starthead 84, startsector 10897408, 2097152 sectors, code offset 0x0

2, 修复boot分区

2.1 , 系统还能运行时: grub-install 修复

# grub-install 修复损坏的boot分区
[root@localhost ~]# grub-install --root-directory=/ /dev/sda
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
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# dd if=/dev/zero of=/dev/sda count=1 bs=200
1+0 records in
1+0 records out
200 bytes (200 B) copied, 0.000935312 s, 214 kB/s

2.2 , 系统不能运行时: grub命令行 修复

# grub命令行 修复损坏的boot分区
[root@localhost ~]# 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)"...  27 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> quit
quit
[root@localhost ~]# sync
发布了276 篇原创文章 · 获赞 37 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/eyeofeagle/article/details/103843413