Clone or Backup your Hard Disk


Sometimes you may want to clone your entire hard disk quickly. You may need an exact replica of your hard disk.

This can be done using the following command as root user:

dd if=/dev/sda of=/dev/sdb

if=/dev/sda is the source hard disk
of=/dev/sdb is the destination hard disk

Wasn’t that quick enough :). Do be careful in not mixing the source and destination disk above.

To make an image of your hard disk in case you don’t have a second hard disk use the command below:

dd if=/dev/sda of=~/disk1.img

To restore above image file run command:

dd if=disk1.img of=/dev/sda
(Visited 1 times, 1 visits today)


  • mikewillis says:

    Cloning a disk using dd is something I’ve heard about but never actually tried. Seeing this article inspired me to actually try it.

    Whilst everything in the article is correct, it is missing some important details. Also the command you cite whilst quick to type, doesn’t really seem to be be a way to “…clone your entire hard disk quickly” as it takes ~40 minutes to do a 40GB disk. (So by extension that would presumably be ~160 minutes for a 160GB disk which is nearly three hours!)

    The operation can be speeded up by specifying a block size. For example, using this command

    $ dd if=/dev/sda of=/dev/sdb bs=1024k

    to clone a 40GB disk was over about three times faster as it took only ~14 minutes.

    If I use dd to clone a harddisk containing a SLED 11 install, then boot from the second harddisk, the boot process stops part way through. This is because /boot/grub/menu.list references the partitions using the by-id method. I.E. the grub entry contains something like


    so during boot it spends a while looking for that and then when it can’t find it a message appears saying it can’t be found and asking

    "Want me to fall back to /dev/sda1? (Y/n)"

    Answer Y and the system continues to boot an all is well. To prevent this happening during boot it is necessary to edit /boot/grub/menu.list and change the partition references to use the /dev/sd method of referencing.

    root=/dev/sda1 resume=/dev/sda3

    It is also worth pointing out that if you clone on to a larger disk then not all the space on the larger disk will be used. E.g. I clone a 40GB disk on to a 120GB disk. When booted from the 120GB disk I could of course I could only see 40GB of usable space. If you want to make use of all the space the partitions need to be resized.
    For example, the last partition on my disk was /dev/sda4 which was 15GB. It was 15GB because that was as large as it could be on the 40GB disk. On the 120GB disk it could be larger. To make it larger, without loosing any data I did

    $ umount /dev/sda4

    Use fdisk to delete the partition, then recreate a new one which uses all available space on the disk.
    Reboot so new partition table is used.

    $ umount /dev/sda4
    $ e2fsck /dev/sda4
    $ resize2fs /dev/sda4
    $ mount -a

    Whilst my cloning attempts were successful, I’ve read that it’s best not to use dd in this way whilst the machine is booted from /dev/sda. Rather you should boot the machine from a Live CD and then use dd. This seems sensible advice as it would seem to avoid the possibility of dd reading part of the disk as data there is being altered.

  • gluten3 says:

    I have cloned a disk with SLED 11 and ran into the disk/by-id
    roadblock. Unfortunately, changing the grub config file to use sda1 instead does not solve the stalemate. The vmlinuz and initrd are apparently found, but then it can’t mount partitions,
    as they are still referenced by model and serial number somewhere else!
    Brilliant, Novell! I doubt I will purchase your product again.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *