HOWTO: Cloning your hard disk

I’m gonna explain another method to backup your whole hard disk. We are going to make an exact clone of our hard disk. In this howto, we will use a very useful command: dd. If your hard disk is /dev/hda and you have a spare hard drive being external in /media/sda1 or internal, just type:

dd if=/dev/hda of=/media/sda1

Be careful, sda1 must be of the same or greater size than hda. If you want to make an image of the whole hard disk into an image file, just type

dd if=/dev/hda of=/media/sda1/image.img

Then, this .img file can be mounted as a loopback filesystem to see its contents.

To restore it, then proceed the other way round:

dd if=/media/sda1/image.img of=/dev/hda

When restoring, the best way is to boot from a live cd and restore the hard disk. There are lots of live cds out there, but I recommend using Knoppix.

9 Responses to “HOWTO: Cloning your hard disk”

  1. Hypercube Says:

    Well… Ubuntu is the same or may be better. You might also wanna play around with -bs option to dd to increase the block size. And make sure it’s a power of two. Usually I use -bs=8192 when cloning disks, it sure speed things up. If you don’t specify this IIRC the default value is 512.

  2. jordilin Says:

    Thanks for the tip. We can reach the I/O limit with bs. I have an external usb hard drive and the maximum writing speed is limited by the usb 2.0 bandwidth.

  3. gnuyoga Says:

    i would recommend partimage instead of full dd. The problem with dd is that the unused bytes also are copied ………… partimage does it intelligently ……… copy only those blocks which are used …….. rest are skipped ………

  4. Savadeep Speaks! » dd: a tool most old, but of the utmost use. Says:

    [...] It was of today that I was a reader of some tips known most ancient for users of Unix and Unixlike systems, but also of some use. My readers, I am of the know that some of you have been switchers to Ubuntu Linux and Kubuntu Linux after being most active readers of my blog. So happy I am that you have been making a decision most prime! And I am of the know that many of you are but likers of backups. That is but an idea rightfully made. Backups of our datas are something we must be doers of in these days of commodity hardwares. The article, it is but a writer about the usages of dd to be a maker of backups of hard drives. My writings, but they will be a teller of my lookings into the history of dd. [...]

  5. jordilin Says:

    gnuyoga,
    You are right. Partimage is more practical as it only copies the used blocks. dd copies “all” the hard drive. If the size is 40Gb, then it will copy 40Gb regardless of unused space.

  6. InYourService Says:

    Isn’t it possible to compress that image?

  7. Stin Says:

    Yes you can compress an image, but you dont get much compression out of it.
    I compressed a 40gig image to about 32gb, with gzip

  8. Rekaissa Says:

    Dear all,

    do you guys know how cloning hd from host to guest in VMware ?
    thanks 4 the advise

  9. Bill Says:

    Migrating a live machine to a VM can be done by VMware converter. It is free on VMware’s web site.

Leave a Reply