Find and repair HDD badblocks

Locked
User avatar
Mihai Romania
Posts: 60
Joined: 2023 May 03, 14:12
Location: ROMANIA
Contact:

Find and repair HDD badblocks

Post by Mihai »

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.

Code: Select all

[root@ ~] badblocks /dev/sda1
The HDD is scanned for sectors, and they will be printed if found.
In this case some of the bad sectors are as follows

Code: Select all

4903531
4903658
4903729
4903814
4903957
4903959
After finding them, writing to each block is attempted with the following command

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
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.
I'm on LinkedIn
Locked