How can I know the number of bad sectors on my hard drive?

I know how to to check / repair my hard drive but I don't know a way how to see the number of bad sectors on my hard drive.

P.S. It looks like my hard drive will die soon :-(


There are two ways to detect bad sectors in Linux: you can use the disk utility (gui), or you can use the badblocks command to check your hard disk for bad sectors:

sudo badblocks -v /dev/{device}

That should answer the question but for anyone else interested in how to mark them it can be done with 2 simple commands...

You add the bad blocks to a file...

sudo badblocks /dev/sdb > {/dir/to/filename}

and then tell fsck to mark these as unusable with ...

sudo fsck -l {/dir/to/filename} /dev/{device}

Use fsck.ext3 (e2fsck) for instance and use the -cc option

-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