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.

Advertisements

About jordilin

I'm a Senior Software Engineer with an MSc in Telecommunications Engineering. I've got a range of interests including Linux, a very powerful and limitless operating system, travelling, gastronomy and technology.
This entry was posted in HOWTOs, Linux. Bookmark the permalink.

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. Pingback: Savadeep Speaks! » dd: a tool most old, but of the utmost use.

  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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s