Disk cloning basics using dd in Linux
January 6, 2012 4:45 PM Subscribe
Backing up a possibly-about-to-die hard drive and putting it on a new drive, using dd in Linux - a few questions regarding how the cloning works.
So the drive in my wife's PC (250gb SATA, Windows Vista) looks like it might be dying - making some weird noises. So I'm in the process of imaging it, and putting the image on a new drive. I am using the "dd" tool on a Linux live CD to do this. I just want to make sure I'm doing it right.
1) I copied the drive image to a file on a portable USB drive, using:
dd if=/dev/sda of=/media/PortableDrive/my.backup
It worked - no errors. It did take almost 3 days to copy the 250gb, though.
Now I have a new drive, plugged it in, and tried the reverse process:
dd if=/media/PortableDrive/my.backup of=/dev/sda
It dies within seconds, telling me there's an Input/Output error at 17mb into the disk. Does this mean that errors on the original hard drive were copied onto the image I made on the portable drive?
So, next thing I tried was plugging the old drive back in, and doing a direct copy from one to the other.
dd if=/dev/sdb of=/dev/sda
I got the same problem - IO error at 17mb into the disk.
Next thing I tried - direct copy using the dd_recover tool, which tries harder to read bad sectors. It didn't balk at the error at 17mb (although it noticed it), but the transfer rate was stupidly slow - about 3mb/s, so I gave up on that.
Alright, so now I'm using dd_recover to copy from the image on my portable drive to my new internal drive. It is going beautifully - much faster, no errors showing up. Can I assume that the bad sectors on my old internal drive will contain messed up data on my new drive? and, most of all, Am I doing this correctly at all?
It just seems strange to me that dd copied data from my old drive to my portable without an error (just slowly), but gave an error when I tried to copy from my portable to my new drive.
posted by Jimbob to computers & internet (10 answers total) 8 users marked this as a favorite
No; dd will stop as soon as it detects an I/O error, so if you managed to make an image using dd and the image is the same size as your original device, the original device contained no unreadable sectors.
My initial suspicion would have been that there's an unreadable block on your backup disk 17MB from the start of your backup image. However, given that you got the same problem when doing a direct copy from the original disk, the only plausible explanation is that there was an unaddressable block on the destination disk at 17MB.
Can I assume that the bad sectors on my old internal drive will contain messed up data on my new drive?
I don't believe your old internal drive had any unreadable sectors, so no.
Am I doing this correctly at all?
Mostly, though the tools you're using aren't the tools I'd use.
The most likely reason why dd took three days to copy a 250GB drive is that you didn't give it a bs= option (I generally use bs=1M) which means it was doing all reads and writes in chunks of its default block size, 512 bytes. This is sloooooooow.
The tool I'd use for this is Gnu ddrescue, which you will find on the Trinity Rescue Kit live CD.
To clone the disk at /dev/sdb onto the one at /dev/sda with maximal chance of error recovery, you'd use Before doing this, make sure /dev/sdb really is your source disk - ddrescue will happily copy a blank drive over the top of your data if you ask it to.
Gnu ddrescue does data transfer in large chunks to start with, coming back to re-examine the areas around unreadable blocks in smaller chunks only when the main copy pass has finished, so it's decently quick. It also has good progress and error reporting, and if you give it a log file as I've done in the example above, you can interrupt it with Ctrl-C and then resume just by re-issuing the original command. Good tool.
Given that 17MB error, I'd be inclined to check the new drive once your existing dd_recover copy session has finished, using and make sure it progresses past 17MB before Ctrl-C-ing it.
posted by flabdablet at 5:45 PM on January 6, 2012 [6 favorites]