手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux 灾难恢复 Linux 系统启动故障修复

[日期:2012-09-21] 来源:IBM  作者:祝 珍泉, 软件工程师, IBM [字体:大 中 小]

我们查询系统磁盘信息,发现硬盘设备 sda 没有包含任何分区。

 bash-4.1# fdik – l 

 Disk /dev/sda: 43.0 GB, 42991616000 bytes 
 255 heads, 63 sectors/track, 5226 cylinders 
 Units = cylinders of 16065 * 512 = 8225280 bytes 
 Sector size (logical/physical): 512 bytes / 512 bytes 
 I/O size (minimum/optimal): 512 bytes / 512 bytes 
 Disk identifier: 0x00032735 

   Device Boot      Start         End      Blocks   Id  System 

 Disk /dev/sdb: 2147 MB, 2147483648 bytes 
 255 heads, 63 sectors/track, 261 cylinders 
 Units = cylinders of 16065 * 512 = 8225280 bytes 
 Sector size (logical/physical): 512 bytes / 512 bytes 
 I/O size (minimum/optimal): 512 bytes / 512 bytes 
 Disk identifier: 0xcdd48395 

   Device Boot      Start         End      Blocks   Id  System 
 /dev/sdb1               1         261     2096451   83  Linux 

 

我们来恢复它的硬盘分区表,创建一个目录并且挂载之前备份的 USB 设备,我们看到它的设备名是 /dev/sdb。

 bash-4.1# mount /dev/sdb1 /usb 
 bash-4.1# ls /usb 
 lost+found  sda.mbr 

 

通过原来备份的 sda.mbr 文件来恢复硬盘设备 sda 的硬盘分区表 :

 bash-4.1# dd if=/usb/sda.mbr of=/dev/sda bs=1 count=64 skip=446 seek=446 
 64+0 records in 
 64+0 records out 
 64 bytes (64 B) copied, 0.038358 s, 4.6 kB/s 

 

再次查询系统磁盘信息:

 bash-4.1# fdisk -l 
 Disk /dev/sda: 43.0 GB, 42991616000 bytes 
 255 heads, 63 sectors/track, 5226 cylinders 
 Units = cylinders of 16065 * 512 = 8225280 bytes 
 Sector size (logical/physical): 512 bytes / 512 bytes 
 I/O size (minimum/optimal): 512 bytes / 512 bytes 
 Disk identifier: 0x00032735 

   Device Boot      Start         End      Blocks   Id  System 
 /dev/sda1   *           1          17      131072   83  Linux 
 Partition 1 does not end on cylinder boundary. 
 /dev/sda2              17         147     1048576   82  Linux swap / Solaris 
 Partition 2 does not end on cylinder boundary. 
 /dev/sda3             147        5227    40803328   83  Linux 

 Disk /dev/sdb: 2147 MB, 2147483648 bytes 
 255 heads, 63 sectors/track, 261 cylinders 
 Units = cylinders of 16065 * 512 = 8225280 bytes 
 Sector size (logical/physical): 512 bytes / 512 bytes 
 I/O size (minimum/optimal): 512 bytes / 512 bytes 
 Disk identifier: 0xcdd48395 

   Device Boot      Start         End      Blocks   Id  System 
 /dev/sdb1               1         261     2096451   83  Linux 

 

硬盘设备 sda 的分区表已经恢复,重启后系统便可正常引导。

系统 GRUB 损坏

类似得我们可以来写零 Bootloader 来实现 GRUB 被破坏的结果:

 [root@FCoE grub]# dd if=/dev/zero of=/dev/sda bs=446 count=1 
 1+0 records in 
 1+0 records out 
 446 bytes (446 B) copied, 0.0017583 s, 254 kB/s 

 

重启后系统会因找不到 GRUB 而卡在“Booting from Hard Disk …”

挂载系统安装光盘然后选择进入 Rescue 模式,然后恢复 GRUB:

 bash-4.1# chroot /mnt/sysimage 
 sh-4.1# grub 
 grub > root hd(0,0) 
 grub > setup (hd0) 
 grub > quit 

图 5. 恢复 GRUB
图 5. 恢复 GRUB

重启主机后,系统可正常引导。

系统内核文件丢失

系统丢失内核 kernel 文件,再次启动后会提示找不到文件。

图 6. 内核丢失
图 6. 内核丢失

挂载系统安装盘进入援救模式,检查 /boot 目录下发现没有 kernel 文件。

 bash-4.1# chroot /mnt/sysimage 
 bash-4.1# ls /boot 
 ls 
 config-2.6.32-71.el6.x86_64     lost+found 
 efi                                  symvers-2.6.32-71.el6.x86_64.gz 
 grub                                 System.map-2.6.32-71.el6.x86_64 
 initramfs-2.6.32-71.el6.x86_64.img 

 

从挂载的系统安装盘强制重新安装内核:

 sh-4.1# mount – o loop /dev/sr0 /media 
 sh-4.1# cd /media/Server/Packages 
 sh-4.1# rpm -ivh --force kernel-2.6.32-71.el6.x86_64.rpm 
 warning: kernel-2.6.32-71.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, \ 
 key ID fd431d51: NOKEY 
 Preparing...                ########################################### [100%] 
   1:kernel                  ########################################### [100%] 

 

在 /boot 目录下已经生成新的 kernel 文件 vmlinuz-2.6.32-71.el6.x86_64

 sh-4.1## ls /boot 
 config-2.6.32-71.el6.x86_64            lost+found 
 efi                                         symvers-2.6.32-71.el6.x86_64.gz 
 grub                                        System.map-2.6.32-71.el6.x86_64 
 initramfs-2.6.32-71.el6.x86_64.img    vmlinuz-2.6.32-71.el6.x86_64 

 

重启主机后,系统可正常引导。

linux
本文评论   查看全部评论 (2)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 2 楼
* 匿名 发表于 2017/4/11 22:29:56
原来还没事,一试系统完全崩溃
第 1 楼
* j2537800会员 发表于 2015/3/9 9:36:18
经典 。。。