Summary
My wife saved two important SD cards from her camera to a faulty USB disk I'd given her. The images got corrupted and she'd deleted the files from her cards. Could Open Source come to the rescue? Let's hope so because divorces are expensive!
Advertisement
Barry Gets In Trouble
My wife recently went on a trip with her sisters to Nicaragua, and took lots
of great pictures with her digital SLR camera. The hard drive on her Mac
had filled up so I gave her a USB external drive that I'd used several times
before, confident that she could export her images onto it instead.
Well, apparently there was something wrong with the disk because all the
images exported from the card got corrupted. To make matters worse, she'd
deleted the images from the cards. Needless to say, she was very discouraged
at the loss of these pictures, and I started to fluff up the throw pillows
on the couch.
Like any caring and mortally afraid husband, I reassured my wife that I could
fix things, so I took the cards and her camera and retreated to my cave, er,
office. Knowing almost nothing about SD cards, I immediate typed in the
first brilliant search that came to mind: "recover SD card images". This lead
me to lots of commercial software products, almost all of which ran
exclusively on Windows. Of course, we're a Windows-free home, so I prepared
for a long stay on that very uncomfortable couch.
Motivated by the phantom twinges prickling my lower back, I did a clever
thing: I went to Wikipedia and looked up SD cards. As most of you probably
know, SD cards for digital cameras are usually formatted with FAT16 or FAT32
file systems. This ancient crufty file system was actually an advantage for me
in this case, because deleted files don't actually get deleted, they
essentially get hidden by being renamed. I'd never trust my company data to
such an insecure file system, but now I was glad for it, and I was beginning to
smell the brownie points baking.
Sharpening up my Google-fu led me to this great page:
Here, there's lots of good advice on using dd and fsck to try to recover the
files. The dd command was particularly useful as I could experiment on a copy
of the SD card's image and not directly on the card. Unfortunately, I
couldn't make much headway with fsck.vfat. I hoped the dog would welcome some
(purely platonic!) company tonight.
PhotoRec is an open source digital image recovery program that ignores the
underlying file system (now known to be hosed) and goes right after the image
data. Hmm, I wonder if it was available on my Ubuntu machine:
% apt-cache search photorec
testdisk - Partition scanner and disk recovery tool
% sudo apt-get install testdisk
(PhotoRec uses testdisk and the photorec binary is provided with that
package.)
Now, the only thing left was to thoroughly read the manual, and carefully,
non-destructively, and systematically experimenting on the image files. I
noticed that it was getting pretty dark outside, and my wife was refilling her
wine glass, so I threw caution to the wind and invoked
Warsaw's Fourth Law:
% sudo photorec sdcard.bad1
The curses u/i was a bit clunky, but fairly easy to navigate, and my clueless
guesses at some of the options yielded almost immediate results. PhotoRec
quickly recovered about 300 pictures off the first bad card! I ran
downstairs, tore the half-completed divorce papers from my wife's shaking
hands, and dragged her upstairs to show her the pictures imported into
F-Spot. Having done almost nothing more than a bit of web searching, a
package installation, and a shot-in-the-dark program execution, I now looked
like a hero. Thanks Google, Ubuntu, and Christophe GRENIER (the author of
PhotoRec).
This basic scenario has played itself out countless times in my open source
career. There's usually some very cool little program that does almost
exactly what you need, but if there's a recurring theme, it's that such
nuggets can be quite difficult to find. You're faced with a problem, you
suspect there's a solution Out There, but getting from problem to solution is
a mysterious path. How many such problems go unsolved just because their
existing solution isn't easily found?
I don't have any great ideas to make this path from problem to solution less
windy and rocky. I welcome your comments. But right now, it's bed time. Oh
honey...
The other product from CGSecurity -- testdisk -- has saved my life more than 3 times. In situations where you've messed up your partition table, testdisk is magical. And you look like a hero!
My friend had lost great amount of data on his harddisk, so I was looking up for solutions. We tried some Windows solutions (although I was not happy with them), but it turned out that even after 6 hours of processing the results were highly disappointing! Then Google told me about testdisk. Not surprising though, but testdisk recovered every single file!