F***, my disk got screwed up!
- Published January 4th, 2007 in Tips & Tricks, GNU/Linux
If your disk is acting strangely (like not being able to copy files or permission denied even if you have full rights) than there’s a chance that you can still use it if it’s only a matter of bad clusters.
If you’re running *BSD, especially FreeBSD, you have a tool on your userland called badsect that basically creates dummy files around the damaged blocks. This will consume extra space since some extra good blocks are required to record the inode (depending on your filesystem/block size settings).
In case you’re running Linux then you can use fsck. It works in a quite different way (or how the British usually say, bloody different. Cheers to my UK readers :-). It keeps a list of the bad blocks (this list is done on the file while the system is being formatted or later on by running badblocks).
Bare in mind that there’s a strong chance the bad clusters will keep growing. If the information is not that critical than it’s a nice workaround during the time you don’t have a new hard drive.




If it’s just one block or a few consecutive blocks, then the disk may still be OK. The solution for this is to write zeros over the affected blocks (and only those) with “dd”.
The intuitive reasoning for this is that the block(s) error correcting code/checksum is bad, and writing zeros without reading creates a new one. But in fact, it probably only forces the disk to realocate the block from the spare blocks area.
If this doesn’t work, then the disk may be going bad after all (no more spare blocks).
I have two disks with a couple of back blocks that I fixed this way, and this was like 5 years ago (and they never developed new ones).
Now, I don’t actually trust disks with any number of bad blocks, fixed or not, unless I _really_ have to…