---恢復內容開始---
只破壞super block(super block用於描述文件系統信息)
------------------------------------------------------
破壞前狀態:
通過 dd if=/dev/zero of=/dev/sdb1 bs=4k count=1
/date目錄發生故障
發現故障后第一件事先umount對應的磁盤,因為在線修復可能會丟失數據
(模擬環境無法卸載,直接重啟)
無法掛載。
fsck -v /dev/sdb1
發現super-block塊損壞,詢問是否修復,一路yes下來,修復完成。
mount成功。數據沒有丟失。
注:本例文件格式為ext4,如果文件格式為xfs,使用e2fsck -b block_number device修復即可。
---恢復內容結束---
破壞super block與大量inode_table/bitmap/等元數據信息以及data_block(會有數據丟失)
----------------------------------------------------------------
通過 dd if=/dev/zero of=/dev/sdb1 bs=4M count=250破壞大量文件
需要指定backup_super_block位置來恢復超級塊文件
可以通過fdisk創建相同大小與文件格式的新空間來查找backup_super_block位置
查找到了backup_super_block位置
在ext文件系統下,也可以通過 mke2fs -n /dev/sdb來模擬創建過程,找出backup_super_block位置
利用mke2fs這個命令 mke2fs -n 設備名,為了不引起歧義,所以這里直接復制了原文解釋。
-n Causes mke2fs to not actually create a filesystem, but display what it would do if it were to create
a filesystem. This can be used to determine the location of the backup superblocks for a particular
filesystem, so long as the mke2fs parameters that were passed when the filesystem was originally
created are used again. (With the -n option added, of course!)
簡單來說就是接了-n 參數 ,mke2fs 不是真的在設備上創建文件系統,它只是模擬這個過程並顯示給你看。讓你明白它究竟做了那些事。
[root@server1 ~]# mke2fs -n /dev/sdb mke2fs 1.41.12 (17-May-2010) /dev/sdb is entire device, not just one partition! 無論如何也要繼續? (y,n) y 文件系統標簽= 操作系統:Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks inodes, 2621440 blocks blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=2684354560 block groups blocks per group, 32768 fragments per group inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 --------------->>> 超級塊的備份位置就在這里 [root@server1 ~]#
通過e2fsck -b superblock_number device來修復
找到正確的數字會提示修復
[root@localhost ~]# e2fsck -b 294912 /dev/sdb1 e2fsck 1.42.9 (28-Dec-2013) Superblock has an invalid journal (inode 8). Clear<y>? yes
錯誤的數字會直接結束
[root@localhost ~]# e2fsck -b 29491 /dev/sdb1 e2fsck 1.42.9 (28-Dec-2013) e2fsck: Bad magic number in super-block while trying to open /dev/sdb1 The superblock could not be read or does not describe a correct ext2 filesystem. If the device is valid and it really contains an ext2 filesystem (and not swap or ufs or something else), then the superblock is corrupt, and you might try running e2fsck with an alternate superblock: e2fsck -b 8193 <device>
接着一路Y修復完成。
[root@localhost ~]# e2fsck -b 294912 /dev/sdb1 e2fsck 1.42.9 (28-Dec-2013) Superblock has an invalid journal (inode 8). Clear<y>? yes *** ext3 journal has been deleted - filesystem is now ext2 only *** /dev/sdb1 was not cleanly unmounted, check forced. Resize inode not valid. Recreate<y>? yes Pass 1: Checking inodes, blocks, and sizes Root inode is not a directory. Clear<y>? yes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Root inode not allocated. Allocate<y>? yes /lost+found not found. Create<y>? yes Pass 4: Checking reference counts Pass 5: Checking group summary information Block bitmap differences: +(0--8481) +(32768--33024) +(98304--98560) +(163840--164096) +(229376--229632) +(294912--295168) Fix<y>? yes Free blocks count wrong for group #0 (24279, counted=24284). Fix<y>? yes Free blocks count wrong for group #8 (16384, counted=32768). Fix<y>? yes Free blocks count wrong (498130, counted=514519). Fix<y>? yes Inode bitmap differences: +1 +(3--10) Fix<y>? yes Free inodes count wrong for group #0 (8180, counted=8181). Fix<y>? yes Directories count wrong for group #0 (3, counted=2). Fix<y>? yes Free inodes count wrong (131060, counted=131061). Fix<y>? yes Recreate journal<y>? yes Creating journal (16384 blocks): Done. *** journal has been re-created - filesystem is now ext3 again *** /dev/sdb1: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sdb1: 11/131072 files (0.0% non-contiguous), 26153/524288 blocks
mount成功,但是我DD了太多,破壞了所有數據。
[root@localhost ~]# mount /dev/sdb1 /date [root@localhost ~]# cd /date/ [root@localhost date]# ls lost+found [root@localhost date]# ll total 4 drwx------. 2 root root 4096 May 20 08:31 lost+found