How can I use DD to migrate data from an old drive to a new drive?

Normally I would suggest a solution such as "hook up the 2nd hard drive using an external enclosure, boot from a linux CD, then use a command such as dd if=/dev/sda of=/dev/sdb bs=1G, but since you want to use the same technique for work, I have what may be a better solution.

All of my servers and laptops get imaged at work using Clonezilla. There are two ways of using it...one of which uses a dedicated server and is probably overkill for you, and another which utilizes a boot CD and external hard drive.

The idea is that you boot in with the Clonezilla CD and have a largish (bigger than the source drive) external USB drive. Clonezilla walks you through making an image of the existing drive, after which you power down the machine, replace the drive, then boot back into Clonezilla, and it walks you through restoring the data.

This gives you the opportunity to A) put the image on a bigger drive, and B) retain a backup of the data.


Your first task would be to connect both disks to an existing Linux system or connect the new disk to the original system.

You must be very careful since it is very simple to copy the blank disk on top of the good disk!

To end up with the boot sectors and all, you would do something like:

dd if=/dev/hdx of=/dev/hdy

Where hdx is your 40G disk and hdy is your 160G disk. You will notice there are no partition numbers like /dev/hdx1. This copies the entire disk, partition info and all.

Your new disk will just like the old disk, 40G allocated. It should boot right up when placed back in your laptop. Hope you used LVM? Otherwise hope you did not use all the partitions? Getting past this point requires a lot more info.

Another solution is to dump each individual partition. This requires a lot more situation awareness since you will need to recreate the boot information.

All of this is best used for cloning computers, not upgrading hard disks. It is much better to restore to a new installation using your backups.


While you can use dd to copy a disk like that, doing so has a number of drawbacks:

  1. The destination must be exactly the same size or larger than the source
  2. After copying, you will need to resize the partitions to use any additional space
  3. You will waste time copying free space
  4. Any fragmentation present in the old disk is preserved

Using an imaging program like Ghost4Linux, partclone, or clonezilla at least takes care of numbers 2 and 3. You can also simply format the new disk, mount it, and copy all of the files over with cp -ax ( as root ), and then reinstall the boot loader on the new drive. This method does not suffer from any of the above drawbacks.