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?
Best Answer
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.
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:
How can I read my hard drive's SMART status in Windows 7?
What is the easiest method of checking SMART status for your hard drive?