Tuesday, April 17, 2012

Recovering pictures from a digital camera memory card in LINUX

Apparently digital cameras can sometimes mess up the file system on the memory card used to store the pictures. This happened to me on an 8MB SmartMedia card inside an "ancient" (8 years old!) Agfa ePhoto 1680 digital camera.
It turns out to be relatively easy to recover most of the pictures on the card, even when the camera says it can no longer read it, and presents you with the question (as in my case): "Format? Yes/No".


You need a multimedia card reader to read the card, like the Hama 35in1 card reader that I'm using.


Note: a much better recovery tool is photorec, part of the testdisk package (yum install testdisk).


For reference, I'm leaving the (outdated) info below:


plug in the card reader, and insert the camera memory card into the reader
after about 10 seconds, type:
[root@akwal]#dmesg | tail and note lines like these:
SCSI device sdh: 16000 512-byte hdwr sectors (8 MB)
sdh: sdh1
as root, type:
[root@akwal]#dd if=/dev/sdh1 of=memcard.dat
(for sdh1 fill in the name you saw in the previous step)


if the card has hardware errors, use this command:
[root@akwal]#dd if=/dev/sdh1 of=memcard.dat conv=noerror


Note that now it may take a long time for the card to be read, and that recovery may be much more difficult, depending on how much of the card is damaged.
Now all contents of the memory card have been saved into a file (called memcard.dat). If the last step produced an error, it is likely that the memory card is physically broken, and the pictures can not be recovered.


Next, we need a tool to extract JPEG images (assuming your camera stores its pictures as JPEG files, which most cameras do) from the memcard.dat file.


For this I used a tool called jpeg-recover: download and install it (decompress using tar jxvf, then in the jpeg-recover directory type make). Run it using:
jpeg-recover memcard.dat


This should recover all JPEG files on the card (and may include lots of old ones as well).


I've heard of cases of jpeg-recover crashing, which is fixable, let me know if this happens.


Send me your comments!


Something didn't work as expected? You'd like to add some useful info to this tip? Use the form below to send me your comments

0 comments: