Adventures with image recovery
So. I was trying to put up images that Dad and Ruth had sent, and something weird happened in gallery, and the long and the short of it is that the damn thing got confused, and went and deleted a directory full of perfectly good pictures (which had, of course, already been deleted from the flash card).
Well, compact flash cards use fat32, so there was hope of recovering the files, and we had another CF card full of images to play with, so that we wouldn’t have to mess with the card we’d already messed up. So, we’ll tell you what we did, and link to the pages that helped us, and maybe someday it will help you, too.
Making a copy of our wounded CF card
pre. dd if=/dev/sda of=image.img bs=512
Next, we mounted the image to a temp mount point. Some math is involved here, and this is how it goes:
pre.. fdisk /dev/sda
Command (m for help): pDisk /dev/sda: 256 MB, 256901120 bytes
16 heads, 32 sectors/track, 980 cylinders
Units = cylinders of 512 * 512 = 262144 bytes
/dev/sda1 * 1 979 250608 6 FAT16
We want to mount that first partition, which starts on cylinder 0, head 1, which leads to offset: 32 sectors * 512 cylinders = 16384:
pre. mount -o loop,offset=16384 -t vfat image.img /mnt/test
And WOOOOO we have an image in a perfect replica! YEE-HAW!
*
References
- Creating and Using Disk Images mini-HOWTO – this one is not directly related to file recovery, but it does have excellent information on how to make an image of your disk, so that you can muck around with a copy instead of the original.
- How to recover lost images from compact flash – This one has lots of nice tips, though he’s more focused on retrieving data after the FAT table got corrupted than because silly fingers pushed the wrong button.
- dosfsck to the rescue! – This one would have worked if we hadn’t deleted the directory structure. dosfsck does a pretty good job of resurrecting the files, but if you’ve gone and nixed the directory structure, which we had, it can’t do much.



