Recovering Images from SD Cards with PhotoRec

I had the horrible situation last Sunday following removing a number of pictures using an SD reader from my SD card that when I inserted it in my camera, it registered nothing upon it. My heart sunk, because this card is stuffed full of images of me and my family (along with my 1 year old son growing up) and I was unsure of which ones I’d actually backed up. After perusing the hidden files on the card, all I could discover was the files I’d most recently transferred from the card….great…

Partly this was my own fault – I’d already experienced problems with the reader in question when trying to write images for my Raspberry Pi and shouldn’t have used it for transferring images I care about. The card in question is a uber cheapo Integral USB 2.0. Despite what the amazon reviews say, steer well clear of it – this has been a pain from day one, with intermittent transfer problems which triggered this situation.

After a little more digging, I came across Photorec, a commandline utility which seemed like it would hopefully help recover some of the images. I attempted to use it with my card reader, but given it’s credentials I’ve given above, found the scanning process would cut out and couldn’t get through the whole card. At this point the card was being reported empty….great…Given the way PhotoRec works, I understood it would still be possible to extract the images despite this. I decided to order another reader and hold fire until it had arrived – this time I opted for a Kingston USB 3.0 (which I haven’t had any such problems with so far).

The Solution

Here are the steps I followed after receiving my new sd reader to recover images from the card using PhotoRec. I’m listing them for anyone else who may have the same horrendous stomach wrenching problem I did last Sunday. It seems to have worked pretty well, with only 1 movie file coming out corrupted and about 500 images recovered.

Firstly, I wanted to take a copy of the card as it currently stood following my investigation. For this I used df, diskutil and ddrescue.

To determine where the card is currently mounted (look for the one that’s about the right size):

df -h

To unmount the card so we can fiddle with it:

sudo diskutil unmount /dev/disk1s1

To backup the card to a disk image on your macbook:

sudo ddrescue /dev/disk1s1 ./sdbackup/image.img backuplog

Finally, using PhotoRec scan the disk image that was just created. My image was FAT formatted I scanned the whole thing rather than just unallocated blocks.

sudo ./photorec ~/sdbackup/image.img

The final piece of this saga was to rename all the files PhotoRec created so they were in folders according to their exif data. My photos are all in folders like “2012_06_30″, so to have 500 files named “f0677440.jpg”, “f0688768.jpg” in a random PhotoRec directory would be pretty annoying. I had looked at setting up an automator task for this, but I ended up using PexifTool for simplicities sake (I’m sure there are other alternatives). I believe if you go the Automator route, you may well have to install plugins in order to be able to extract exif data from files.

comments powered by Disqus