This site is now 100% read-only, and retired.

XML Logo

Posted by ido50 on Sun 27 Jul 2008 at 21:36
Tags: none.

At home I have several external hard drives which I use to store movies, music, etc. One of these drives is a 500GB Western Digital My Book, which I use for storing TV Shows. The drive came with a FAT32 partition or something, but I formatted it to ext3 right after I bought it.

I almost never check these drives for errors with fsck for some reason, and last Thursday the partition was kinda acting up (Entire folders would disappear and I had to remount the partition for them to show up again), so I decided to make a little check on it.

So I pressed F12 and fired up the yakuake terminal emulator, switched to root, and hastily issued the command mkfs.ext3 /dev/sdc1.

Anything looks weird? Well yes indeed. Instead of performing an fsck.ext3 on the partition to check for errors, I did an mkfs.ext3 to format the partition.

Of course I didn't realize it at first. It took me a few seconds, but when I saw that the output was entirely not what I expected, I realized what was going on and quickly pressed Ctrl+C to terminate the process.

I spent the next few minutes panicking and sincerely considered hanging myself on the ceiling, and wildly started testdisk like a million times, trying to see if it finds any files on the partition, to no avail. So when I was done panicking, I quickly examined my situation. When I killed the mkfs process, it was in the middle of laying out backup superblocks across the partition. I realized that when I first formatted the partition to ext3, I used the exact same command I used by mistake now, so if I stopped it early in the process, it is more than safe to assume that the superblocks are being stored in the exact same locations they were stored before, and my files shouldn't be harmed.

Of course, since the filesystem was screwed, I couldn't mount the partition or anything. So I decided that perhaps I should try to format the partition again with mkfs, only this time I'd use the -S option so that it only writes superblock and group descriptors, without touching any of the data. The man page for mkfs.ext3 claims that "it is critical to specify the correct filesystem blocksize when using this option, or there is no chance of recovery." Again, I figured the blocksize is exactly the same as before, so I just read the current blocksize using the following command: dumpe2fs /dev/sdc1 | grep -i 'Block size', and issued the format command: mkfs.ext3 -S -b 4096 /dev/sdc1.

I'm not sure how crucial was this step for saving my data, since it finished pretty fast and its last output was a complaint that an ext3 journal already exists. Which to me was good news enough so I went to the next step, which obviously was checking the filesystem for errors. Assuming it would take a long time, and that I would probably answer "yes" to any question that would pop up, I issed the command fsck.ext3 -y /dev/sdc1 and went to sleep.

It was still running when I woke up, so I went to work, and when I got back, it was done, but said the filesystem still has errors. So I issued the same command again. This time it was fast, and though it didn't complain that the filesystem still has errors, I issued the command yet a third time, just to see the word "clean."

I mounted the partition, and none of my directories was there, except for the annoying, but apparently life-saving directory called "lost+found". All my files were there! The directory structure was all screwed up, but none of my files were missing!! All of them work, all the same as they was, and now I can continue falling asleep to the soothing sounds of Homer Simpson's voice.

1. The root user is the root of all evil. Or Simpsonwise, it is the cause of, and solution to, all of life's problems.
2. Buy a very large external hard drive (Possibly 1TB) and regularly synchronize it with the other drives.
3. Get a girlfriend. If you're willing to kill yourself for a gajillion episodes of weird TV Shows, you've got serious problems.
4. John Cleese is the king!