0

If I understand the situation, modern hard drives are responsible for bad sector detection and avoidance. When a sector is written, it is immediately read back to ensure that sector is good, and if it isn't, the physical sector is marked bad and the data is written somewhere else, changing the mapping between that virtual sector and its physical sector.

That all makes sense except for one thing: where are all of these extra sectors coming from? Are there just more physical sectors than virtual sectors? That's the only thing that makes sense to me. Otherwise, a command like dd if=/dev/urandom of=/dev/sda would fail eventually once it inevitably hits the bad sectors, which are sure to exist, even on the best and newest of drives.

Also, after running the above command, as far as the hard drive knows, every virtual sector on it is being used. Yet there isn't a sudden increase in write errors on the software end, like you would expect there to be if the hard drive had run out of room to remap bad sectors. Therefore the hard drive must have somewhere else to map any new bad sectors it finds, even though as far as the hard drive knows, the entire virtual address space is being used.

Assuming there are more physical sectors than virtual ones, how can you figure out how many extra sectors there are, and how many are left? That way, when the extra sector supply is running low, I could get some kind of warning so I can replace my hard drive before it dies.

EDIT: It turns out I didn't exactly understand the situation right. Reading after every write operation isn't necessary when error correction codes are used. That makes me wonder, though: does a sector get marked bad and remapped every time an ECC has to be used to recover from a write error to a sector?

  • "When a sector is written, it is immediately read back" -- Not true. Such an operation is called "write-then-read" or "write verification", and is not a standard write operation (because such an extended operation requires another revolution of the platter). – sawdust Oct 25 '16 at 22:57
  • Wow, really, it isn't on by default? Crap, I'm going to go figure out how to enable that. It seems fairly obvious. – enigmaticPhysicist Oct 26 '16 at 6:01
  • "It seems fairly obvious" -- Only if you're paranoid. You probably don't even know what kind of write caching policy is employed in your HDD. See Write Caching. IOW your OS could be notified that the write operation is successfully complete before the the sector has been actually written, much less verified. – sawdust Oct 26 '16 at 8:32
  • Here's a patent for the (integrated) disk controller to automatically perform a read-after-write. Look for the paragraph near the end that starts with "There is a performance cost associated with this RVaW feature..." that validates my first comment. I have no idea if any HDD actually uses this scheme. – sawdust Oct 26 '16 at 8:46
  • I just remembered these hard drives also use error correction. That's how they can get away with it. Very interesting. And I know about caching, BTW. – enigmaticPhysicist Oct 26 '16 at 19:45
2

Where are all of these extra sectors coming from?

Modern disks have a pool of spare sectors that can be swapped with damaged sectors.

This is called the Spare Sector Pool.

Spare sector pools

All modern hard disk drives have a spare sector pool. This is used when bad sectors develop during the normal life of the hard disk and any new bad sectors are 'replaced' with good ones from the spare sector pool. This process is invisible to the user and will probably never know that anything has changed.

Source Bad sector remapping


How can I get some kind of warning so I can replace my hard drive before it dies?

Use smart monitoring software.

See the following questions for more information:

  • That's a confusing and low-quality article used for a citation. I've done extensive work with (older) disk drives and controllers, and the explanations made little sense (and the bad grammar doesn't help). AFAIK zero-filling a drive doesn't repair or fix bad sectors. A much better article is Bad sector remapping – sawdust Oct 25 '16 at 23:13
  • I have heard of SMART. Does it specifically tell you how many sectors are left in the spare sector pool? – enigmaticPhysicist Oct 26 '16 at 5:16
  • @sawdust Thanks for the reference. I've updated the answer. – DavidPostill Oct 26 '16 at 7:58
  • @enigmaticPhysicist Not directly. SMART won't tell you exactly how large the spare sector map is but it will tell you how much of it is used. Combined with the trigger information as to percentages for a SMART failure and you should be able to determine with a fair amount of accuracy just how big the spares are. – DavidPostill Oct 26 '16 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.