您的位置:首页 > 运维架构 > Linux

Linux 文件系统错误的修复方法 ddrescue替代dd的恢复软件 备用超级块

2016-06-02 11:51 1046 查看
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 把不能正确链接的文件和目录放在了这个文件夹里
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: