I wonder why there is no complete answer on this page.
Here are the two steps to recover bad blocks (why stop at scanning and get only numbers of bad blocks?):
Step one, collect numbers of bad blocks in file:
sudo badblocks -v /dev/sda1 > ~/bad_sectors.txt
Note, that I do not use the key
-s that is normally used to show a progress indicator, we need to have only numbers in the file.
Step two, fix them (it is not repair; it just removes them from consideration while arranging data on drive):
For extX filesystems:
sudo e2fsck -fccky /dev/sda1
sudo fsck -fccky /dev/sda1
Thats it. It alleviates the problem if bad sectors exist but are not growing in quantity rapidly.
These options meaning:
-f Force checking even if the file system seems clean.
-cc This option employs the use of badblocks(8) program to do a read-only scan for bad blocks. If there are any bad blocks they will be added to bad block "file" (inode) to prevent their use. If twice, then the bad block scan will be done using a non-destructive read-write test.
-c option, any existing bad blocks in the bad blocks list are preserved with adding newly found.
-y Assume an answer of `yes' to all questions.
Also, deriving from the model of the HDD, I would recommend downloading and using the Hitachi Drive Fitness Test, which should work with the most HGST-legacy HDDs:
(need to build a bootable DOS volume, read the doc)