HowTo recover jpeg images from corrupt memory card

Today my digital camera decided that it had been too well behaved of late and the SD card decided to completely corrupt itself for no good reason, losing all the photos on it.

I've spent a significant portion of my youth messing around with file system editing and partition table editing an was not going to give up on the series of photos I'd taken over the last couple of days - luckily it didn't need anything more than a couple of simple commands to recover all the photos. Go Open Source software.

This tutorial is written for Ubuntu, but should be similar for most Linux machines

Step 1 was to make an image of the card (to have a backup of it) using the venerable dd command.

sudo dd if=/dev/sdb of=sdcard.img bs=1M

  • sudo - used to perform command as root user (i.e. have correct privileges)
  • dd - command to copy data a byte level
  • if=/dev/sdb - read data from /dev/sdb - you may need to change this depending on where your memory card it located.
  • of=sdcard.img - save this to the sdcard.img file in the current directory
  • bs=1M - Copy it in 1M chunks

Once this has completed you will need to run the marvellous program recoverjpeg on it.

First lets install it:

sudo apt-get install recoverjpeg

Then run it:

recoverjpeg sdcard.img

and you should get something like the following:

$ recoverjpeg sdcard.img
Restored 290 pictures
The images will be saved in the same folder.

Check the images out and hopefully it works as well for you as it did for me.

Cheers, Mark

Comments
Fantastic!! Windows screwed up our memory card trying to rotate an image. I spent hours with PCFileInspector etc and still jpegs were corrupt.
Back to Ubuntu and in 30 seconds all the photos were back with us.
Thanks a million!!
# Posted By Nelson Perry | 10/2/07 6:02 AM
Thanks for the help, you've really saved me. I used this to recover over 100 photos of my youngest son I had saved on 160GB external drive. The only challege I had is that I had to do this in chunks, since I had no drive big enough to hold a 160GB disk image.

Something like dd if=/dev/sdb of=disk.img bs=1M skip=<blocks copied> count=30000

I repeated the above 6 times, each time copying 30 Gigs of data. I also had to skip the first 40 megs since there was some kind of disk error.
# Posted By Jason Nichols | 6/22/08 12:07 PM
Sorry, I meant 1000 images! Also, your captcha took me seven tries to get the text correct >:-0
# Posted By Jason Nichols | 6/22/08 12:10 PM
Glad the tutorial helped out. Sorry about the captcha, I might have to come up with something else, as some blogspam is still getting through.

Cheers,
Mark
# Posted By Mark Lynch | 6/23/08 4:06 AM
This is really useful. Alas, I can't get it to work under my setup. Here is what I tried:

$ sudo dd if=/dev/mmcblk0p1 of=sdcard.img bs=1M
dd: reading `/dev/mmcblk0p1': Input/output error
0+1 records in
0+1 records out
126976 bytes (127 kB) copied, 0.0539359 s, 2.4 MB/s

I also tried running recoverjpeg directly on /dev/mmcblk0p1, likewise to no avail.

/dev/mmcblk0p1 is definitely there; I can open it with fdisk.

Any ideas?
# Posted By Colin | 6/28/08 11:03 PM
Hi Mark,

I've used recoverjpeg also and it seems to work pretty well. Out of all 980 photos I had, 69 of them are still corrupt. Also there are many of the photos that seem to be warped i.e. there may be half the image missing or it may be half one image, half another which is a bit weird.

I've tried using an application called photorec (apt-get install testcard and then photorec sdcard.img ) which seems to have done a very good job. It has around the same number of images corrupt but there doesn't seem to be the same visual defects with recovered images. Combined together they all have done a pretty good job of recovering most of my images!
# Posted By Eddie Long | 9/13/08 1:59 PM
I've been trying to recover images from a CF card all week to no avail, and this worked a treat! Many thanks.
# Posted By Chris | 10/14/08 5:14 AM
If the memory card is not recognized in the PC or it is impossible to access the data on it, the controller on the card is damaged. There is only one way to get the data back, unsolder memory chips and directly access their raw data with a programable chip reader. Software can't help, that is a physical damage! Have a look at: http://card-recovery.biz/us/service.php
# Posted By leoseo | 4/2/09 9:13 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.