Thursday, December 11, 2008

Recovering files off corrupted disks

Not too long ago, I returned from a weekend trip with over 350 digital photos. I have no idea what went wrong, but after trying to import them, my photo application informed me that it failed to import 367 photos. Something went wrong with my card all of a sudden.

Looking at the directory indicated that the file system (directory structure and file information) was mangled. The camera failed to read the card either.


Now if your storage media, be it a hard disk or a flash card or a pen drive - anything that holds files, has not failed physically, you still have a chance of recovering your data. Physical failure would be when the media fails to be read or recognized entirely, sometimes accompanied by weird sounds in the case of hard disks. This wasn't the case for me. The problem was simply data corruption.

Data corruption may be localized to a few regions of the disk. When it scrambles certain important areas like the directory structure, you media may be apparently rendered useless because the system cannot find the file names and contents properly. This doesn't mean that the files themselves have been wiped out. The data from the files is most likely sitting there. All we need is a program to pick out data block by block and piece it together.

The best software I've seen for this job is PhotoRec from Christophe Grenier. PhotoRec works on all platforms - Windows, Linux, Mac OS X and a few more. PhotoRec isn't limited to recovering just photograps. It can recognize and recover dozens of different types of files, including ZIP archives, office documents and much more.

PhotoRec uses file carving techniques to reconstruct data by looking at blocks directly, bypassing the media's directory structure entirely. And PhotoRec has a very high rate of success! The only drawback of PhotoRec is that it is a text based program, without a fancy graphical user interface. However, the fact that PhotoRec is free more than makes up for this drawback.

The following screenshots show you how I recovered 366 out of 367 photographs from my date with disaster. Click on each screenshot to get a detailed view.

Step 1: Choose your disk. Here, I have selected my 2GB Compact Flash card:


Step 2: Tell PhotoRec how the media was partitioned. In most cases, it will be either an Intel/PC partition, or None.


Step 3: PhotoRec will now try and show you various volumes contained in the partition. I usually select the whole disk. You may get a few extra files left over from previous usage, but no harm in recovering them and deleting them later if not needed.


Step 4: Tell PhotoRec how the media was formatted. Again, in most cases, it will be "Other", for FAT and NTFS file systems.


Step 5: Select the directory you want for storing the recovered files. PhotoRec will create a "recup" folder within that directory for storing all the files it can recover.


Now sit back and keep an eye on the number of files recovered! Hopefully you'll get all your data back.


At the end of the process, here's how my recup folder looked like, with almost all my photos recovered.


The one lost photo is a reminder of how I almost suffered a huge data disaster, but was luckily able to recover from it!

Another tutorial on using PhotoRec is available here.

No comments: