Linux 文件系統錯誤的修復方法 ddrescue替代dd的恢復軟件 備用超級塊


Linux 文件系統錯誤的修復方法  ddrescue替代dd的恢復軟件  備用超級塊

http://www.mamicode.com/info-detail-1372846.html

 

最近處理的一件 linux 服務器斷電導致文件系統啟動后文件系統不可讀寫,數據不可用的案
例,現總結下 Linux 文件系統錯誤的修復方法。
EXT3-fs error (device hda3) in start_transaction: Journal has aborted
If your system abruptly loses power, or if a RAID card is beginning to fail, you might see an
ominous message like this within your logs:
EXT3-fs error (device hda3) in start_transaction: Journal has aborted
Basically, the system is telling you that it’s detected a filesystem/journal mismatch, and it can’t
utilize the journal any longer. When this situation pops up, the filesystem gets mounted read-only
almost immediately. To fix the situation, you can remount the partition as ext2 (if it isn’t your active
root partition), or you can commence the repair operations.
If you’re working with an active root partition, you will need to boot into some rescue media and
perform these operations there. If this error occurs with an additional partition besides the root partition,
simply unmount the broken filesystem and proceed with these operations.
Remove the journal from the filesystem (effectively turning it into ext2):
# tune2fs -O ^has_journal /dev/hda3
Now, you will need to fsck it to correct any possible problems (throw in a -y flag to say yes to all
repairs, -C for a progress bar):

# e2fsck /dev/hda3

Once that's finished, make a new journal which effectively makes the partition an ext3 filesystem
again

# tune2fs -j /dev/hda3

You should be able to mount the partition as an ext3 partition at this time:

# mount -t ext3 /dev/hda3 /mnt/fixed

Be sure to check your dmesg output for any additional errors after you’re finished!

 


硬盤故障導致的數據丟失有可能是慘重的,但如果已經發生了,就需要最大程度地將數據恢復出來。

這介紹當磁盤因嚴重問題無法訪問后(但 BIOS 還能識別),數據的搶救方法,並討論ext2&ext3 格式分區的磁盤短讀(short read)錯誤。

首先約定:需要手動輸入的字符用黑體字給出,其余的為終端輸出。
如果使用 ext2 或 ext3 文件系統,可能會收到類似下面一些警告信息,該警告信息來自e2fsck 實用程序:

e2fsck /dev/hda1
e2fsck: Attempt to read block from filesystem resulted in short read

 


如果看到這個消息,首先想到可能是磁盤的主超級塊損壞。而在創建文件系統的時候,mke2fs 已經自動創建了磁盤的超級塊的備份。

可以告訴 e2fsck 程序使用一個備用超級塊檢查文件系統。

備用超級塊一般創建於塊 8193、16384 或 32768取決於磁盤的大小(可以使用 mkfs.ext3 -n /dev/hda1 查看)。假設是塊大硬盤,則使用:

e2fsck -b 32768 /dev/hda1

 


如果是超級塊的問題,則程序返回后,備用超級塊被啟用,磁盤恢復正常。如果提示下面的問題:

e2fsck: Attempt to read block from filesystem resulted in short read while checking
ext3 journal for /dev/hda1

 


說明問題不是出在超級塊,出自日志文件系統的日志。此時可以安全地刪除 ext3 文件系統的日志:

tune2fs -f -O ^has_journal /dev/hda1

 


這樣就刪除了/dev/hda1 文件系統上的日志,這時可以重新嘗試掛載分區,必要的話可以重建日志系統(使用 tune2fs -j /dev/xxx)。
如果 tune2fs 提示下面的錯誤:

tune2fs: Attempt to read block from filesystem resulted in short read while
reading journal inode

 


則說明指向日志的 inode 壞了,意味着無法清除日志。這時可以嘗試 debugfs 命令,它是ext2&3 文件系統的調試器。

也可以再次使用 e2fsck,加上-c 參數檢查文件系統的壞塊。至此,因為無法檢查或修復問題磁盤上的文件系統,該拿出殺手鐧了。
使用 ddrescue 克隆損壞的磁盤
如果磁盤因為壞塊而妨礙了讀取,可以使用一個原始的磁盤復制實用程序創建磁盤的一個副本。

Unix/Linux 系統自帶了一個簡單實用程序 dd,它把一個文件/分區/磁盤復制到另一個(在第一個專題里用到過)。

前提條件時必須在系統里添加一塊容量不小於問題磁盤的新硬盤。
新硬盤准備就緒后,輸入下面命令:

dd if=/dev/hda of=/dev/hdb conv=noerror,sync

 


上面的命令將壞磁盤(/dev/hda)復制到新磁盤(/dev/hdb),忽略讀取時遇到的錯誤(noerror),當遇到不能訪問的塊時用適當數量的空值填充輸出(sync)。
但是 dd 有幾個缺點:首先是速度太慢;然后是不顯示進度信息,直到完成前它都是沉默的;


不重新嘗試失敗的讀取,這會減少能從壞盤恢復的數據量。因此在這里介紹另一個軟件——ddrescue,

可以從 http://www.gnu.org/software/ddrescue/ddrescue.html 獲取
最新版(Fedora8 用戶可以直接用 yum install dd_rescue 安裝) 。

http://mirrors.ustc.edu.cn/gnu/ddrescue/

 

目前 ddrescue 最新版本是 1.7,直接下載鏈接: http://ftp.gnu.org/gnu/ddrescue/ddrescue-1.7.tar.bz2
編譯、安裝后,可以使用下面命令完成相同的任務:

ddrescue --max-retries=-1 /dev/hda /dev/hdb


其中 max-retries=-1 參數表示無論遇到多少錯誤都不要停止。程序從 hda 讀取數據並寫到 hdb 中時,不斷更新各項數據,可以方便地查看工作進行情況。
在 ddrescue 結束磁盤復制后,在新硬盤上運行 e2fsck,以消除原始磁盤的壞塊引起的文
件系統錯誤。由於肯定會有大量錯誤,可以用-y 參數運行 e2fsck,指示 e2fsck 對每個問題都回答 yes:

e2fsck -y /dev/hdb

 


此時,可以使用 mount 命令掛載文件系統,看看數據的恢復情況了。記得檢查驅動器根目錄下的 lost+found 文件夾,

fsck 把不能正確鏈接的文件和目錄放在了這個文件夾里


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM