0

Let's say a movable-part hard drive has a few damaged sectors somewhere. Is there a way to mark these, and a good margin neighbouring sectors, as unusable or map them to a separate partition called "broken", so that you can semi-safely use the rest of hard drive, of course at a risk, but with a smaller chance of letting the drive head going near the broken sectors?

I know this is a bad idea in principle, but some times you have old hardware with no important data that you want to keep running for fun and experiments without spending money to fix minor issues.

How can I do this using UNIX or macOS?

Mokubai
  • 95,412
forthrin
  • 2,207

2 Answers2

4

Theoretically speaking, regardless of whether the sectors are marked unusuable, the fact that you can see these sectors at all means that the drive is getting progressively worse, and that the drive should be replaced in short order before it fails completely.

The drive firmware has facilities to deal with damaged sectors and to cordon them off from use and reserves a small amount of disk space to deal with this. The fact that you can see bad sectors directly means that all of the reserved space has been consumed, so the few bad sectors you can see actually have hundreds to thousands of "invisible" bad sectors behind them. So it's not that the drive will be going bad, it's that the drive has already been going bad for a while already.

3

If you're reformatting the drive, you can scan for problematic spots via badblocks and give mkfs the information so that the filesystem can blacklist the bad sectors on creation. The following commands generate a blacklist at /root/badblocks.txt and use them for filesystem creation with mkfs.

$ badblocks -wsv -o /root/badblocks.txt /dev/<device>
$ mkfs.<filesystem-type> -l /root/badblocks.txt /dev/<device>

On the other hand, fsck can scan for bad blocks on an extant filesystem and blacklist them without destroying the existing data:

$ fsck -vcck /dev/<device-PARTITION>

Since the drive is showing signs of damage, don't forget to take precautions to keep your data safe.

https://wiki.archlinux.org/index.php/badblocks