Articles / Computer Cloning with Parti…

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

Conclusion

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.

Recent comments

02 Sep 2005 05:54 Avatar bender647

Re: different sizes of a partition


> for cloning an 1:1 partition, I don't

> really need partimage. dd and gzip are

> my best friends.

%

partimage has an advantage over dd+gzip in

that it only copies and compresses used disk

blocks. with dd+gzip, you usual fill the unused

area of the disk with zeros to make the

compression higher. this step is unnecessary

with partimage it doesn't waste time copying

those blocks to begin with. i find the resulting

partition images smaller.

the downside is that the images are locked into

one tool. dd+gzip images could be restored from

any *nix boot disk you can find. partimage images

require partimage to restore.

08 Dec 2004 00:56 Avatar naren_rulz

Re: great but..


> First of all thanx to the authors for

> this useful tutorial and software..

>

> My experience with that; if u didn't

> unmount the the partition that you will

> backup, partimage doesn't work without

> any notice. Because &quot;-b&quot;

> option is given so the program works in

> batch mode; u don't get the nice but

> confusing curses screen.. But u also

> don't see potential errors.

>

> That's why before working try:

>

> # umount /dev/hdaX

>

> Plus, my question is: what if the

> partition that we backup makes more than

> 700mb when compressed. Then, how to

> restore it with more than gz files?

Split the .gz in to two files each of size less than 700 Mb

using split command

and the

cat >> produces initial one........

Bye

29 Nov 2004 06:13 Avatar naren_rulz

Simple correction
we have to add &quot;swapon&quot; to use the swap file

created using &quot;mkswap&quot;

....................

17 Nov 2004 06:49 Avatar ronfox

Re: Great article
We use FAI (Fully Automated Install).

> One thing that I've been looking for

> information about (and hopefully someone

> can help me out here) is a means to send

> images out on a network using

> multicast.

>

> Currently, I use Norton Ghost for this,

> but I hate having to use a Windows

> system to image my Linux systems (I

> typically restore about 10-15 systems a

> week for a classroom setup). I've read

> over the partimage information and it

> seems the recommendation is to

> distribute the image file(s) to a

> partition on each hard drive and then

> use partimage to restore it. Thing is,

> I'm starting from a bare metal restore,

> and can't have any dependencies on the

> local drive having anything in

> particular on it. I also don't want to

> have to use a significant portion of the

> relatively small drive to hold an image

> file to be restored, but would rather

> see something like Norton's

> &quot;Ghostcast&quot; functionality.

>

> Are there any projects out there that

> can meet these requirements?

14 Nov 2004 06:04 Avatar taternuts

Re: I hate to advocate using the best tool for the job...


> But Norton Ghost 9 is all of $60 MSRP,

> and even the basic version includes

> support for storing images on a network

> share for cloning from an image. I use

> it for all my workstations at work, both

> Windows and Linux, and it includes all

> the dynamic resizing features you could

> want.

Erm...Have you read the EULA for Ghost ?

Specifically the part where it says :

"You may use the Software on one computer to clone, or apply an image of a hard drive on that computer, or to another hard drive on the same computer, a replacement computer, secondary media, or network drive..."

and

"You may not use the Software commercially or non-commercially for the purpose of creating multiple computers or hard drives, except for multiple hard drives installed in or attached directly to the original computer."

So while it may be only $60, that is for 1 computer...Unless you have no problem violating licensing agreements...I think most companies do, and since the original article was all about "When you have over a hundred computers to install..." I think it likely it was intended for an commercial/enterprise audience.

That being said, I do like Ghost. It works quite well...And if you're in an enterprise environment, the cost per machine of the Enterprise version is much less than $60/pc. But let's not confuse $60 with $60 x 100 as you seem to be doing...

Screenshot

Project Spotlight

Kigo Video Converter Ultimate for Mac

A tool for converting and editing videos.

Screenshot

Project Spotlight

Kid3

An efficient tagger for MP3, Ogg/Vorbis, and FLAC files.