- Introduction
- Making a byte-by-byte copy
- Making a file-system copy with tar and ssh
- Making a file-system copy with tar and netcat
- Making a file-system copy with rsync
- Using multiple partitions
- Installing a Boot Loader
- Automating the creation of the file systems
- Things to watch
- Comments
- External Links
Introduction
This document describes how to install Linux in a given machine by making an exact copy over the network of an already setup machine. Through this techniques you might be able to replicate installations very fast.
There are three options. The first involves making a byte-by-byte copy of the disk in the source machine. This is slow and requires identical disks in the local and remote machine. The second, using tar to make a file-system level copy, tends to be much faster but requires a little more intervention (creating the filesystems). The third, using rsync to make the copy, is very similar to the second but might be faster if the machine already has some version of Linux installed in the partition where you want to make your copy.
To sum things up, you should:
- Make a byte-by-byte copy if you have plenty of time (and can waste a lot of bandwidth) and don't want to create the filesystems manually.
- Use the tar method if your target machine doesn't have Linux installed.
- Use the rsync method if your target machine has some (probably older) version of Linux installed that you want to overwrite.
The following sections require you to first boot your Live CD in the target machine and configure the network.
You might want to see our system administration tips page.
Making a file-system copy with tar and ssh
Create the file systems in the target machine. Mount the partition where you want to leave the root of your filesystem, cd into it and run the following command:
ssh -C USER@SOURCE tar -c --exclude /proc --exclude /sys / | tar -x
You'll also need mkdir proc sys and install a boot loader (see below).
Making a file-system copy with tar and netcat
WARNING: under testing.
If you're in a trusted network you can also use netcat. It's faster than ssh.
In the destination machine (and directory) run:
nc -l -p 2000 -q 1 | tar -x
In the source machine, do:
tar -c --exclude /proc --exclude /sys / | nc DESTINATION 2000
Making a file-system copy with rsync
This option is very similar to the former, but might be a lot faster when the target machine already has some version of Linux installed that you want to override.
Mount the partition where you want to leave the root of your filesystem (which should contain some version of Linux installed; otherwise you would be using the former method), cd into it and run the following command:
rsync -a --exclude=/proc --exclude=/sys USER@TARGET:/ .
You'll also need mkdir proc sys and install a boot loader (see below).
Installing a Boot Loader
In order for your machine to boot, you'll need to install a boot loader.
If you are using GRUB, make sure that boot/grub/menu.lst in your target machine is correct (you might have to change it if the partitions where /boot is mounted in the source and target machines differ) and then run grub-install –no-floppy /dev/hda (again, replacing hda with the name of your disk).
If you're using LILO, check etc/lilo.conf and, after that, run lilo -r ..
Automating the creation of the file systems
If you are setting many mirrors of a given machine (which happens very often when you are into giving Linux courses), you can accelerate the process by having a script create the filesystems in all your target machines.
Q: If you can figure out any way to do this, please document it here.
Well,
This doesn't directly address your question but helps. I had to install a diskless system in a cluster, and I was kinda scared because they were 50+ nodes. But I found an easy way to do it. I installed dhcp. Once I booted Knoppix I would do:
wget 10.0.0.1/install.sh ./install.sh
And that was all.
(I was installing Etherboot on a system with existing partitions from an old installation)
---------- install.sh ------------- cd / fsck /dev/sda1 && \ mount /dev/sda1 /boot && \ grub-install --no-floppy /dev/sda && \ cd boot && \ wget http://10.0.0.1/GRUPO1/eepro100.zlilo && \ ln -s eepro100.zlilo eb && \ cd grub && \ wget http://10.0.0.1/menu.lst && \ cd / && \ umount /boot && echo "Done?" -----------------------------------
---------- menu.lst --------------- timeout=0 default=0 title=Etherboot kernel=(hd0,0)/eb ---------- ------------------------
I don't know if there's an easier way to do it, but for similar tasks I've successed using 'expect', which can help you interact with a program from a script. I think it woudln't be too hard to make a three-step installation using expect (boot, wget server/install.sh; chmod +x install.sh; ./install.sh; reboot). With expect you can "talk to" fdisk, and use it within a script. It seems there's an example here with a Perl module. I used expect directly and it's quite nice to know there's a Perl module. (I don't know if there is another non-interactive way to create partitions – I would use expect). Here's a related article.
I've heard of FAI (Fully Automatic Installation) but I've never used it. Sounds good.
-- NEC.
Things to watch
There are some problems with setting up identical copies of a given machine.
The first thing to watch is that on certain distributions (such as SUSE) files are created with MAC addresses in their path. In this case, you might have to fix things manually.
Also, regardless of the distribution, it should be evident that you will need to use DHCP to assign network addresses to your machine or fix the configuration in the target to use a different address.
Last update: 2007-05-05 (Rev 11240)