I don't currently have a problem with one of my flash cards but I thought I'd throw this out there anyway because I ran across magicrescue which is a Linux program for recovering data from flash cards. From the man page...

Magic Rescue opens devices for reading, scans them for file types it knows how to recover and calls an external program to extract them. It looks at ``magic bytes'' in file contents, so it can be used both as an undelete utility and for recovering a corrupted drive or partition. It works on any file system, but on very fragmented file systems it can only recover the first chunk of each file. These chunks are sometimes as big as 50MB, however.

 

So even if you're operating system can't read the file system on the card you should be able to recover something. Before you use magicrescue you might want to make a copy of the flash card. First we need to know the actual device number of the card. We'll assume we actully looked at the label on the card before inserting it into our card reader and we know it's a 4GB card.

 

grant@workstation:~$ cat /proc/partitions
major minor #blocks name

8 0 80418240 sda
8 1 39070048 sda1
8 2 1 sda2
8 5 979933 sda5
8 80 3912704 sdf
8 81 3906976 sdf1

We see two devices, sda and sdf - the latter is about 4GB so that's our memory card. Now we can make a copy of the flash card in case we mess it up. Always back up your data before committing any actions on it!

dd if=/dev/sdf of=~/flashbackup.bin

Note: Make sure you change the /dev/sdf to match the contents of /proc/partitions on your computer!

Also make sure you type the rest in exactly as I have it. This will copy your flash card (in my case /dev/sdf) to a file called flashbackup.bin in my home directory. If later I want to make an exact duplicate of my flash card I can just insert a new flash card and revers the if= and of= lines. For example:

dd if=~/flashbackup.bin of=/dev/sdf

This is assuming your new flash card came up as /dev/sdf. View /proc/partitions to make sure before executing this string!!! If you're not sure don't do this. If for example you put in your operating system device name (sda?) instead of the flash card device name it will wipe out your operating system. You have been warned.

Now we have a backup so we can proceed in retrieving the pictures off of it. Let's start by making a directory in our home directory named recovered-photos for the recovered photos.

mkdir ~/recovered-photos

Before recovering you need to know which files you want to recover. Magicrescue has filters called recipes. A recipe knows how to scan for a particular file type. For example a recipe for jfif searches for jpeg files. You can make your own recipes if you know a bit about the file header but as they say, that's beyond the scope of this book. Currently the recipes included with magicrescue are listed here.

 

  1. avi
  2. elf
  3. gimp-xcf
  4. gpl
  5. jpeg-jfif
  6. jpge-exif
  7. mp3-id3v2
  8. msoffice
  9. perl
  10. png
  11. zip

If we're trying to recover jpeg files we'd specify the jpeg-jfif recipe. If you need to scan for a different file format you can consule the manpage for magicrecipe to see a short tutorial on how to do so.

magicrescue -r jpeg-jfif -r jpeg-exif -d ~/recovered-photos /dev/sdf1

This will scan for jpeg-jfif and jpeg-exif files on /dev/sdf1 (the partition on /dev/sdf) and save them in ~/recovered-photos. The ~ character denotes the home directory of the user executing the command. If you run this as root the files will be saved in root's home directory. If you run this as bob they will be saved in bob's home directory and so on.