Thursday, August 25, 2011

Clone a failing Windows hard disk with ddrescue on Ubuntu Rescue Remix

Scenario: The hard disk is starting to throw "bad block" errors. Windows still works/boots, but who knows for how much longer. And you don't want to have to go through the time and expense of rescuing the data from the failing disk, installing Windows and all your applications on a new hard disk, and re-loading the data on the new hard disk.

Solution: You want to use a free Linux tool called Gnu ddrescue to clone the failing drive to the replacement drive.  This is one of the tools available on the Ubuntu Rescue Remix.  For more info on this tool, start here: http://www.gnu.org/s/ddrescue/ddrescue.html

If you Google ddrescue, you'll find lots of info on how to use ddrescue to recover data.  However, there's not a lot on how to move a Windows load from a failing drive to a new drive.  For example, one mistake that I've made is imaging the failing drive instead of cloning it.  The image file is not easily restored and bootable on the new drive. 

Here's what you need to do.  Idiots beware, this is not an idiot-proof guide.  Important but obvious steps are omitted.  Feel free to embellish or enumerate such steps in your comments.
  1. Download Ubuntu Rescue Remix here: http://ubuntu-rescue-remix.org/Download and burn it to a CD.
  2. Get a hard disk to replace the failing drive that is the same size or larger.
  3. Connect the new disk to the machine with the failing disk.  A fast connection (eSATA) is better than a slow connection (USB).
  4. Boot the machine to the Ubuntu Rescue Remix CD.  This will get you to a command-line prompt; there is no GUI.
  5. At the command prompt, key in the command:
     .  This command will identify the disks as /dev/sda and /dev/sdb (or perhaps /dev/hda and /dev/hdb, or perhaps you have more than 2 drives connected, ...).  This command will list the size and make of each drive, which should allow you to determine which drive designation is the source/failing drive and which is the target/replacement drive. You need to know this without ambiguity; it is easier if the target is larger than the source.  
  6. For the sake of example, let's assume that the source drive designation is determined to be /dev/sda and the target drive designation is /dev/sdb.  Your situation may be different.  To clone the source drive, at the command prompt, key in the command:

    That's it.  Depending on the size of the source drive and the number of bad blocks, it will take time to clone the drive.
  7. When ddrescue is done, swap out the target disk for the source disk in the PC, and fire it up.  It should boot and work as well as the source disk, but without the looming prospect of imminent disk failure.
  8. If you have used a larger target disk to clone the source, you may want to expand the partition to use the whole, larger disk.  GParted will do the trick.  Unfortuantely, this tool is not on the Ubuntu Rescue Remix CD.  Parted is, but it will not resize NTFS partitions.  You can find GParted on the Ubuntu live CD.  You can download it here:  http://www.ubuntu.com/download/ubuntu/download.  Instructions for using GParted to resize a disk are here: http://gparted.sourceforge.net/larry/resize/resizing.htm.

17 comments:

John Redmond said...

Some advice on the web says to format the target disk with a native linux file system (e.g., ext3). Usually this advice is provided in connection with cloning a linux source disk or capturing an image of the source disk. In my experience, cloning a Windows disk, you want the target to be brand new or formated with NTFS.

John Redmond said...

For further info.. http://www.gnu.org/s/ddrescue/manual/ddrescue_manual.html

kattyjohn012 said...

Hard drive failure is a surprisingly common problem, and one that can put your data at great risk. But retrieving that data is often not as difficult as the situation may seem. Contacting a professional data recovery engineer for a free consultation is a good start.

data and recovery

JMX said...

trying to add the -not so obvious- preliminary requirements.
1) does the destination drive got to be formated under linux format?
i got the message "output file exists and is not a regular file" - is there anyway that this warning should not appear?

Chinoto Vokro said...

@John Redmond: If you are dding a partition onto another partition, it doesn't matter what the second partition was formatted as because the first partition will overwrite it (so copying a NTFS partition onto a Ext4 partition will result in an NTFS partition).

Ext3 is probably suggested because it works well with Linux and supports very large files (2TiB with 4KiB blocks). This makes it suitable for containing the entire contents of a partition in a single file, which can then be manually mounted and inspected.

Btw a neat trick to making a filesystem within a file is to use "fallocate -l 4GiB ./file", "mkfs.ext3 -F ./file", then make a folder to mount it with and use "mount -t ext3 ./file ./mount/"

Blueuniform said...

John, this is a very good tutorial. It is direct and to the point, which is how I wish others would write!
Keep up the good work, it is appreciated.

William said...

one thing missing is if you have to resume the operation if you have to exit. I tried using the same command I used to begin and it started from the beginning again. a waste of a week's worth of recovery. a critical piece of missing instruction, making for a poor tutorial.

David Hawkins said...

Thanks for the very nice informative post.John If we don't have linux then what we should do? Then how can we fix
hard drive problems?

Chinoto Vokro said...

@David Hawkins: If you had even bothered to read the post, you would know your comment makes no sense at all. Damn link spammers.

Dan said...

I keep having an issue with the log file not saving...

ddrescue: Error writing logfile: No space left on device.

I am running from a 4GB flash drive.

mve said...

Great summary of ddrescue!
I tried another clone software that failed to recover the failing HDD to a new SSD drive.
Then this solution worked great!

Just had to confirm previously unsuccessful attempt, because ddrescue complained " Output file exist and is not regular file." Suggestion was to add --force option.
#ddrescue --force -v -r 3 /dev/sdb /dev/sda logfile
Be extra cautious which drive is source and which target, you may overwrite your data if you do not pay attention using "--force" option!

stroyde said...

"The image file is not easily restored and bootable on the new drive"

Why?

Ddrescue is designed to do this write step.
Is not the saved image the literal bitwise copy of the device, in the usual case here containing at least a boot partition and a recovery partition?
Then I see a reminder from another source one will have to activate partitions using a running Win machine, not a big deal.

But I have yet to try it myself, so I'm curious about what problem you had with this.
You don't say a word about the log file, which appears to be an important matter in cases where there could be an interruption, or multiple passes are desired.

Formatting a storage destination drive for the image with ext3 cannot be a problem, and this also gives a place for the logfile to be stored by ddrescue.
In my case though, I would also use ubuntu remix from a bootable flash drive, so the logfile could reside there too.
So yes, again I'm curious about your cryptic rejection of the imaging approach.

Chinoto Vokro said...

@stroyde, I believe he is merely saying that after rescuing an image to another drive as a file inside a partition, it is difficult to make the image be the contents of the drive without a spare drive. It certainly is possible to shuffle data around and make it work, but it can be quite a chore. LVM with whatever free space you have split into several physical volumes and some pvmove/vgreduce magic could make this task easier.

Shailesh Mehta said...

Good solution for the boot disk failure issue. Most of the times it may be hard disk issue or sometimes even loose connection can cause boot disk failure problem. Keep writing more on other topics also.

Rajesh Kumar said...

Boot disk failure is a very common issue. Even shifting the cpu from one place to another place can also cause this problem. Restarting the cpu can also solve boot disk problem. Thanks for the wonderful blog on pc issues.

Arun Ramesh said...

Thanks for such a detail post on clearing system disk failure. It is not a critical issue and can be cleared easily. We do pc and Printer Service and blogs like these are very useful for out team.

Ravi Kumar said...

Good post with lots of details. Good to read and understand. Hard disk problems can cause booting problem. If there is loose connection then one should remove the wire and plug it back into the hard disk again and it might solve the problem and you do not have to go to computer service center.