linux – 如何在fsck之后恢复损坏的ext4文件系统?

前端之家收集整理的这篇文章主要介绍了linux – 如何在fsck之后恢复损坏的ext4文件系统?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在软件raid5上有一个ext4文件系统.当我开始耗尽空间时,文件系统运行“好了”好几年了.我在6x2T硬盘上有9T的音量.我开始通过执行mdadm失败,删除,添加,重建,重复过程升级到3T驱动器,直到我有一个更大的阵列.
然后我增加了luks容器,然后当我卸载并尝试resize2fs时,我收到了消息,文件系统很脏,需要e2fsck.

不假思索我刚刚做了e2fsck -y / dev / mapper / candyBox,它开始喷出各种inode被删除类型的消息(记不清楚)我杀了e2fsck并试图重新安装文件系统来备份我关心的数据.当我试图在这一点上安装时,我得到:

  1. # mount /dev/mapper/candyBox /candyBox
  2. mount: wrong fs type,bad option,bad superblock on /dev/mapper/candyBox,missing codepage or helper program,or other error
  3. In some cases useful info is found in syslog - try
  4. dmesg | tail or so

回顾我的旧日志,我注意到每次机器启动时文件系统都会出现此错误

  1. kernel: [79137.275531] EXT4-fs (dm-2): warning: mounting fs with errors,running e2fsck is recommended

因为不注意而感到羞耻:(

然后我尝试使用每个备份超级块(一个接一个)挂载,每次尝试都将其保留在我的日志中:

  1. EXT4-fs (dm-2): ext4_check_descriptors: Checksum for group 0 Failed (26534!=65440)
  2. EXT4-fs (dm-2): ext4_check_descriptors: Checksum for group 1 Failed (38021!=36729)
  3. EXT4-fs (dm-2): ext4_check_descriptors: Checksum for group 2 Failed (18336!=39845)
  4. ...
  5. EXT4-fs (dm-2): ext4_check_descriptors: Checksum for group 11911 Failed (28743!=44098)
  6. BUG: soft lockup - cpu#0 stuck for 23s! [mount:2939]

尝试重新启动e2fsck会导致:

  1. # e2fsck /dev/mapper/candyBox
  2. e2fsck 1.41.14 (22-Dec-2010)
  3. e2fsck: Group descriptors look bad... trying backup blocks...
  4. candy: recovering journal
  5. e2fsck: unable to set superblock flags on candy

此时,我决定最好订购更多驱动器并使用ddrescue制作图像
两周后,我在.img文件中有一个luks分区的图像.

  1. # ls -lh
  2. total 14T
  3. -rw-r--r-- 1 root root 14T Oct 25 01:57 candyBox.img
  4. -rw-r--r-- 1 root root 271 Oct 20 14:32 candyBox.logfile

经过多次尝试使用我在网上找到的所有内容后,我无法强迫e2fsck在图像上做任何事情,所以我使用了mkfs.ext4 -L candy candyBox.img -m 0 -S并且我能够只读装入脏文件系统记录和恢复960G的数据.它给出了不存在的各种目录的各种错误等等,但我能够得到一些东西.这给了我一些希望!

然后我再次运行e2fsck并且它必须重新创建根inode并提供了一个大量的纠正组计数列表,我接受了root inode创建并且拒绝其他所有内容,留下一个完全空的文件系统.再次重新运行并对所有问题表示同意,结果相同,但现在是一个“干净”但空文件系统.

extundelete给了我0个可恢复的inode.

而现在我再次陷入困境,我无法想出任何其他方法,除了像photorec这样的东西,这将给我一个绝对的混乱文件系统的大小.

我愿意重新复制原始数组中的图像并重新开始,如果我可以获得任何建议或想法以获得更多我的文件.

我希望我可以提供已经运行的命令的更详细的日志,但是输出是长滚动的,除了记录到syslog的内容以及我的内存由于发生的时间范围而没有详细说明.

任何帮助是极大的赞赏!

10月27日更新

我已经完全重新复制了图像以重新开始测试,这是迄今为止的输出.
复制过程:

  1. [root@gamma rescue]# nbd-client 172.16.10.204 2000 /dev/nbd0
  2. Negotiation: ..size = 14307292MB
  3. bs=1024,sz=15002283540480 bytes
  4. [root@gamma rescue]# cryptsetup luksOpen /dev/nbd0 candyBox
  5. Enter passphrase for /dev/nbd0:
  6. [root@gamma mnt]# pvcreate /dev/md5
  7. Physical volume "/dev/md5" successfully created
  8. [root@gamma mnt]# pvscan
  9. PV /dev/md5 lvm2 [18.19 TiB]
  10. Total: 1 [18.19 TiB] / in use: 0 [0 ] / in no VG: 1 [18.19 TiB]
  11. [root@gamma mnt]# vgcreate vg-rescue /dev/md5
  12. Volume group "vg-rescue" successfully created
  13. [root@gamma mnt]# lvcreate --size 15T --name lv-rescue vg-rescue
  14. Logical volume "lv-rescue" created
  15. [root@gamma mnt]# mkfs.xfs /dev/vg-rescue/lv-rescue
  16. log stripe unit (524288 bytes) is too large (maximum is 256KiB)
  17. log stripe unit adjusted to 32KiB
  18. Meta-data=/dev/vg-rescue/lv-rescue isize=256 agcount=33,agsize=125828992 blks
  19. = sectsz=512 attr=2
  20. data = bsize=4096 blocks=4026531840,imaxpct=5
  21. = sunit=128 swidth=640 blks
  22. naming =version 2 bsize=4096 ascii-ci=0
  23. log =internal log bsize=4096 blocks=521728,version=2
  24. = sectsz=512 sunit=8 blks,lazy-count=1
  25. realtime =none extsz=4096 blocks=0,rtextents=0
  26. [root@gamma mnt]# mount /dev/vg-rescue/lv-rescue rescue/
  27. [root@gamma rescue]# ddrescue /dev/mapper/candyBox candyBox.img candyBox.ddlog
  28.  
  29.  
  30. Press Ctrl-C to interrupt
  31. Initial status (read from logfile)
  32. rescued: 0 B,errsize: 0 B,errors: 0
  33. Current status
  34. rescued: 13194 GB,errsize: 1807 GB,current rate: 0 B/s
  35. ipos: 13194 GB,errors: 1,average rate: 73528 kB/s
  36. opos: 13194 GB,time from last successful read: 44 s
  37. ^Clitting Failed blocks...
  38. Interrupted by user
  39. ## Network hung,had to try again here
  40. [regan@gamma ~]$sudo nbd-client -d /dev/nbd0
  41. Disconnecting: que,disconnect,Error: Ioctl Failed: Invalid argument
  42.  
  43. Exiting.
  44. [regan@gamma ~]$sudo nbd-client 172.16.10.204 2000 /dev/nbd0
  45. Negotiation: ..size = 14307292MB
  46. bs=1024,sz=15002283540480 bytes
  47.  
  48. [root@gamma rescue]# ddrescue -r 2 /dev/mapper/candyBox candyBox.img candyBox.ddlog
  49.  
  50.  
  51. Press Ctrl-C to interrupt
  52. Initial status (read from logfile)
  53. rescued: 15002 GB,errsize: 7426 kB,errors: 60
  54. Current status
  55. rescued: 15002 GB,current rate: 77529 kB/s
  56. ipos: 15002 GB,errors: 0,average rate: 69297 kB/s
  57. opos: 15002 GB,time from last successful read: 0 s
  58. Finished
  59.  
  60. [root@gamma rescue]# lvcreate -l 100%FREE -s -n rescue_snap /dev/vg-rescue/lv-rescue
  61. Logical volume "rescue_snap" created
  62. [root@gamma rescue]# cd ..
  63. [root@gamma mnt]# mount -o remount,ro rescue/
  64. [root@gamma mnt]# mkdir rescue_snap
  65. [root@gamma mnt]# mount -o nouuid /dev/vg-rescue/rescue_snap rescue_snap
  66. [root@gamma mnt]# cd rescue_snap/
  67. [root@gamma rescue_snap]# ls
  68. candyBox.ddlog candyBox.img

凌乱:

  1. [root@gamma rescue_snap]# mkfs.ext4 -L candy candyBox.img -m 0 -S
  2. mke2fs 1.41.10 (10-Feb-2009)
  3. candyBox.img is not a block special device.
  4. Proceed anyway? (y,n) y
  5. Filesystem label=candy
  6. OS type: Linux
  7. Block size=4096 (log=2)
  8. Fragment size=4096 (log=2)
  9. Stride=0 blocks,Stripe width=0 blocks
  10. 915668992 inodes,3662666368 blocks
  11. 0 blocks (0.00%) reserved for the super user
  12. First data block=0
  13. Maximum filesystem blocks=4294967296
  14. 111776 block groups
  15. 32768 blocks per group,32768 fragments per group
  16. 8192 inodes per group
  17. Superblock backups stored on blocks:
  18. 32768,98304,163840,229376,294912,819200,884736,1605632,2654208,4096000,7962624,11239424,20480000,23887872,71663616,78675968,102400000,214990848,512000000,550731776,644972544,1934917632,2560000000
  19.  
  20. Skipping journal creation in super-only mode
  21. Writing superblocks and filesystem accounting information: done
  22.  
  23. This filesystem will be automatically checked every 26 mounts or
  24. 180 days,whichever comes first. Use tune2fs -c or -i to override.
  25.  
  26. [root@gamma rescue_snap]# mount -o loop candyBox.img /mnt2
  27. [root@gamma rescue_snap]# df -h
  28. Filesystem Size Used Avail Use% Mounted on
  29. /dev/md2 147G 138G 3.1G 98% /
  30. tmpfs 16G 5.7M 16G 1% /dev/shm
  31. /dev/md0 494M 199M 276M 42% /boot
  32. /dev/sdc1 1.8T 979G 763G 57% /mnt/macmirror
  33. /dev/sdj1 1.8T 970G 771G 56% /mnt/usbrescue
  34. /dev/mapper/vg--rescue-lv--rescue
  35. 15T 14T 1.4T 91% /mnt/rescue
  36. /dev/mapper/vg--rescue-rescue_snap
  37. 15T 14T 1.4T 91% /mnt/rescue_snap
  38. /mnt/rescue_snap/candyBox.img
  39. 14T 15M 14T 1% /mnt2
  40.  
  41. ## Even though it says only 15M is used,I was able to rsync 960G to /mnt/usbrescue
  42.  
  43. [root@gamma rescue_snap]# cd /mnt2/
  44. [root@gamma mnt2]# ls -l
  45. ls: cannot access Fedora-19-x86_64-DVD: Input/output error
  46. ls: cannot access rsync_batch: Input/output error
  47. ls: cannot access shell1: Input/output error
  48. ls: cannot access New Folder (2): Input/output error
  49. ls: cannot access shell2: Input/output error
  50. ls: cannot access revolution: Input/output error
  51. ls: cannot access mail: Input/output error
  52. ls: cannot access testing: Input/output error
  53. ls: cannot access export: Input/output error
  54. ls: cannot access ben_backup_20130903: Input/output error
  55. total 160488672
  56. drwxr-xr-x 2 regan regan 4096 Sep 3 20:16 100MEDIA
  57. drwxr-xr-x 19 regan regan 4096 Sep 26 05:18 android
  58. d?????????? ? ? ? ? ? ben_backup_20130903
  59. -rw-rw-r-- 1 regan regan 12126 Jan 4 2013 durations.txt
  60. d?????????? ? ? ? ? ? export
  61. drwxrwxr-x 10 regan regan 4096 Dec 29 2012 family-pc_20121229
  62. d?????????? ? ? ? ? ? Fedora-19-x86_64-DVD
  63. -rw-r--r-- 1 regan regan 72116729363 Sep 30 04:39 gamma_backup_20130928.tgz
  64. -rw-rw-r-- 1 regan regan 55606528323 Jul 27 2011 gamma_tar_20110727.tbz2
  65. -rw-rw-r-- 1 regan regan 3839 Sep 27 2012 Good Quality2.plist
  66. -rw-rw-r-- 1 regan regan 4663 Oct 7 2012 Good Quality3.plist
  67. -rw-rw-r-- 1 regan regan 3852 Sep 26 2012 Good Quality.plist
  68. drwxr-xr-x 7 regan regan 4096 Nov 13 2012 grok
  69. d?????????? ? ? ? ? ? HardDisks
  70. -rwxr--r-- 1 regan regan 54248 Mar 16 2013 IMAG0868.jpg
  71. -rwxr--r-- 1 regan regan 51156 Mar 16 2013 IMAG0869.jpg
  72. -rwxr--r-- 1 regan regan 85912 Mar 16 2013 IMAG0870.jpg
  73. -rwxr--r-- 1 regan regan 76875 Mar 16 2013 IMAG0872.jpg
  74. -rwxr--r-- 1 regan regan 68451 Mar 16 2013 IMAG0873.jpg
  75. -rwxr--r-- 1 regan regan 59587 Mar 16 2013 IMAG0874.jpg
  76. -rwxr--r-- 1 regan regan 81232 Mar 16 2013 IMAG0875.jpg
  77. -rwxr--r-- 1 regan regan 44211 Mar 16 2013 IMAG0876.jpg
  78. -rwxr--r-- 1 regan regan 41660 Mar 16 2013 IMAG0877.jpg
  79. -rwxr--r-- 1 regan regan 36778 Mar 16 2013 IMAG0878.jpg
  80. -rwxr--r-- 1 regan regan 76964 Mar 16 2013 IMAG0879.jpg
  81. -rwxr--r-- 1 regan regan 81876 Mar 16 2013 IMAG0880.jpg
  82. -rwxr--r-- 1 regan regan 1568002 Mar 16 2013 IMAG0953.jpg
  83. -rwxr--r-- 1 regan regan 1548566 Mar 16 2013 IMAG0954.jpg
  84. -rwxr--r-- 1 regan regan 1351743 Mar 16 2013 IMAG0955.jpg
  85. -rwxr--r-- 1 regan regan 1750128 Mar 16 2013 IMAG0956.jpg
  86. -rwxr--r-- 1 regan regan 1694378 Mar 16 2013 IMAG0957.jpg
  87. -rwxr--r-- 1 regan regan 1277128 Mar 16 2013 IMAG0958.jpg
  88. -rwxr--r-- 1 regan regan 1467452 Mar 16 2013 IMAG0965.jpg
  89. -rwxr--r-- 1 regan regan 1595903 Mar 16 2013 IMAG0966.jpg
  90. -rwxr--r-- 1 regan regan 1372444 Mar 16 2013 IMAG0967.jpg
  91. -rwxr--r-- 1 regan regan 1698010 Mar 16 2013 IMAG0968.jpg
  92. -rwxr--r-- 1 regan regan 1550641 Mar 16 2013 IMAG0969.jpg
  93. -rwxr--r-- 1 regan regan 1333768 Mar 16 2013 IMAG0970.jpg
  94. -rwxr--r-- 1 regan regan 1432347 Mar 16 2013 IMAG1010.jpg
  95. -rwxr--r-- 1 regan regan 1668159 Mar 16 2013 IMAG1013.jpg
  96. -rwxr--r-- 1 regan regan 1657058 Mar 16 2013 IMAG1014.jpg
  97. -rwxr--r-- 1 regan regan 1496547 Mar 16 2013 IMAG1016.jpg
  98. -rwxr--r-- 1 regan regan 1609156 Mar 16 2013 IMAG1017.jpg
  99. -rwxr--r-- 1 regan regan 1604832 Mar 16 2013 IMAG1019.jpg
  100. -rwxr--r-- 1 regan regan 2048916 Mar 16 2013 IMAG1073.jpg
  101. -rwxr--r-- 1 regan regan 2006024 Mar 16 2013 IMAG1074.jpg
  102. -rwxr--r-- 1 regan regan 1926686 Mar 16 2013 IMAG1075.jpg
  103. -rw-r--r-- 1 regan regan 1583090 Jul 14 21:15 IMAG1565.jpg
  104. -rw-r--r-- 1 regan regan 1435031 Sep 22 05:19 IMAG1762.jpg
  105. -rw-r--r-- 1 regan regan 1531602 Sep 22 05:19 IMAG1763.jpg
  106. -rw-r--r-- 1 regan regan 1450926 Sep 22 05:19 IMAG1764.jpg
  107. -rw-r--r-- 1 regan regan 1336103 Sep 23 21:31 IMAG1765.jpg
  108. -rw-r--r-- 1 regan regan 1235885 Sep 23 21:32 IMAG1766.jpg
  109. -rw-r--r-- 1 regan regan 1224376 Sep 23 21:32 IMAG1767.jpg
  110. -rw-r--r-- 1 regan regan 1235229 Sep 23 21:32 IMAG1768.jpg
  111. drwxrwxr-x 2 regan regan 4096 Mar 9 2013 jakeanmal
  112. -rw-rw-rw- 1 regan regan 115228 Oct 29 2009 jj_nas
  113. drwx------. 2 root root 16384 Nov 8 2012 lost+found
  114. -rw-r--r-- 1 regan regan 3123877728 Nov 6 2010 luridmirror_20090806.tar.xz
  115. -rw-r--r-- 1 regan regan 2877033943 Mar 1 2013 macabre_20130301.tgz
  116. d?????????? ? ? ? ? ? mail
  117. -rw-r--r-- 1 root root 6771 Aug 10 2009 mail_mirror
  118. -rw------- 1 regan regan 21913047552 Apr 4 2013 mallorys_hdd.vBox.img
  119. d?????????? ? ? ? ? ? MSDN
  120. -rw-r--r-- 1 regan regan 8572 May 10 2010 Music
  121. d?????????? ? ? ? ? ? New Folder (2)
  122. drwxrwxrwx 24 regan regan 4096 Mar 22 2013 onyx
  123. drwxr-xr-x 231 regan regan 24576 Sep 30 09:29 ptp
  124. -rwxr--r-- 1 regan regan 483328 Jan 26 2013 putty.exe
  125. d?????????? ? ? ? ? ? revolution
  126. -rw-r--r-- 1 root root 6272757760 Oct 16 2012 root.tar
  127. d?????????? ? ? ? ? ? rsync_batch
  128. drwxrwxr-x 2 regan regan 12288 Oct 6 04:09 saber
  129. drwxrwxr-x 2 regan regan 188416 Sep 25 04:20 session_tmp
  130. d?????????? ? ? ? ? ? shell1
  131. d?????????? ? ? ? ? ? shell2
  132. d?????????? ? ? ? ? ? testing
  133. drwxrwxr-x 3 regan regan 4096 Oct 7 2012 tofix
  134. -rwxr--r-- 1 regan regan 64991966 Jan 2 2013 VIDEO0041.mp4
  135.  
  136. [root@gamma mnt2]# cd ..
  137. [root@gamma /]# umount /mnt2
  138. [root@gamma /]# cd /mnt/rescue_snap/
  139. [root@gamma rescue_snap]# e2fsck candyBox.img
  140. e2fsck 1.41.10 (10-Feb-2009)
  141. Backing up journal inode block information.
  142.  
  143. candy contains a file system with errors,check forced.
  144. Resize inode not valid. Recreate<y>? yes
  145.  
  146. Pass 1: Checking inodes,blocks,and sizes
  147. Pass 2: Checking directory structure
  148. Pass 3: Checking directory connectivity
  149. Root inode not allocated. Allocate<y>? yes
  150.  
  151. /lost+found not found. Create<y>? yes
  152.  
  153. Pass 4: Checking reference counts
  154. Pass 5: Checking group summary information
  155. Block bitmap differences: -(9252--9255) <Snip a few dozen MB of text> -(3662666237--3662666238) -3662666240 -(3662666242--3662666244) -(3662666247--3662666249) -3662666253 -(3662666255--3662666256) -3662666259 -3662666262 -3662666264 -(3662666268--3662666271) -3662666276 -3662666281 -3662666285 -3662666294 -(3662666296--3662666297) -3662666301 -3662666307 -3662666309 -3662666311 -3662666313 -3662666316 -(3662666318--3662666319) -3662666324 -(3662666326--3662666328) -(3662666331--3662666332) -3662666334 -(3662666341--3662666342) -3662666344 -(3662666346--3662666347) -3662666349 -(3662666351--3662666352) -3662666354 -3662666357 -3662666362 -(3662666366--3662666367)
  156. Fix<y>? yes
  157.  
  158. Free blocks count wrong for group #0 (23517,counted=23516).
  159. Fix<y>?
  160.  
  161. Free blocks count wrong (3605188902,counted=3605188901).
  162. Fix<y>? yes
  163.  
  164. Free inodes count wrong for group #0 (8191,counted=8190).
  165. Fix<y>? yes
  166.  
  167. Directories count wrong for group #0 (1,counted=2).
  168. Fix<y>? yes
  169.  
  170. Free inodes count wrong (915668991,counted=915668990).
  171. Fix<y>? yes
  172.  
  173.  
  174. candy: ***** FILE SYSTEM WAS MODIFIED *****
  175. candy: 2/915668992 files (0.0% non-contiguous),57477467/3662666368 blocks
  176. [root@gamma rescue_snap]# mount -o loop candyBox.img /mnt2
  177. [root@gamma rescue_snap]# ls -l /mnt2
  178. total 4
  179. drwx------ 2 root root 4096 Oct 27 19:33 lost+found
  180. [root@gamma rescue_snap]#

请注意,我现在在快照中有我的备份图像,所以如果有人有想法,我可以一遍又一遍地尝试理论……

解决方法

我首选的文件系统数据恢复工具是 UFS Explorer.

我不知道LUKS加密将如何影响这一点,但下载UFS资源管​​理器的评估并尝试正常的最佳实践.针对您的图片运行它,看看事情是否更容易恢复.该工具将为您提供目录结构的良好视图,并提供搜索数据的能力.

另见:How to recover XFS file system with “superblock read failed”

猜你在找的Linux相关文章