我怎样才能知道我的硬盘上有多少坏扇区?

我知道如何检查/修复我的硬盘,但我不知道如何查看硬盘上的坏扇区数量。 附注:看起来我的硬盘很快就要死了 :-(
2个回答

在Linux中,有两种方法可以检测坏扇区:您可以使用磁盘工具(图形界面),或者您可以使用badblocks命令来检查硬盘上的坏扇区。
sudo badblocks -v /dev/{device}

这应该回答了问题,但对于其他对如何标记它们感兴趣的人来说,可以使用两个简单的命令来完成...

您将坏块添加到一个文件中...

sudo badblocks /dev/sdb > {/dir/to/filename}
然后告诉fsck将这些标记为不可用的...
sudo fsck -l {/dir/to/filename} /dev/{device}

2似乎e2fsck有一个-c选项,它会自动调用badblocks并处理块大小。如果按照你的方式操作,必须非常小心确保它们匹配。 - Martin Ueding
3使用badblocks+fsck来标记坏块可能是危险的。根据badblocks手册中的说明:"重要提示:如果badblocks的输出将被传递给e2fsck或mke2fs程序,请务必正确指定块大小,因为生成的块编号非常依赖于文件系统所使用的块大小。因此,强烈建议用户不直接运行badblocks,而是使用e2fsck和mke2fs程序的-c选项。"请参考@john-mehorter的回答。 - sierrasdetandil
谢谢,我昨天刚好在想这个问题。+1 - WinEunuuchs2Unix

使用 fsck.ext3(e2fsck)例如,并使用 -cc 选项
-c     This option causes e2fsck to use badblocks(8) program to do a read-only scan of the device in  order  to  find  any  bad
          blocks.   If  any  bad blocks are found, they are added to the bad block inode to prevent them from being allocated to a
          file or directory.  If this option is specified twice, then the bad block scan will  be  done  using  a  non-destructive
          read-write test.`
fsck -cc /dev/sda1

1我在过去几年里读过这个好几次,但我不知道什么是非破坏性测试。它对硬盘没有任何改变吗?它只是提供信息而已吗? - Robert Vila
我假设它会尝试在每个块中进行写入,但最终还是将原始数据写回去。 - Martin Ueding