Recovering Bad Sectors in Linux
- Details
- Written by: JC
- Category: Linux
For those dealing with either hard drive recovery (we're talking spinning disk) or want to use them in retro builds, being able to mark or reassign sectors is very useful. For recovery it could speed up the effort by having the OS skip over the marked bad sectors or for retro you can still use the disk minus the space marked in bad sectors. As is mentioned before this is only relevant to spinning disks as most of the time a physical event occurred to have the bad sector creep up.
The obvious OS choice for this effort is Linux. I like to use System Rescue CD to live boot the machine with the hard drive installed as it comes with all tools one would need to do any type of recovery of data. (Don’t let the title fool you, you can flash this CD to a USB boot stick).
Once booted, you need to find the sector number that is bad. I use this command to start a sector-by-sector scan so that I can find the sector numbers:
badblocks -v /dev/<device>
Once you have the sector number you can use these combination of commands to make the change to the hard disks:
sg_reassign -a <sector number> /dev/<device>
sg_reassign -g /dev/<device>
You would then rinse and repeat until badblocks comes back clean. I was reading that some (if not most hard drives) do contain “extra” sectors just for this purpose so you don’t lose space.