Computer Cloning with Partition Image

When you have over a hundred computers to install, you really start to scratch your head and think that it would be nice not to do the same installation a hundred times. When I faced this problem, I looked at computer cloning as a solution. I did not want to spend big bucks on commercial software like Norton Ghost. I know that some people might be skeptical about using Open Source software, but I gave partimage a try and found it to work very nicely.
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.

Case study

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.
Part 1: Make an HDD Image of the Installation

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 drive:


# 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 by running 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 partitions.

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

Part 2: Restore the Image to a New Drive on a Different Computer

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 <>

Comments

Popular Posts