It depends on the filesystem you are using. If you are using ext2, etx3 or ext4 (IIRC Ubuntu 9.10 defaults to ext4 for new installs, earlier versions default to ext3) then you can run
e2fsck -c -c -k -C 0 /dev/device
i.e.
e2fsck -c -c -k -C 0 /dev/sdc1
for the filesystem on the first partition of drive sdc
. The filesystem should not be mounted while this takes place, so if it is needed for your normal running system you will need to run e2fsck
while booted from a "live CD" or similar.
The -c
option is what causes the surface scan to be added to what the checker does, then second -c
makes it do a non-destructive write+read test, -k
tells it to keep any existing list of badblocks instead of retesting them and -C 0
just makes e2fsck output more progress information as it does its work. See man e2fsck
for more detail.
The above will mark the bad blocks so that are not used in future. You will need to rerun it if you ever reformat the drive or that individual partition. You should also rerun it occasionally anyway, in case there are any "almost bad" sectors that degrade further. There is no way of "recovering" bad sectors.
I recommend you consider migrating your data onto another drive instead though, unless there is nothing of any real importance on there (i.e. it wouldn't inconvenience you overly if the drive suddenly got much worse and the data became practically unreadable or corrupt). If you don't replace the drive, make sure you have good backups in place for anything you do care about (though you should have a good backup regime in place anyway).
Using badblocks with -n raises the possibility of further corrupting the drive, particularly if there are many bad blocks, causing the firmware to exhaust the 'spare' blocks. – Taryn – 2018-11-07T00:47:21.753
1
For link purposes, as this answer may be of equal interest to Mac users who wish to check blocks of a volume that uses NTFS: Fix bad blocks on Mac hard disk and in Ask Different, What free or open source software can I use with Mac hardware to verify integrity of every block of a disk where Core Storage is used?
– Graham Perrin – 2012-07-27T18:06:01.107