用的组合dumpe2fs
和debugfs
被包括在e2fsprogs
包沿着fsck.ext*
。
您必须将命令的输出用作下一个命令的参数。
这些工具会自动检测文件系统的块大小,因此它比直接badblocks
调用更为一致和安全。
打印文件系统的已注册坏块:
# dumpe2fs -b DEVNAME
打印使用给定阻止列表的inode:
# debugfs -R "icheck BLOCK ..." DEVNAME
将路径名打印到给定的inode列表:
# debugfs -R "ncheck INODE ..." DEVNAME
debugfs
也有一个交互式外壳程序和-f cmd_file
选项,但是在这种情况下它们并没有太大的作用或有用。
-R选项允许更多的自动化脚本,如下所示:
#!/bin/sh
# Finds files affected by bad blocks on ext* filesystems.
# Valid only for ext* filesystems with bad blocks registered with
# fsck -c [-c] [-k] or -l|-L options.
# Can be extremely slow on damaged storage (not just a corrupt filesystem).
DEVNAME="$1"
[ -b "$DEVNAME" ] || exit 1
BADBLOCKS="$(dumpe2fs -b "$DEVNAME" | tr '\n' ' ')"
[ -n "$BADBLOCKS" ] || exit 0
INODES="$(debugfs -R "icheck $BADBLOCKS" "$DEVNAME" | awk -F'\t' '
NR > 1 { bad_inodes[$2]++; }
END {
for (inode in bad_inodes) {
if (inode == "<block not found>") {
printf("%d unallocated bad blocks\n", bad_inodes[inode]) > "/dev/stderr";
continue;
}
printf inode OFS;
}
}
')"
[ -n "$INODES" ] || exit 0
debugfs -R "ncheck -c $INODES" "$DEVNAME"