Recovering lost photos from a memory card using Linux

Occasionally my camera has messed up the memory card and lots of photos have been lost. Of course, the photos are not really lost it’s just the file system that is corrupt. With the right software, it’s possible to search the contents of the card and retrieve the lost or deleted files.

I use Linux, and as with most things, there are free open-source applications that do exactly what you want. If you are ever in this situation, here is what you need to do.

As soon as you know there is a problem - take the memory card out of the camera! If you do not do this you run the risk of overwriting the lost photos, and then they will be lost forever.

Install the application photorec which is part of the “testdisk” package. Under Fedora Linux this is very easy to do since it is included in the Fedora repository. As root run the command

# yum install testdisk

Now, using a card reader make an image of the contents of the card. This can be done easily using “dd” which is included by default with most Linux distributions. Assuming that your card reader shows up as “/dev/sdb” and the photos are on the first partition, use

$ dd if=/dev/sdb1 of=card.img bs=1024

You will need to check this is correct for your particular system.

Finally, give the card image to photorec and follow the prompts.

$ photorec card.img

Tell it the type of partition - this will almost certainly be FAT or FAT32. Photorec will then search through the image and recover any media files it finds which will hopefully be all of your photos! This has certainly saved me a lot of frustration in the past!