如何知道硬盘上坏道的数量?

Alp*_*hus 10 hard-drive

我知道如何检查/修复我的硬盘,但我不知道如何查看硬盘上坏扇区的数量。

PS 看来我的硬盘很快就要死了:-(

Rin*_*ind 12

在 Linux 中有两种检测坏道的方法:您可以使用磁盘实用程序 (gui),或者您可以使用badblocks命令来检查您的硬盘是否有坏道:

sudo badblocks -v /dev/{device}
Run Code Online (Sandbox Code Playgroud)

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

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

sudo badblocks /dev/sdb > {/dir/to/filename}
Run Code Online (Sandbox Code Playgroud)

然后告诉fsck将这些标记为不可用...

sudo fsck -l {/dir/to/filename} /dev/{device}
Run Code Online (Sandbox Code Playgroud)

  • 使用 `badblocks`+`fsck` 来标记坏块可能很危险。来自 `badblocks` 手册页:“重要说明:如果 badblocks 的输出将被提供给 e2fsck 或 mke2fs 程序,正确指定块大小很重要,因为生成的块号非常依赖于文件系统使用的块大小。因此,_强烈建议用户不要直接运行坏块,而是使用 e2fsck 和 mke2fs 程序的 -c 选项_。请参阅@john-mehorter 答案。 (3认同)
  • 似乎 `e2fsck` 有一个 `-c` 选项,它调用 `badblocks` 本身并处理块大小。如果您按照自己的方式进行操作,显然必须非常小心这些匹配。 (2认同)

小智 8

例如使用 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.`
Run Code Online (Sandbox Code Playgroud)

fsck -cc /dev/sda1