Recover a dead hard drive using dd 



Fri, Mar 4 '05 at 07:56AM • from: Anonymous

The Unix program dd is a disk copying util that you can use at the command line in order to make a disk image. It makes a bit-by-bit copy of the drive it's copying, caring nothing about filesystem type, files, or anything else. It's a great way to workaround the need for Norton Ghost.

Normally, in order to make a disk image, the disk you're copying from has to be able to spin up and talk -- in other words, it's OK to make a copy if the disk is healthy. But what happens when your disk is becoming a doorstop? As long as it continues to spin, even with physical damage on the drive, dd and Mac OS X will get you out of the fire.

We had a situation recently where a friend sent a disk to us that had hard physical errors on it. It would boot in Windows, but then it would hit one of these scratch marks and just die. We fired up dd, and it started OK, but stopped at the same physical error location -- complaining about a Hard Error.

So the workaround was to designate the dd mode as noerror -- which just slides over the hard stops, and to add the mode sync, which fills the image with nulls at that point. We did it on BSD Unix, but as long as you can get the hard drive attached to your Mac, the command is the same:
dd bs=512 if=/dev/rXX# of=/some_dir/foo.dmg conv=noerror,sync
The bs=512 designates block size, and the if=/dev/rXX# is the UNIX path to the actual disk device. Make sure that the chosen directory (some_dir) has enough room to take the entire disk image -- which will be equal to the size of the drive. Since dd doesn't care about the contents of the drive, it copies every bit on the thing, so you get an image equal to the disk's capacity. A really big file. One workaround is to put it on a RAID array.

Once you've established the disk image (in this example, foo.dmg), you're almost home. Here's where your Mac OS X box is far and away the best thing to have. In this example, the dd output file is foo.dmg. You have to realize that this is an exact copy of a busted drive, but the "holes" are filled with nulls. As long as the damage isn't to the boot sector, though, when you double-click on it, Mac OS X mounts it without breathing hard ... who cares if it's FAT32, NTFS, whatever.

Due to the size of the image that we were copying, we put it on a RAID array, and had to access the image over the network -- it still mounted fine. In straight UNIX, if you try to mount a disk image, it complains that there is "no block device" and fails. Once your image is mounted, it appears in your Finder, and then it's easy work to retrieve the critical files from the image -- usually things like .doc files and .xls files and the lot.

Finally, since your disk is actually dying, once you have your image, you can drop it to tape or something and you've not only recovered your files, you've made a viable backup as well. Once again, that which destroys a Windows box becomes a play thing to a Mac OS X box.
______________________________________________



... Email hint • Print hint  
 


 

Recover a dead hard drive using dd
24 comments | Create New Account



The following comments are owned by whoever posted them. macosxhints is not responsible for what they say



Recover a dead hard drive using dd

Authored by: daybrother on Fri, Mar 4 '05 at 10:26AM

This is the best hint I have ever seen. Thank you.

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: signal15 on Fri, Mar 4 '05 at 10:55AM

I have been using this method for awhile, however, I stopped using the sync option. They sync option made it so I would have files that were totally unusable. Without the sync option, I end up with everything readable. Does dd try to re-read the data until it gets it if you don't use sync? That's what it seems like.

Without the sync option, the dd copy takes WAY longer, so I assume it keeps going over the same spot until it gets your data.

I lost 2 drives on my powerbook in the last 4 months, and dd saved my azz. :)

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: melo on Fri, Mar 4 '05 at 11:10AM

Much better: check out dd_rescue and it's frontend dd_rhelp.

I recently had hard drive problems and with those two utilities I could restore most of my hard-drive (lost 12kbytes).

dd_rescue: http://www.garloff.de/kurt/linux/ddrescue/
dd_rhelp: http://www.kalysto.org/utilities/dd_rhelp/index.en.html
my rescue day: http://www.simplicidade.org/notes/archives/2005/02/recover_day.html

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: dgchichester on Fri, Mar 4 '05 at 12:19PM

Regarding:

The bs=512 designates block size, and the if=/dev/rXX# is the UNIX path to the actual disk device.

How would you determine the UNIX path to the disk device?

I have an old desktop drive that got hammered during the transition from System 9 to 10 some time back, and I've always held on to it in hopes of finding a way to "get at it." I can hook it up to a firewire case and plug it into my functioning system that way, but what would be the UNIX route for such a connection?

Thanks in advance.

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: electricferret on Fri, Mar 4 '05 at 01:03PM

In OS X you can use the "disktool" command to find out what disks you have connected. Try
disktool -l
to get started. I don't know how you would do this on other Unixes - it varies by system, as does the disk naming convention.

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: peragrin on Fri, Mar 4 '05 at 01:07PM

I can't tell you the exact location of the unmounted drive. The easiest way is to hook it up to the enclosure and try to let OS X mount it. If it fails, You can use Diskutil to determine the /dev location of the drive.

There Is a commandline version of diskutil as well. just type man diskutil, into either the command line or google. If you are trying to figure out how to use a commandline tool and don't like man pages, you can use google to pull up html versions.

Just remember this creates one file the size of the formatted drive. so if it was 20gigs you have about a 20 gig file.

I never did a system 9 to OS X transition. I do know both used the same file system. So you have a good chance at getting data.

---
I thought once I was found but it was only a dream

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: electricferret on Fri, Mar 4 '05 at 01:13PM

This is a great hint and I'm preparing to rescue a failed PowerBook drive like this, but how do you get the drive connected to a Mac in the first place? I've put my dead drive in an external USB enclosure, but when I plug it into the Mac, OS X insists on trying to mount the drive. Since the disk seems to have errors in the volume definition areas, this fails and eventually the drive just spins without reading. OS X never mounts it and I can't do anything with it.

I tried the same on an old Linux box, but when reading the errored parts of the disk, the USB ports froze and Linux now refuses to recognize a drive there at all (short of powering down).

Is there anyway to prevent OS X from mounting a drive when you connect it?


[ Reply to This ]

Disk Utility

Authored by: lullabud on Fri, Mar 4 '05 at 01:48PM

When you open Disk Utility it gives you a list of physical disks attached to the computer and their related partitions. If you click on the physical disk and hit "Info" it will show you the "Disk Identifier", such as disk0, disk1, and so on The number increments as you attach more physical disks to the system. If you click on a partition you'll see that you get a Disk Identifier of disk0s3, disk0s4, or so on up with the second number. I don't know why it starts at 3, but it does, and it goes on up from there. (I just partitioned a disk into 6 partitions to check this.)

So, to apply this practically, you would plug in the disk that is corrupted and check its identifier in Disk Utility. If DU can read the partition table it will assign the "s#" to it, even if it can't mount it. You can then go into terminal and put this in place in the dd command listed in the hint.

[ Reply to This ]

Actually...

Authored by: lullabud on Fri, Mar 4 '05 at 01:56PM

The partitions seem to go up in odd numbers, and the disks aren't always consecutive. I have 4 disks attached right now and they are 0, 1, 3, 4. At any rate, the way to find the information is right.

[ Reply to This ]

Save Space with Gzip

Authored by: lullabud on Fri, Mar 4 '05 at 02:00PM

If you're limited on local space you can use a pipe to gzip instead of the "of=" option.
dd bs=512 if=/dev/rdisk2s3 conv=noerror,sync | gzip -9 > foo.dmg.gz

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: simonpie on Fri, Mar 4 '05 at 08:53PM

I so agree !!!

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: Zeitkind on Sat, Mar 5 '05 at 10:09PM

You can mount most images on newer unix-systems if they support loopback-devices. Just google for lofi and lofiadm.

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: burro on Sun, Mar 6 '05 at 12:01AM

disktool lists them as

..
**Disk Appeared ('disk1s1',Mountpoint = '', fsType = '', volName = '')
..

the suggested command has a format

rXX#

Which one is it?
------------------------
PS. UNIX such a nice idea so sloppily implemented.

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: burro on Sun, Mar 6 '05 at 12:11AM

disktool lists them as

..
**Disk Appeared ('disk1s1',Mountpoint = '', fsType = '', volName = '')
..

the suggested command has a format

rXX#

Which one is it?
------------------------
PS. UNIX such a nice idea so sloppily implemented.

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: burro on Sun, Mar 6 '05 at 12:44AM

I put mine in FW enclosure. It never mounts. Depending on the phase of the moon, the fire wire bridge chip will reported it as a unformatted drive or will refuse to work with the disk at all. In the latter there is no way you can use this scheme in ext. enclosures at least. Put it back in the original machine, boot it up from external and try again.

OS X will see the disk, mounted or not. Issue

disktool -l


With my failed FW enclosed drive hooked up I got two new entries

***Disk Appeared ('disk1',Mountpoint = '', fsType = '', volName = '')
***Disk Appeared ('disk0',Mountpoint = '', fsType = '', volName = '')

(for ref here is my bootup system disk mounted,
***Disk Appeared ('disk0s9',Mountpoint = '/', fsType = 'hfs', volName = 'System')

To decide which one is it (don't you hate UNIX for its unbelievable sloppiness?) go to Disk Utility, select your disk and using contextual menu (right mouse click) get Information. In my case FW enclosure was disk1.

Issue
dd bs=512 if=/dev/disk1 conv=noerror,sync | gzip -9 > foo.dmg.gz
to read that disk in. You should see some activity on that drive. Reading may take forever as internal disk microcode will try to read every failed block numerous times.

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: obiwan2u on Mon, Mar 7 '05 at 01:30AM

dgchichester asked:
How would you determine the UNIX path to the disk device?

The df command seems to list this info (see the left hand column, first row of data):
Filesystem 512-blocks Used Avail Capacity Mounted on
/dev/disk0s5 120093120 108689400 10891720 91% /
devfs 193 193 0 100% /dev

But I'm not sure if this is the right device name. When I try and copy from it using dd, I get a "device busy" error.

Do I have to boot from a CDROM to make a disk image copy of my normal boot disk?

PublicMailbox at benslade dot.com


---
Put 030516 in the email subj to get mail thru to me.

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: electricferret on Mon, Mar 7 '05 at 01:03PM

It depends on what OS you're trying to read the disk in, really. (See your sig for details. :))

On OS X, you use what disktool reports, but put a "/dev/" in front of it. FWIW, I found that I had to read the whole disk to get it to work, not just a single partition. YMMV. The full disk is the "diskX" name, and the individual partitions on it are the "diskXsY" names. All together, this means on OS X you're going to get a device path like:
/dev/diskX
The "rXX" device name is for the author's BSD system. On a Linux system, you'll get names like "hdaX". (And Sun and HP and every other system have yet other naming conventions.)

[ Reply to This ]

How long will it take?!

Authored by: masthugget on Mon, Mar 7 '05 at 03:27PM

And with "forever" you mean?

I started a dd-session to make a disk image of my 60GB drive in my iBook and it has so far only copied 110MB in 85 minutes. At this speed it will take some 30 days to complete!

Can this be right?

[ Reply to This ]

How long will it take?!

Authored by: masthugget on Mon, Mar 7 '05 at 03:35PM

I started a dd-session to make a disk image of my 60GB drive in my iBook and it has so far only copied 110MB in 85 minutes. At this speed it will take some 30 days to complete!

Can this be right?

[ Reply to This ]

How long will it take?!

Authored by: electricferret on Mon, Mar 7 '05 at 04:41PM

Depending on the number and severity of errors on your disk, absolutely. 30 days might even be optimistic. In reality portions of your disk are probably still good and will read very quickly, but the errors slow the whole process down.

You might want to read the man page for dd, especially the "skip" and "count" options. Instead of reading the whole disk in one pass, you can read parts of the disk into several files and cat them together later. Of course this means you need twice the disk space of the original to reassemble the rescued image in.


[ Reply to This ]

How long will it take?! / Done, but it won't mount!

Authored by: masthugget on Tue, Mar 8 '05 at 01:14PM

Just as you said, it was only certain parts of the drive that took that long, the rest went much quicker. It's ready now.

But now to another, more severe?, problem. I cant mount the .dmg file! When I try I get an error message saying that it can't connect to the filesystem (translation from swedish).

Any ideas?



[ Reply to This ]

rdisk0 or disk0?

Authored by: masthugget on Tue, Mar 8 '05 at 01:37PM

I can see people are both talking about rdisknn and disknn as identifier for the faulty disk. In the disk utility it says (for me) disk0, but under /dev/ I find both rdisk0 and disk0. What's the difference, which one should be used?

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: aerodr on Thu, Mar 24 '05 at 01:46PM

I've tried this hint both with and without the sync option as suggested by the orginal poster and signal15 on a corrupted drive that contains Redhat 7.0 and Windows 2000 partitions. The resulting .dmg files are the expected size, but when I try to mount the images, a window pops up stating that the image failed to mount because there were "no mountable file systems".

If I run hexdump -C on the .dmg files, I can see some of the filenames on the corrupted disk, so I think the image has the data I want, but mount isn't working.

Anyone have any ideas?

[ Reply to This ]

Recover a dead hard drive using dd

Authored by: verypuzzed on Thu, Mar 31 '05 at 12:14PM

Similar problem here, I have a drive that contained BeOS and FAT32 partitions, and I "DMG"ed it using OS X.3 Disk Utilities by creating an image from the device. My intention was to get a carbon copy of my drive in order to restore it later, but the Disk Utilities will not accept to restore it (even though the image is being restored to the hard drive it was first taken from). The DMG format (created by Disk Utilities) is probably not a byte-for-byte dump of the drive (i've tried "dd"ing it back) and there dos not seem to be any utilities out there that can reproduce the raw image of my drive out of the DMG file.

If anyone has any ideas on how to proceed, I'm (desperately) open for suggestions! 

Posted: Tue - September 13, 2005 at 09:06 PM        


©