Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Ubuntu: Recovering Photos from Memory Cards

📅 2010-Apr-02 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

 

Today a friend deleted a few photos from my camera SD card by mistake. But, recovering those deleted photos turned out to be quite easy. Here is how to recover deleted photos from a memory card on Ubuntu:

  1. As soon as you discover the deletion, shutdown the device, take out the memory card and make sure it is made read-only. Most SD cards have a tiny latch, that when pulled down locks the card into read-only mode. For example, the yellow colored latch on my Kingston SD card in the photo above.

  2. Put the card into the memory card reader slot on your computer. Typically, Ubuntu will mount it automatically.

  3. Figure out the device name of the mounted memory card. This can be done by looking at the contents of /etc/mtab. This text file holds the table of mounted devices on the computer. For example, my SD card is named ASH_D40 and I found that its device name is /dev/mmcblk0p1 by finding this line in /etc/mtab:

    /dev/mmcblk0p1 /media/ASH_ND40 vfat rw,nosuid,nodev,uhelper=devkit,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,flush 0 0
  4. Install the testdisk package. This is available on the Ubuntu repositories, so can be installed using Synaptic Package Manager. This package has photorec, a tool that can be used to recover photos from memory cards.

  5. Execute photorec as superuser providing it the memory card device name:

    $ sudo photorec /dev/mmcblk0p1
  6. Photorec leads the user through a few prompts, each of which is a multiple choice question. Most of them should be easy to answer, here are some of the important ones:

    1. Partition table type: For SD cards used in cameras, the choice should typically be [Intel] Intel/PC partition

    2. Partition: Since most SD cards are formatted such that the entire space is a single partition, the choice could be No partition [Whole disk]

    3. Filesystem type: Most SD cards are formatted as FAT16, hence the choice could be [Other] FAT/NTFS/HFS+/ReiserFS/...

  7. After it obtains all the necessary information, photorec churns through the memory card, this may take a while. It will access the card strictly in read-only mode, so there is no fear of it messing up the recovery information available on the card. After it is done, the recovered photos can be found in directories named in the format recup_dir.X, where X is an integer.