Recovering Deleted Photos from an SD card with PhotoRec

Whilst on holiday recently I was using Shotwell (the rather excellent photo manager for Ubuntu) to import some photos. After importing the photos Shotwell asks if you want to delete the imported photos from the card. Without thinking, I absently-mindedly said yes. What I'd missed was I'd not separately imported the videos that were on that SD card, (Shotwell doesn't currently cater for video imports though this feature is destined to be added soon.) usually this isn't an issue but in this case I'd inadvertently removed the videos I wanted to keep.

The good news is by realising I'd removed the files, I could just make sure I didn't write anything to that card, because deletion just means that the space those files occupies on the memory card is marked as free. So as long as you don't fill that freed space with new writes the files should be recoverable.

So I looked for a suitable utility to recover my files and I came across PhotoRec. It's available for a whole slew of operating systems including Windows, Linux and OSX.

On Ubuntu PhotoRec is available via the package "testdisk":

sudo apt-get install testdisk

Mass Storage Devices vs Photo Transfer Protocol

As I was on holiday I wanted to use photorec on the SD card using the camera as a card reader. Depending on which camera you're using this may or may not work. In my case I was using an IXUS, it doesn't support mounting of the memory card as a mass storage device. On my wife's Lumix it's configurable. So to be able to recover the files I had to wait till we got home so I could use the card reader in my Lenovo dock.

File Recovery

Recovering the files is done on the command line. On Linux you have to use sudo e.g:

sudo photorec

It then displays a list of the available drives you can recover data from. In my case it was /dev/sdc:

Next you just have to select the partition table type, in my case it was Intel/PC - PhotoRec highlights the detected partition table type by default.

After that you have to choose the partition, here I chose "Whole disk":

After that choose the filesystem type. Once again the default is the auto-detected value. In this case Other because our card is FAT.

Next you decide where to save the files. PhotRec creates directories inside this location itself so Desktop will suffice:

Next the recovery begins.

Once complete you should find all your files in a directory named: "recup_dir.1".

This took about 10 mins for a 2GB card on my machine and lo and behold my videos were restored.

comments powered by Disqus