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.

Rss Recent comments

Rcomment-before 13 Nov 2004 01:02 Rcomment-trans helli72 Rcomment-after

different sizes of a partition
for cloning an 1:1 partition, I don't really need partimage. dd and gzip are my best friends.

But what if my PCs does have different HD sizes? Can it fill or downsize partitions?

An simple example:

Source(s):

10gb (2gb full) partition

Destinations:

1 PC with a 10gb harddisc

1 PC with a 4gb harddisc

1 PC with a 8gb harddisc

1 PC with a 20gb harddisc

If I understand how partimage works, than only the 1st PC can be restored nativly or I have had the last PC (20gb) with 10gb free space, because partimage do not fill the last 10gb of his harddisc and I have 2 PCs (4/8gb) where I can't restore because the harddiscs are to small.

If I really understand partimage I can't do for example this situation:

source 10gb:

3gb partition1 (1gb full) (30%)

7gb partition2 (1gb full) (70%)

destinations:

20gb harddisc:

30% (6gb) filled with partition 1

70% (14gb) filled with partition 2

5gb harddisc:

30% (1.5gb) filled with partition 1

70% (3.5gb) filled with partition 2

So I think, partimage is (now) a bit useless in a company where exist different PCs with different harddiscs

If I'm at home, then it's ok (but than I can use dd with gzip and a nfs mount or ftp)

Rcomment-before 13 Nov 2004 09:30 Rcomment-trans mmaki Rcomment-after

Start with a small partition
The solution to the small partition issue is to create your master image on a small partition. I support several hundred Windows 2K and XP boxes and have had very few problems with partimage. I created a master syspreped image with all of our standard apps and configurations on a 5GB partition. Now if a new image ever needs to be installed I know it will fit. After the install I use QTParted to resize the partition to desired size. If I have problems with the boot partition I use the partimage boot image restore option.

Rcomment-before 13 Nov 2004 10:13 Rcomment-trans esokullu Rcomment-after

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?

Rcomment-before 13 Nov 2004 12:56 Rcomment-trans hendersj Rcomment-after

Great article
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?

Rcomment-before 13 Nov 2004 14:40 Rcomment-trans job Rcomment-after

Not tar?
Why would you want to use partimage instead of

regular tar or cp (or dd if you really can't have

kernel support for the file system used)?

tar -czf /mnt/hd1/image.tgz /mnt/hd2

is normally like something I would use for a full

system backup (plus the partition table and mount

points, of course). You can throw in a -S for good

measure too.

(I would normally prefer star to GNU tar,

as it creates archives in a more standardized

format and handles ACLs and EAs correctly. I often

end up involving my friends nc or SSH too.)

Rcomment-before 13 Nov 2004 16:08 Rcomment-trans marb Rcomment-after

imaNgine
About a year ago, while I was working with a small foundation we hit a problem with the disk cloning that was used from start: bpbatch (free, but closed source bpbatch (http://www.bpbatch.org)). Workstations were mostly Win98 machines (probably best suited for educational software) connected to a server. The cloning program ran in a PXE environment.

As development of bpbatch had stopped problems appeared with newer workstations.

To solve those problems, I created a network bootable diskimage running Linux, added a bash script which could create a master image on the server or retrieve it to be cloned on a machine similar to the master (remember the workstations were MS Windows based).

The script also repartioned the disk, formatted at least one partition, made it bootable, and did some registry tricks. Preliminary support for WinXP on FAT32 was also available, except for the registry tricks.

On the server a dhcp daemon should be running, as well as NFS.

Two versions have been made: one being able to boot from a PXE NIC (using pxelinux), the other needed a floppy containing an EtherBoot ROM image.

User intervention was possible, and some feedback was given using a dialog interface. Because dialog was too difficult to handle for our interns, I also created a graphical interface using nano-X and TinyWidgets which used the same syntax as curses-dialog.

All this is available under the GPL:

schoolLAN-imaNgine-5.2.0-1.i386.rpm
containing everything you need. Source for TinyWidgets, which had some modifications, and the new dialog will take some time beacuse of an unfortunate hard disk crash. At least most of the source survived in a backup.

For those of you able to read Dutch, have a look at Stichting SchoolLan (http://www.stichting.schoollan.nl) to read more about the foundation.

Rcomment-before 13 Nov 2004 17:19 Rcomment-trans hippomachus Rcomment-after

Re: Great article
Search for a project called Frisbee.

Rcomment-before 13 Nov 2004 19:49 Rcomment-trans bconway Rcomment-after

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.

Rcomment-before 14 Nov 2004 06:04 Rcomment-trans taternuts Rcomment-after

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

Rcomment-before 17 Nov 2004 06:49 Rcomment-trans ronfox Rcomment-after

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?

Rcomment-before 29 Nov 2004 06:13 Rcomment-trans naren_rulz Rcomment-after

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

created using &quot;mkswap&quot;

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

Rcomment-before 08 Dec 2004 00:56 Rcomment-trans naren_rulz Rcomment-after

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

Rcomment-before 02 Sep 2005 05:54 Rcomment-trans bender647 Rcomment-after

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.

No-screenshot

Project Spotlight

libkarma

A C library for managing the Rio Karma.

C4aaaa1ddd0211216b5faa959858183c_thumb

Project Spotlight

Kuklomenos

An abstract shoot-em-up