Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

10.4: Recover a dead hard drive using GNU ddrescue UNIX
Tiger only hintI had a problem with my disks (an original Maxtor from a dual G5). It had three HFS Plus journaled partitions. Suddenly, the system would not boot. When looking at the disk with Apple's Disk Utility, the disk is visible, the name of the volume is not displayed (/dev/disk0s5 was displyed instead), and the volume would not mount. Using Apple's Disk Utility repair function failed to fix the drive.

I tried using DiskWarrior, but it was really slow -- the message was saying something like "speed inhibted by disk malfunction." It was so slow, I was not sure if it had crashed, or if it would take weeks to get through. So I decided to look what other tools were available, I looked on macosxhints, and found this article about using dd to make a block copy of a volume (e.g. /dev/disk0s5). Then, looking aroung on the net, I found a Linux tool called GNU ddrescue made by Antonio Diaz Diaz (not to be confused with dd_rescue written by Kurt Garloff, which was mentionned in one of the comments of the original article).

I tried to compile ddrescue on Panther and it did not work. I then tried to compile it on Tiger, and it worked the first time (great to see Linux tools compiling on OS X without causing a headache). To compile, open the Terminal and cd to the ddrescue directory, and then run the following commands:
$ ./configure
$ make
Then you can run ddrescue (once compiled, it would probably also run on 10.3).

The syntax for ddrescue is quite simple and here are the steps I followed:

Copy the content of the volume into an image file:
sudo ./ddrescue -v /dev/disk0s5 MyVolImage.dmg MyVolRescue.log
The were errors reported during the copy of few blocks. ddrescue retried several times until I considered that there was no hope to recover these dead blocks (initially there were read errors on about 3000 blocks, and at the end, it turned out that 900 blocks had died). The computer really slows down (everything freezes) during that kind of operation.

I was monitoring the action by looking at the log ddrescue produces, and using this command:
$ sudo fs_usage | grep ddrescue
A cool feature of ddrescue is that you can stop and resume its activity. It will use the log file to pick up where it stoped last. Then I tried to mount the image file, but it did not work. I don't know why not; maybe because it was an HFS Plus journaled partition.

So I got a new disk (to be sure there were not bad blocks and to keep the original disk intact, just in case) and created a partition with pdisk of the exact same size (number of blocks) of the original partition (and the image file, remember a block is usually 512 bytes). Then I used ddrescue to copy the image file back onto the new partition:
$ sudo ./ddrescue -v MyVolImage.dmg /dev/disk1s3 MyVolRestore.log
I was then able to run DiskWarrior to repair the remaining problems (faster this time because there were no bad blocks) on that new partition. After that, I was able mount the volume and get my most important files back.
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[72,598 views]  

10.4: Recover a dead hard drive using GNU ddrescue | 23 comments | Create New Account
Click here to return to the '10.4: Recover a dead hard drive using GNU ddrescue' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: lewsmind on Thu, Jul 28 2005 at 10:38AM PDT
That is a pretty impressive solution. Nice job. I'll have to file this away, just in case.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: trollll on Thu, Jul 28 2005 at 3:24PM PDT
okay, need to try this...

stupid maxtor drive (replacement for the other one that died) lost a partition with some very important files almost two years ago. haven't touched it since then other than to give another rescue method a shot.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: khedron on Thu, Jul 28 2005 at 3:39PM PDT
The amount of time diskwarrior takes can definitely vary widely: although it often takes only a few seconds to run, I've heard of it taking as long as three days on a damaged hard drive... and successfully restoring a system that had been unable to start up before.

On the other hand, I once tried to run it on a damaged hard drive, and after about a day, it finally finished, and when it tried to overwrite the old directory data with the rebuilt data, gave me a message saying that there was a write error, and diskwarrior had just unintentionally destroyed ALL directory data, and that while some files were accessible at that moment, the next time I restarted everything would be gone. Oops.

At this point, I ran a Norton program... Norton Volume Recover, I think it's called. It can rebuild the directory from scratch by scanning the entire hard drive for bits of files. I wasn't expecting it to help at all, as I haven't been impressed with Norton recently, but it miraculously managed to restore virtually every file on the hard drive, succeeding where every other program I tried had failed. (I had not been running Filesaver, or whatever it's called, which collects data to aid Volume Recover in case of an emergency.)

So that's a tool that's now a permanent part of my collection.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: mathias01 on Fri, Jul 29 2005 at 11:34AM PDT
DiskWarrior has an often overlooked preview option. If you have rebuilt a drive you suspect of having problems, click on the "Preview" button in the lower left hand corner, and DiskWarrior will mount a read-only version of the drive. This drive shows up to other disk utilities as a real drive, and I've had very good luck imaging from this preview drive using utilities like carbon copy cloner. I do agree that it is rather impolite of DiskWarrior to dump the rebuilt directory with no warning if it encounters a problem during the replacement.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: johnsawyercjs on Tue, Sep 6 2005 at 7:49PM PDT
The publisher of Diskwarrior, Alsoft, claims that Diskwarrior's directory replacement process won't wipe the old directory until it's successfully written the replacement directory (unless there isn't enough free space for the replacement directory, in which case Diskwarrior will write over the old directory, which can be unsafe if there's a power outage, a crash, etc.), but sometimes, especially on drives that have bad blocks, this guarantee doesn't hold up. Whenever you see Diskwarrior report "Speed inhibited by disk malfunction", it means the drive has bad blocks, and you shouldn't let Diskwarrior try to replace the directory--as mathias01 says, use Diskwarrior's Preview option to Finder-mount the results of Diskwarrior's scan, and copy your files from that preview volume to a backup drive.

The commercial utility "Data Rescue", from ProSoft, will do essentially what Bruno's hint describes, with a convenient GUI--it will scan the whole hard drive for files, and if it encounters a bad block, it will spend a reasonable amount of time retrying to read the block, and eventually will give up and go on with the rest of the drive. It doesn't spend too much time trying to read a bad block, but if the drive has a lot of bad blocks, it can still take many hours or even a full day (or longer). If the command line utils described in this hint let you change the amount of time spent retrying bad blocks, that would sometimes be very useful, since usually a bad block can't be read no matter how many times the utility tries, but as Bruno describes in his hint, sometimes letting the util keep trying is a good thing, since his drive had around 3000 problematic blocks, but only 900 had completely died--the utility may have been able to get data from some of the problematic blocks because it kept trying to read them.

The feature of ddrescue that lets you stop its scan, and resume it later using the log file it generates, sounds pretty handy--I don't think Data Rescue has that feature, and I know Diskwarrior doesn't.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: mproud on Thu, Jul 28 2005 at 4:59PM PDT
Isn't the standard procedure

./configure
make
make install

?



[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: vykor on Thu, Jul 28 2005 at 6:37PM PDT
Make install would just put a copy of the binary in /usr/local/bin (if you didn't configure it with some other prefix). You could do that, or you could just run it out of the build directory if you don't want to install the binary into the official binary directory, for whatever reason. This particular piece of software ought to work either way.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: DuallyG5 on Mon, Sep 5 2005 at 10:24AM PDT
I can't seem to get it compiled
./configure says

VPATH = .
prefix = /usr/local
datadir = $(prefix)/share
infodir = $(datadir)/info
mandir = $(datadir)/man
OK. Now you can run make.

so now what ? any ideas ???

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: derrickbass on Fri, Jul 29 2005 at 3:52AM PDT
I'm a little confused by exactly why the disk image is being used. If you already have a blank disk you are going to use for a rescue volume, you can just use ddrescue straight onto that disk and then use Disk Warrior to fix any damage.

I should also point out that if you don't have a rescue volume, you can use Disk Warrior (or pretty much any other disk repair program) to repair an image directly. If the image won't mount, go to the the command line and type
[code]
hdiutil attach -nomount image.dmg
[/code]
Then launch DiskWarrior. If the disk image is not too badly damaged it should see it and be able to repair it.


[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: Gregory on Wed, Aug 10 2005 at 11:41AM PDT
my situation: one firewire disk enclosure, two drives.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: jklos on Sun, Jul 31 2005 at 3:06PM PDT
That's cool that it works, but although nitpicky, this isn't a "Linux" tool. Linux is a kernel. Most of the rest of what people call Linux (ie, the rest of the OS besides the kernel) is GNU. This tool is GNU. Linux has nothing to do with it.

[ Reply to This | # ]
recover more blocks using 'raw' devices
Authored by: krishna on Sun, Jan 8 2006 at 10:45PM PST
I just finished recovering (under a linux box I set up to be dedicated for the recovery operation) a fat32 partition that was giving me errors on what appeared to be multiple blocks. Then I followed 'info ddrescue' 's information on setting up a raw device and retrying the recovery, it came down to a single 512-byte sector (!) that was bad and producing multiple block errors.

So if I can find which file that block belongs to, I have my whole partition back. While ddrescue's not a linux-specific tool, that valuable 'raw' information in the documentation is definitely linux-specific; so I wouldn't say I wouldn't say ddrescue has *nothing* to do with Linux, since it definitely seems to be the chosen platform for testing. Of course, information on raw devices under macosx would be awesome to have.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: Applesmurf on Tue, Jul 11 2006 at 4:31AM PDT
Yes.
Install Xcode tools from the Tiger cd or the developer tools. You need a compiler to do this and gcc is installed with Xcode.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: bcreane on Sat, Oct 7 2006 at 8:48PM PDT
Once you create a copy of your drive using ddrescue, you can use testdisk and/or photorec to search the disk for recoverable files. Check out: http://www.cgsecurity.org/wiki for more info.

[ Reply to This | # ]
***Beware deletion of data***
Authored by: TC!! on Thu, Nov 2 2006 at 3:18PM PST
Hopefully this is just something I did wrong, but I ended up wiping another hard drive on my machine.

I had one disk fail on and old headless B&W g3, it contains 2 disks, 20GB which has the system on it and an 80GB drive for data which died. Diskwarrior qwouldn't even see the volum and in disk utility it was shown as disk1s10.

I attached a firewrie drive with one empty 80GB partition and used ssh to remotely log into the machine. I had already copied ddrescue into my home folder on the drive. So I tried this command first:
sudo ./ddrescue -v /dev/disk1s10 /Volumes/Video/Biggy.dmg Biggy.dmg

Video is the name of the empty firewire disk and Biggy was the hard disk which failed. After running that it seemed to start and then paused. It then quit with an error message telling me it couldn't write the log file. A quick ls showed me the directory I was in was empty. I tried to access the drive remotely and could see directories disapearing as I moved around folders. In the end I was left with just the system files.

I tried again, this time saving the log file onto the firweire disk. It seemed to go a little further and then I lost alll contact with the machine, it had crashed completely. This may have been due to the missing files or the system files where deleted as well.

Im not going to be able to check until I can get a monitor to boot the machine adn try using disk warrior to repair the system disk. I'll try a recover tool to get the files I've lost off the system disk. I think I'll have to do that first and then reinstall the system.

If anyone can see what I did wrong then please let me know, if not then please beware this application in case it caused the deletion. I think I'll completely give up on two drives in a rev 1 B7W G3.


[ Reply to This | # ]
To mount or not to mount?
Authored by: Andrman on Sun, Feb 18 2007 at 8:27PM PST
I am currently running ddrescue on my PowerBook's former internal drive per this hint. It's finally gotten to the error-ridden area and I'm looking forward to seeing what I can recover.

Reading the INFO that came with ddrescue, I found this:

"IMPORTANT! Never try to rescue a r/w mounted partition. The resulting copy may be useless."

My old drive is connected through a USB-ATA adapter and is mounted on the desktop. Should I have not mounted it? I did not see this specified anywhere in the hint or comments - I hope I haven't wated my time (and the integrity my drive has left).

I manually stopped the process when it was about 80% through and tried to mount and got a "not recognized" error. I'm not sure if this was because the image was incomplete or because I didn't do it right.

If so - what is a good way to connect the drive to the computer without mounting it? Command-line or UI instructions would be fine... I'm not very experienced in any of these UNIX practices.

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: paulhagstrom on Sat, Jul 21 2007 at 3:09PM PDT
Just wanted to add a note here: This also works well with floppies. I finally decided to image all of my floppies and then throw the floppies away, given that most of the media is over a decade old. It went pretty well using Disk Utility's disk image creation, but where a disk had a bad sector on it, DU refused to do anything with it. This ddrescue program did a nice job of preparing me to use DiskWarrior to repair. I still have only DiskWarrior 3.03, on a PPC machine, and there are some issues with the preview mode, but I've found that if Classic is running, DW seems to work. Who knows why, maybe it's just superstition, but I don't think it is entirely. Anyway, I did the following, in the terminal:
  • Insert the disk
  • df
  • Locate the floppy drive, say /dev/disk6
  • If the floppy mounted, unmount it by:
    diskutil unmount disk6
  • Run ddrescue:
    ddrescue -v /dev/disk6 ddr_sda159.dmg sda159.log
  • Eject the disk:
    diskutil eject disk6
Then, mount the resulting image (ddr_sda159.dmg in this example, double-clicking on it will do the trick), switch over to DiskWarrior, rebuild, preview. Switch over to Disk Utility, select the rebuilt volume (with the DW icon), convert the image. Back to DiskWarrior to cancel, and then finally unmount the original image. It worked quite nicely for those disks that had only a tiny amount of damage. I haven't had any that actually didn't mount at all, so parts of this procedure may need to be tweaked for that scenario. Specifically, the part where I mounted the disk image that ddrescue produced might not work in that case, and it would probably require using hdiutil attach -nomount to get it to be visible to DW, something like this, though I haven't had a need to try it:
hdiutil attach ddr_sda159.dmg -nomount


[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: paulhagstrom on Sat, Jul 21 2007 at 3:17PM PDT
Let me just add one thing: The reason I didn't use DW on the floppy directly is because it flipped out in various ways, spontaneously unmounting things causing the Finder to complain about unorthodox device removal. I did try that first. What I like about this recipe is that it gets as much off the disk as the drive is capable of and then I can play around with whatever recovery tools I want on the image.

One thing that I am not confident of is that DW will detect if there was an error in the middle of a file's data, my guess is that it won't. So, it's still probably necessary to treat the recovered files as being only possibly working.

[ Reply to This | # ]
Compiled version of ddrescue for 10.4
Authored by: aangel on Thu, Oct 25 2007 at 1:37PM PDT
To save someone (maybe you) the hassle of compiling ddrescue, I have posted a compiled version here.

It's against 10.4.10. I have not tested it against 10.5 as I don't have a copy yet.

The command I used was: sudo ddrescue -v /dev/disk2s3 /Volumes/TerraLinda/SaveMaxtor.dmg savemaxtor.log

But you will need to run diskutil list to get the correct label for your device (it's not likely to be disk2s3).

It's currently recovered 16GB and counting...

[ Reply to This | # ]

Compiled version of ddrescue for 10.4
Authored by: atonaldenim on Thu, Jan 14 2010 at 3:12PM PST
Thank you very much for continuing to host this ddrescue binary for Tiger (you probably have forgotten all about it by now). I'm trying to recover a drive with many bad blocks, which seems like it will take days, and the only machine around that's not being used is running Tiger. No development tools installed to compile my own binary, but yours works perfectly. Thanks!

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: jammjamm on Thu, Nov 1 2007 at 11:28PM PDT
Has anyone got this working on PPC Leopard?

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: arbee on Fri, Jan 30 2009 at 3:07AM PST
Your article has created a glimpse of hope. I have problem booting from the hard drive so I boot from the Mac OS X 10.4 DVD. Disk utility cannot fix the disk. How to run ddrescue on it if it does not boot. Thanks for any help and advice.
One last thing, am not too command line savvy. any additional help will be appreciated

[ Reply to This | # ]
10.4: Recover a dead hard drive using GNU ddrescue
Authored by: JLG on Mon, Apr 27 2009 at 2:41PM PDT
An easy way to get ddrescue installed is to install Mac Ports (http://www.macports.org). You can then open a terminal window, type "sudo port install ddrescue", and the port will install. Once that's done, you can type "sudo ddrescue" to run the program, or "sudo man ddrescue" for instructions.

[ Reply to This | # ]