Linux 灾难恢复 Linux 系统启动故障修复
#http://hi.baidu.com/winshining/item/3d964328e252b6cfdcf69aaa
#http://www.verydemo.com/demo_c281_i514.html
?
簡介: Linux 發行版本眾多,現如今也得到了越來越廣泛的應用,同時也面臨著系統出現故障的潛在風險,本文將詳細介紹幾種 Linux 災難恢復技術和方法,以確保 Linux 系統安全恢復。
Linux 災難恢復
Linux 發行版本眾多,現如今也得到了越來越廣泛的應用,同時也面臨著系統出現故障的潛在風險,本文將以發行版本 RHEL6 為例詳細介紹幾種 Linux 災難恢復技術和方法,以確保 Linux 系統的安全恢復。
在介紹 Linux 災難恢復方法之前,我們先來了解下 MBR,其全稱為 Master Boot Record,即硬盤的主引導記錄。它由三個部分組成,主引導程序、硬盤分區表和硬盤有效標志。在總共 512 字節的主引導扇區里主引導程序(Bootloader)占 446 個字節,第二部分是硬盤分區表,占 64 個字節,硬盤有多少分區以及每一分區的大小都記錄在其中。第三部分是硬盤有效標志,占 2 個字節。具體如圖示:
圖 1. MBR
系統硬盤分區表破壞
生產環境中的 Linux 服務器可能會因為病毒或者意外斷電而引起硬盤分區表被破壞,通常恢復硬盤分區表需要之前我們先備份其分區表的信息,一般我們使用 USB 外接設備來備份主機硬盤的分區表。
在主機上掛載 USB 設備后我們查看系統當前磁盤設備 :
?[root@FCoE ~]# 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: 0x00000000
?Disk /dev/sdb doesn't contain a valid partition table
?
?
現在我們在 sdb 這個設備上創建一個新的分區 :
?[root@FCoE ~]# fdisk /dev/sdb
?Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
?Building a new DOS disklabel with disk identifier 0xcdd48395.
?Changes will remain in memory only, until you decide to write them.
?After that, of course, the previous content won't be recoverable.
?Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
?WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
???????? switch off the mode (command 'c') and change display units to
???????? sectors (command 'u').
?Command (m for help): n
?Command action
?? e?? extended
?? p?? primary partition (1-4)
?p
?Partition number (1-4): 1
?First cylinder (1-261, default 1):
?Using default value 1
?Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261):
?Using default value 261
?Command (m for help): p
?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
?Command (m for help): w
?The partition table has been altered!
?Calling ioctl() to re-read partition table.
?Syncing disks.
?
?
在新分區 sdb1 上創建文件系統:
?[root@FCoE ~]# mkfs.ext3 /dev/sdb1
?mke2fs 1.41.12 (17-May-2010)
?Filesystem label=
?OS type: Linux
?Block size=4096 (log=2)
?Fragment size=4096 (log=2)
?Stride=0 blocks, Stripe width=0 blocks
?131072 inodes, 524112 blocks
?26205 blocks (5.00%) reserved for the super user
?First data block=0
?Maximum filesystem blocks=536870912
?16 block groups
?32768 blocks per group, 32768 fragments per group
?8192 inodes per group
?Superblock backups stored on blocks:
??????? 32768, 98304, 163840, 229376, 294912
?Writing inode tables: done
?Creating journal (8192 blocks): done
?Writing superblocks and filesystem accounting information: done
?This filesystem will be automatically checked every 24 mounts or
?180 days, whichever comes first.? Use tune2fs -c or -i to override.
?
?
掛載新的文件系統:
?[root@FCoE ~]# mount /dev/sdb1 /mnt/
?
?
通常我們通過備份硬盤的 MBR 來備份硬盤分區表:
?[root@FCoE ~]# dd if=/dev/sda of=/mnt/sda.mbr bs=512 count=1
?1+0 records in
?1+0 records out
?512 bytes (512 B) copied, 0.000777948 s, 658 kB/s
?
?
現在我們來寫零硬盤分區表來實現類似分區表被破壞的結果:
?[root@FCoE ~]# dd if=/dev/zero 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.00160668 s, 39.8 kB/s
?
?
查詢硬盤 sda 上的分區信息,發現其已不包含任何分區:
?[root@FCoE ~]# 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
?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
?
?
當主機硬盤分區表丟失了之后,再次啟動后 GRUB 會因找不到配置文件而進入命令行模式 :
圖 2. 分區表丟失
接下來我們掛載 RHEL6 的安裝盤,同時也接入我們之前備份的 USB 設備,然后重啟主機,選擇 CD-ROM 為第一引導設備,啟動后選擇“Rescue installed system”。
圖 3. 選擇援救
按照提示,最終我們選擇一個 shell。
圖 4. 選擇 shell
本篇文章來源于 Linux公社網站(www.linuxidc.com)? 原文鏈接:http://www.linuxidc.com/Linux/2012-09/70971.htm
轉載于:https://blog.51cto.com/redhatdebian/1019927
總結
以上是生活随笔為你收集整理的Linux 灾难恢复 Linux 系统启动故障修复的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server2008R2查询数据
- 下一篇: .读取excel表格(JAVA)