Find and repair HDD badblocks
Posted: 2023 May 03, 18:56
It is assumed that the operating system stops starting, some files appear corrupted, some files cannot be read, directories and/or files disappear while the operating system is running. One of the solutions (if it is not a ransomware type virus that encrypts and hides files) is by scanning the HDD.
The HDD is scanned for sectors, and they will be printed if found.
In this case some of the bad sectors are as follows
After finding them, writing to each block is attempted with the following command
After writing each individual block, the badblocks command is executed again to scan if there are any "bad" type sectors.
If the HDD supports S.M.A.R.T. (Sefl-Monitoring Analysis and Reporting Technology ), will automatically detect that writing failed on that block (sector) and will use another sector. Of course, the problem sector will not disappear from the HDD, only that it will no longer be used and no more problems will occur due to it.
Recommendation: It's time to take that HDD out of production and replace it with another new HDD because its life is nearing its end.
Code: Select all
[root@ ~] badblocks /dev/sda1
In this case some of the bad sectors are as follows
Code: Select all
4903531
4903658
4903729
4903814
4903957
4903959
Code: Select all
[root@ ~] dd if=/dev/zero of=/dev/sda1 bs=1024 count=1 seek=4903531
[root@ ~] dd if=/dev/zero of=/dev/sda1 bs=1024 count=1 seek=4903658
[root@ ~] dd if=/dev/zero of=/dev/sda1 bs=1024 count=1 seek=4903729
[root@ ~] dd if=/dev/zero of=/dev/sda1 bs=1024 count=1 seek=4903814
[root@ ~] dd if=/dev/zero of=/dev/sda1 bs=1024 count=1 seek=4903957
[root@ ~] dd if=/dev/zero of=/dev/sda1 bs=1024 count=1 seek=4903959
If the HDD supports S.M.A.R.T. (Sefl-Monitoring Analysis and Reporting Technology ), will automatically detect that writing failed on that block (sector) and will use another sector. Of course, the problem sector will not disappear from the HDD, only that it will no longer be used and no more problems will occur due to it.
Recommendation: It's time to take that HDD out of production and replace it with another new HDD because its life is nearing its end.