How to fix bad sectors on HDD using badblocks overwrite

How what??!?

First of all I have to say that this procedure is NOT able to repair physically damaged HDDs and it is just a waste of time trying to repair physically damaged HDD this way - sorry - no magic today :-/

Using this procedure you are able to repair sectors which are currently unreadable because they were not written properly for some reason - in most cases because of power-fail or vibrations during write process. For examle HDDs from notebooks suffer vibrations while playing games, because the HDD is just under the keyboard...

OK, but how?

The procedure itself is very simple - we just call badblocks to make non-destructive read-write test of the HDD. This means that every sector is read - written (which is important) - and verified by badblocks and this makes the HDD to try to rewrite every sector again (even if the read operation failed) - result of this is that sector which were written improperly in the past are correctly overwriten and become readable!

Also in some cases (depends on drive's firmware) the controller is able to replace (realocate) physically damaged sectors with (to) spare ones (in case that the drive have some left) and fix light physical damage of the HDD, but I DONT recommend you to use such HDD for any data that you cant afford to loose.

Using badblocks to fully-rewrite HDD

Make a backup of all data on the HDD - it will put extra load on your disk which might cause it to fail.

# run following command as root
# replace sdX according to your drive
badblocks -svvn -c 262144 /dev/sdX

Now wait until the procedure finish. After that results are shown. For example:

Pass completed, 7 bad blocks found (7/0/0 errors)

This means that there were 7 error while reading, 0 when writing and 0 when comparing, so right now we fixed 7 unreadable sectors on the HDD.