What follows is a short tale about how to recover digital photos from a broken hard disk under Linux.

When I returned from a short vacation this week, one of the hard disks reported read errors for the Reiser filesystem superblock. And while I had multiple backups of all valueable data, my digital photos were only stored on this hard disk.

To add insult to injury, I noticed that I had deliberately switched off a SMART warning some months ago: for the "offline uncorrectable sector count". I had ignored this early warning sign because further SMART offline tests returned a count of zero.

After running badblocks for a while, it looked like only two small areas at the start of the disk were damaged.

Not wanting to take any more risks, I bought another 160GB hard disk, and copied the whole disk:

dd if=/dev/hdb of=/dev/hdc bs=512 count=65536 conv=noerror,sync
dd if=/dev/hdb of=/dev/hdc bs=4096 skip=8192 conv=noerror,sync

The conv parameters ensure that read errors on /dev/hdb are ignored, and that any data missing due to these errors is replaced with null bytes. Because I hoped that there were no errors after the first 32 MB, I used a larger block size for the second run, to speed up dd.

While all blocks after the first 32 MB were indeed readable, the disk grew hot, and only delivered 2.5 MB per second. This gave me 18 hours to plan the next steps.

First, I ran reiserfsck. The superblock was gone, so I had to use the --rebuild-sb parameter. Didn't help much, so --rebuild-tree was next. After that, I saw some familiar directories and filenames, but looking at the content of those files did not turn up a single of my photos.

So, do what special agents do, and use some forensic tool for evidence recovery. Reading the list from the Knoppix Security Tools Distribution, I first tried foremost, but found that it was unusable for 2.5 MB digital photos, because its memory consumption grew exponentially with the size of searched files. The next tool was photorec, a tool specifically written "to recover pictures from digital camera memory".

As with all filesystem-agnostic tools, it cannot deal with fragmented files, but it recovered almost 90% of my photos. Its usage is pretty simple, as it has a text-based UI. The recovered files are stored in a directory named recup_dir, which is created in the current working directory.

The only problem I had with photorec was that it sometimes did not find the end marker for a file type before it had copied a few hundred MB. And it seems that it looks for that start marker in areas which it already has copied to a file, because I ended up with more data than I could store.

Telling photorec to only scan a specific area of a disk is not possible, but one can use fdisk for that. Changing the partition table of an unmounted disk which you don't plan to write to does not erase any data, except for the old partition table. So I created a couple of partitions, ran photorec on one of them, sorted out the good data, and moved on to the next partition.

Now, I have two hard disks connected to two different IDE channels, housed in fan-cooled aluminium docking bays. I use software RAID level 1 to mirror my data, and I have set up multiple smaller partitions with LVM so I don't ever have to shift through the whole disk when a few thousand bytes disappear. And of course I have included my photos in my backup process.

Setting up RAID and LVM and copying an existing Fedora Core 3 installation to the new disks was pretty easy. The only tricky part was that I use LVM for the root partition (not recommended). To make this work you just have to create a new initial RAM disk with mkinitrd, as the RAM disks from the kernel RPMs do not contain the necessary LVM stuff.

Update 20 Jan 2005: The initial RAM disk is not part of the kernel RPM, but is created when you install the kernel on your machine. So if /etc/fstab already points to an LVM root partition during a kernel upgrade, there is no need to created a custom RAM disk.

21:51, 09 Jan 2005 by Carsten Clasohm Permalink | Comments (0)

RSS

Archive

January 2005
S M T W T F S
           
9  10  11  12  13  14  15 
16  17  18  19  20  21  22 
23  24  25  26  27  28  29 
30  31           
September 2008
July 2008
June 2007
May 2007
March 2007
January 2007
December 2006
September 2006
June 2006
April 2006
March 2006
February 2006
January 2006
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
January 2005
December 2004
November 2004
October 2004

Blog Categories

Hiking (5)
Desktop Linux (28)
Server Linux (5)
Palm (3)
Photography (5)
Politics (2)
Web Applications (15)

Notifications

Request notifications

Syndication Feed

RSS

Recent Comments

  1. Anonymous Visitor: Security issue
  2. Anonymous Visitor: Thanks
  3. Anonymous Visitor: AT&T U.S.
  4. Anonymous Visitor: All went well under CentOS 5.0 in Croatia (VIP network)
  5. Anonymous Visitor: tmp crypt not necessary
  6. Anonymous Visitor: Great article
  7. Anonymous Visitor: So it's not a Virus...
  8. Anonymous Visitor: Thanks! Helps also on Windows!
  9. Anonymous Visitor: Thank you
  10. Anonymous Visitor: Economic Incentives