Cover V09, Ixx
Listing 1
Listing 2
Listing 3


Using Linux to Duplicate Computers

Mark Nielson

The main purpose of this article is to demonstrate the use of Linux and Perl, and the replication of Linux computers on a mass scale with minimal hardware requirements. The secondary purpose is to gather people in the community to help develop a tool for companies, universities, and individuals to easily replicate computers. It's important to be able to replicate computers with free software for the following reasons: you don't have to bother buying upgrades every once in a while; you can empower yourself to install computers rather than relying on an overpaid computer consultant; it reduces downtime and increases turnover of bad hardware; and you get to see what the software is doing, which will help you modify it for your particular needs. A primitive tool called MILAS is located at for public use. One way of replicating Linux installations will be shown, although it is not the only way. Following are the basic steps and requirements:


1. Red Hat Linux (You can use any Linux distribution, but I use mkbootdisk in the article).

2. Perl programming language with the Expect, IO-Stty, and IO-Tty modules installed. (Perl will not be used in the first example below, but it will be used later.)

3. A PC computer with hard-drive-removable kits and Linux installed. (The computer used for this article had a SCSI hard drive and 4 IDE hard-drive-removable kits. It was an AMD K6-2 400 with 64 megs of ram. The SCSI hard drive had a pre-installed Linux distribution.)

Basic Steps

1. Use the Perl Expect module (or other programs) to partition the hard drives.

2. Use the UNIX program mkfs to format Linux partitions.

3. Use the UNIX program mount to mount partitions to their temporary locations.

4. Use UNIX utility programs called tar or rsync to copy over a Linux installation.

5. Shut down the computer, take out the hard drives, and put the hard drives into the new computers.

6. Boot off of a Linux-bootable floppy disk and run the command lilo. This installs LILO to make the new computers bootable from the hard drive.

Example A

Use a basic UNIX shell script to duplicate a hard drive. The commands below can be stored in a file and executed as needed. The first step is to make a master copy of a Linux distribution. This is a brand new installation and not the one you use to boot the duplication computer.

1. Install Linux onto a master drive using one of the removable IDE drives. You can do this on a spare computer. Install Linux onto a Linux partition at /dev/hda1 and with a swap partition at /dev/hda2. After you finish installing Linux on the spare computer, reboot the computer, put a blank floppy disk in, and type mkbootdisk 'uname -r'. This will create a bootable disk for later use.

2. Take the master drive out of the spare computer and put it into a hard-drive-removable kit and put it into the duplication computer.

3. Turn on the duplication computer and mount the master IDE drive (step 4a below).

4. Copy the master installation from the master IDE drive to the SCSI drive in the duplication computer.

a. Here are the steps to copy to /MASTER on your computer:

mkdir -p /MASTER
mkdir -p /MASTER_TEMP
mount /dev/hda1 /MASTER_TEMP
tar -C /MASTER_TEMP -cp . | tar -C /MASTER -xvp
b. Shut down the computer with the command halt.

c. Take out the master hard drive.

Now you have copied a master image of your Linux distribution to /MASTER on the duplication computer. The next step is to manually copy this to a new hard drive:

1. Insert a fresh new hard drive into the duplication computer and make it the master hard drive on the primary IDE controller.

2. Turn on the computer.

3. After you log in as root, type fdisk /dev/hda.

4. Next, recalculate the cylinders and heads for the hard drive. Type p and record the number of cylinders, heads, and sectors. Multiply these three numbers. For example, if H=15, C=8912, and S=63, multiply, 15*8912*63=8,421,840. Set the heads to 255. The new cylinders will be 8,421,840/ 63 / 255 = 524.

  • Type “x” for expert mode.
  • Type “h” press enter, and then type “255” and press enter.
  • Type “s” press enter, and then type “63” and press enter.
  • Type “c” press enter, and then type “524” and press enter.
  • Type “r” to return to the previous menu.
  • Type “w” to quit the program. Now script the rest of the installation. In later examples, this step will be taken care of with a Perl Expect script.

5. Now copy the master image of Linux to the copy. Create a file called Partition_It.bat with the following commands:

6. This script will make a Linux partition at /dev/hda2 that will be 20 cylinders, and will change it to a swap partition. It will then create a Linux partition at /dev/hda1 that will consume the rest of the diskspace. To direct these commands to fdisk, type fdisk /dev/hda << Partition_It.bat and press Enter. This will partition your hard drive. If you always have hard drives with at least have 524 cylinders, this script doesn't have to change.

7. Now execute these commands:

   mkdir -p /COPY
   mkfs -t ext2 /dev/hda1            ## format the Linux partition
   mkswap -c /dev/hda2               ## format the swap partition
   mount /dev/hda1 /COPY
   tar -C /MASTER -cp . | tar -C /COPY -xvp  ## Copy over the stuff
   umount /COPY
   halt                              ## Shutdown the computer
8. You have copied one Linux hard-drive to another. Put the new hard drive into another computer, boot off of the floppy disk you made earlier, log in as root, type lilo and press Enter, and you are done.

Example B

Well, that was a pain. Most of the first example can be scripted, except when you have to deal with the cylinders of the hard drive. The remainder of this article will explain how to use other tools to eliminate the manual labor, and to discuss user-friendly interfaces.

Tasks to Eliminate

1. Delete all current partitions. (This requires Perl Expect.)

2. Auto-calculate the new cylinder number and change the hard drive stats. (This requires sfdisk and Perl Expect.)

3. Create a Perl script to let people change variables, like using /dev/hdb, having more than one partition for Linux, etc.

4. Format the new partitions and install the software.

The goal is to create a user-friendly menu, which is beyond scope of this article. I will cover Task 1 and Task 2. For Tasks 3 and 4, any reasonable programmer can create a menu to make a user-friendly interface. For example, there is a Perl script called “MILAS” for “MILAS Installs Linux And Stuff”. It is a script that has been used at The Computer Underground for a year. It has been cleaned up for readability and is available for general public use.

Listing 1 deletes all partitions on hard drive /dev/hda. Listing 2 calculates the cylinders, heads, and sectors for the hard drive on /dev/hda. From Listing 2, assume $Cylinders is defined. This will change the cylinders on the hard drive (Listing 3).

Example C

MILAS is not limited to installing Linux on computers. By using dd and gzip, TCU managed to burn images of Windows 98 and NT in dual boot mode with Linux. Many people want to use operating systems other than Linux. MILAS can make it easy to replicate any operating system in less time than it would take to build a new computer using cheap hardware and Linux. Examples of how to manually copy Windows 98 installed on /dev/hda1 and burn it to /dev/hdb1 are:

dd if=/dev/hda1 | gzip > /tmp/Windows98.img

gunzip -d /tmp/Windows98.img | dd of=/dev/hdb1
To boot Windows 98 off of the hard drive after you put it in a new computer, remember to boot off of a bootable Windows 98 disk that has the file on it and and then type the command sys c:.

Things To Do:

1. Create a Web implementation.

2. Look at programs to replace Perl Expect for partitioning hard drives. Possibilities include Red Hat's Disk Druid, some new tools from Mandrake, and sfdisk. I haven't found a program that gives me the full power of fdisk, so I still use Perl Expect.

3. Create installation floppy disks that will use SMB, NFS, OpenSSH, or ftp with rsync or tar. This could take the place of other ghosting programs (which would be nice).

4. All of this will be reprogrammed in Python (someday).

5. Incorporate the ability to install rpms from scratch without using a Linux image. This will prevent you from having to use the installation programs provided by the Linux companies.

6. Instead of installing over the net, if your image is less than 600 megs compressed, install from a custom-made CD-ROM. If you have more than 600 megs compressed, just install the first 600 megs from a CD-ROM and connect to the net to finish the rest of the installation.

Comments and Other Notes

Three easy ways to install Linux:

1. Install from Red Hat (or other distributions) using a kickstart disk. If you install from the network and you put your own rpms on the network, you can install your own rpms on top of the distribution's rpms, and issue your own custom-made commands. This can be tedious for many post-installation changes. Kickstart disks can also make it easy to perform upgrades.

2. Use a duplication computer. I have learned that you can actually burn hard drives faster than people can build computers. This is the fastest and best method for new computer builds.

3. When it is developed, install from a custom-made CD-ROM or over the network using MILAS. This can replace commercial ghosting software. This is also a good option if you have a computer in the office that you don't want to move.

It is important to be able to replicate computers for free. This saves a lot of time and headaches when setting up new systems. Once a Web interface is developed, Linux can be installed easily. Many startup hardware companies will have virtually no software cost if they stick to Linux, StarOffice, MILAS, Perl, Python, PostgreSQL, Apache, and other free software to solve their office productivity needs. At TCU, MILAS also post-configures 100% of the Linux options so that the only post-installation step required is to boot from a Linux boot disk once. For Windows 98, you need to boot from a Windows 98 boot disk once, and configure the hardware. MILAS cannot configure the hardware for Windows 98, but it can save a lot of time by getting past the basic installation, which normally takes 30 to 40 minutes.

About the Author

Mark Nielsen is JALG working at ZING and The Computer Underground. His passion is to reduce the cost for startups so that they can compete with the big boys. Thanks to Rick Holbert from ZING for proofreading this article.