SUSE Conversations


Clone or Backup your Hard Disk



By: mendesdomnic

February 16, 2010 10:00 am

Reads:3752

Comments:1

Rating:5.0

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

Note:
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
VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Clone or Backup your Hard Disk, 5.0 out of 5 based on 1 rating

Tags:
Categories: Enterprise Linux, openSUSE, SUSE Linux Enterprise Desktop, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

1 Comment

  1. By:mikewillis

    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


    root=/dev/disk/by-id/ata-HDS728040PLA320_PFDG00S1U772-part1

    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.

Comment

RSS