Jan 03 2010

Photo file recovery (with Linux tools)

Published by Dougal at 9:54 pm under Computing

Well, I’ve just done my good deed for the day by pulling some photographs off a corrupted memory card. Helen’s camera stopped talking to its SD card on Boxing Day and the photos from Christmas Day were assumed lost. The solution was quite painless:

  1. Copy the contents of the memory card to a file for safekeeping. The file ends up taking up as much space as the original disk does but it’s generally much nicer to take one copy and use it rather than risk further degradation if you’re worried that the memory card itself is dying.

    $ dd if=/dev/sdd of=memcard.img

    The card reader was named /dev/sdd from the viewpoint of my machine but this will no doubt depend on what kind of reader and how many devices you use. Adjust for your own circumstances. Typing dmesg into a terminal just after you’ve inserted the card in the reader will probably give you usable info — this is what I saw, in case it helps:

    [177907.297698] sd 5:0:0:1: Attached scsi generic sg4 type 0
    [177907.321601] sd 5:0:0:1: [sdd] Attached SCSI removable disk
    [177922.175874] sd 5:0:0:1: [sdd] 3994624 512-byte logical blocks: (2.04 GB/1.90 GiB)
    [177922.177838] sd 5:0:0:1: [sdd] Assuming drive cache: write through
    [177922.183593] sd 5:0:0:1: [sdd] Assuming drive cache: write through
    [177922.183608]  sdd: unknown partition table

    You can see it found the disk, named it sdd but couldn’t read any partition data from it. This is just as we expected because it got corrupted somehow.

  2. Install file recovery tools. This installs a disk recovery program and something that will trawl through disks looking for lost files. It looks like a direct port of a DOS/Windows app because the help commmand lists all CLI flags as being prefixed with a / instead of --. But it still works well.

    $ sudo aptitude install testdisk

  3. Run the newly installed photorec from the above suite. Any found files will be put into a newly-created directory called recovered. If this dir already exists it’ll create a new one with a numbered suffix rather than reusing it. I don’t know why.

    $ sudo photorec -d recovered memcard.img

    We were only expecting a few dozen photographs because the card had been emptied just before Christmas. In the end it pulled over 300 JPEGs and a video from the memory card — a nifty tool if you accidentally reformat a disk!

The Christmas photos were saved and Helen will no doubt be posting them soon. Stay tuned.

3 Responses to “Photo file recovery (with Linux tools)”

  1. Helenon 03 Jan 2010 at 10:04 pm

    You forgot the most important line of code, silly!

    $ sudo pull your socks up, grumpy memory card!

  2. Kenon 03 Jan 2010 at 11:11 pm

    I am terribly impressed, Dougal, but you are an expert. I think if I ever find myself in a similar situation, I will probably pop round and get you to do it, though!

  3. […] post: Looking Out To Sea » Photo file recovery (with Linux tools) Tags: friends, hobbies, life, linux, looking-out-to-sea, memory, photo, recover windows files, […]

Trackback URI | Comments RSS

Leave a Reply