Because you have to boot a different OS in order to clone the one on the hard drive, I downloaded System Rescue CD. The only problem with it was that it does not boot with SATA hard drives. There is a known bug listed in the project bug list. If you need to clone SATA hard drives, you can use an installation of Linux with partimage on a separate HDD.
Experienced Linux users might point out that there is also the venerable dd command, which makes a bit-by-bit copy of the given partition. The drawback of dd is that the images created are much larger than ones created with partimage, because partimage saves only used portions of the drive.
I would like to use the following example to show how to clone a Linux installation to a different computer. First, I have to note that the new computer where you will put a copy of the drive image needs to have a motherboard with the same architecture as the original one. Otherwise, Linux will not boot.
Now, let's start. I have a computer with Fedora Core 2 Linux installed on an IDE drive with the following partitions:
/dev/hda1 /boot /dev/hda2 / /dev/hda3 swap /dev/hda4 /home
I would like to create images of these partitions and use them to make an exact duplicate on a drive of the same size in another computer.
I connect another HDD as a secondary master, where I will put hard drive
images of the first disk, and boot using System Rescue CD. During
booting, it asks for a keyboard to use, then offers the
prompt. First, we need to mount a partition on the secondary master
# mount /dev/hdc4 /mnt/temp1
Under temp1, we can make a directory to store our images.
# mkdir /mnt/temp1/fedora_core2_template # cd /mnt/temp1/fedora_core2_template
Now, it's time to save the Master Boot Record and Partition Table information of the /dev/hda drive.
# dd if=/dev/hda of=fedora_core2_template.hda.mbr count=1 bs=512
I use the .mbr extension just to show that this is a Master Boot Record.
# sfdisk -d /dev/hda > fedora_core2_template.hda.pt
.pt is for Partition Table.
Now, we're ready to run partimage to save the contents of the /dev/hda1, /dev/hda2, and /dev/hda4 partitions. We do not need to image the swap partition, as it can be created after applying the partition table information to a new drive.
To save a partition, I use the following command:
# partimage -b -z1 -o -V700 save /dev/hda1 fedora_core2.hda1.partimg.gz
This will create a compressed file of the first partition and, if it is larger than 700 MB, split it into multiple 700 MB files which end with 000, 001, ..., ###. 700 Mb is just enough to put one file on a CD, if you ever want to backup your installation. After executing the above command, I type a description of the image and hit F5 to continue.
I will not explain each flag I use in a command, since you can view them
partimage --help. The reason I am not using the
graphical interface is that you may get confused by the choice of which
partition to back up, as partimage does not use /dev/hda# in describing
Repeat the above command for the /dev/hda2 and /dev/hda4 partitions, and a copy of the first hard drive is done.
# partimage -b -z1 -o -V700 save /dev/hda2 fedora_core2.hda2.partimg.gz # partimage -b -z1 -o -V700 save /dev/hda4 fedora_core2.hda4.partimg.gz
The new computer can have an HDD of the same size or larger. Images we
made in the first part of the tutorial cannot be applied to a smaller
HDD than the one we made a copy from. Connect an HDD with images as a
secondary master and boot with System Rescue CD. When you get to the
# prompt, mount the partition on the second drive.
# mount /dev/hdc4 /mnt/temp1 # cd /mnt/temp1/fedora_core2_template
Now, we can restore the master boot record on the new drive.
# dd if=fedora_core2_template.hda.mbr of=/dev/hda
Before we can run partimage, we also need to apply partition table information to the new drive.
# sfdisk /dev/hda < fedora_core2_template.hda.pt
Now, everything is ready for partimage. Use the following command to restore the image to the new drive:
# partimage -e restore /dev/hda1 fedora_core2.hda1.partimg.gz.000
After you hit enter, partimage will display information about the image. You can verify that this is the right image for this partition and click F5 to continue. After it's done, repeat the above command for the remaining partitions:
# partimage -e restore /dev/hda2 fedora_core2.hda2.partimg.gz.000 # partimage -e restore /dev/hda4 fedora_core2.hda4.partimg.gz.000
Now, all that's left is to make swap on the /dev/hda3 partition.
# mkswap /dev/hda3
This will create a default swap structure and will use the whole /dev/hda3 partition for it. Restoration of the installation is complete. We can shut down and disconnect the second HDD.
I had one case in which the GRUB loader would not load after restoration. If this happens to you, get a Fedora Core 2 Installation CD and boot into Linux rescue. After that, you can use chroot to switch to the installation on the HDD and restore grub by running grub-install /dev/hda. This will fix the boot loader, and Linux should load nicely after that.
This process can be used for Windows installations, as well. If you would like to look at other ways to do it for Windows systems, there is a very nice tutorial on cloning Windows XP installations using Norton Ghost, HDClone, and Ranish Partition Manager.
I hope you enjoyed reading how I cloned a Linux installation. Please drop me a note if you have a comment or suggestion, or would like to add something new.