A more sensible method is to backup only the data on the active partitions of the drive, in compressed form, and in a format that allows it to be restored to any sufficiently large partitions on any sufficiently large drive. Fortunately this is very easy to do under Linux. Another bonus is that the backup can be restored to a different filesystem (ext3, xfs, jfs, reiser, etc).
My own strategy is to use the [RIP] Rescue Is Possible rescue disk to backup and restore drive partitions. The initial backup requires that the machine be booted using the RIP disk, but subsequent updates *can* be done live on a per-directory or per file basis.
The initial backup is done by rebooting using RIP, and backing up the data in the active partitions to an inactive partition, another drive, a dvd, or over the network. This will also protect you against possibly unknown links.
Note that the purpose of rebooting from the rescue cd is to avoid backing up the potentially very large virtual filesystem under /proc, and the dynamically created files in /dev and /tmp. You also avoid backing up NFS mounts this way.
Here is the strategy for backing up a computer with a boot partition (/dev/hda1) and one data partition (/dev/hda2) - backing up to a scratch partition (/dev/hda3):
Reboot the computer using the RIP rescue cd, and issue these commands:
cd /mnt
mkdir hda1 hda2 hda3
mount /dev/hda1 hda1
mount /dev/hda2 hda2
mount /dev/hda3 hda3
tar cvzf hda3/hda1.partition.tar.gz hda1
tar cvzf hda3/hda2.partition.tar.gz hda2
Remove the cd and reboot.
And that is it! You are backed up! Copy those files to cd's or dvd's, or external hard drive or whatever, and remember to record the machine name, type, and OS version.
Restoration is slightly more complicated
The computer is rebooted using the rescue cd, and if necessary fdisk is used to repartition the new drive, and new filesystems are created if necessary. Then:
cd /mnt
mkdir hda1 hda2 hda3
mount /dev/hda1 hda1
mount /dev/hda2 hda2
mount /dev/hda3 hda3 (or whatever the device with the backup on it is...)
rm -rf /mnt/hda1/*
rm -rf /mnt/hda2/*
tar xvzf hda3/hda1.partition.tar.gz -C /mnt
tar xvzf hda3/hda2.partition.tar.gz -C /mnt
mount /mnt/hda1 /mnt/hda3/boot (this is for a boot partition, remember?)
grub-install --root-directory=/mnt/hda3 (yes, this really works, from /mnt)
OR
lilo -b /dev/hda -r /mnt/hda3 (ditto, this works the same. both use chroot, q.v.)
If you are cloning multiple machines from a single set of partitions, there will be distro specific file edits required to set the network information:
That's it! Remove the cd, reboot, and you are DONE.
Download the RIP Recue CD ISO image from:
http://www.tux.org/pub/people/kent-robotti/looplinux/rip/
Mount the image using the loop device and copy the contents to a working directory (must be done as root):
mkdir rip-rescue
mount -o loop RIP-NN.N.grub.iso.bin rip-rescue
cp -r rip-recue my-rescue-disk
umount rip-rescue
rm -rf rip-rescue
The script my-rescue-disk/boot/mkiso.sh is used to create the new ISO image after adding your own files to the distro. Add appropriately named directories at the same level as the boot directory to hold whatever tools and partition images you want to have on the disk. Additional partitions can be stored on other cd's, dvd's, or external storage devices that can be mounted using RIP when you need them (after booting RIP, you can remove the RIP cd from the drive, all the useful bits are in memory).
#!/bin/sh
# The argument is only the numerical index of the node N="$1";
# here we are assuming /dev/hda1 is the boot partition # and /dev/hda3 is the root partition cd /mnt mkdir hda1 hda3 hdc mount /dev/hda1 hda1 mount /dev/hda3 hda3 mount /dev/hdc hdc rm -rf /mnt/hda1/* rm -rf /mnt/hda3/* tar xvzf hdc/hda1.partition.tar.gz -C /mnt tar xvzf hdc/hda3.partition.tar.gz -C /mnt mount /mnt/hda1 /mnt/hda3/boot grub-install --root-directory=/mnt/hda3
cat >/mnt/hda3/etc/sysconfig/network <<_EOF NETWORKING=yes HOSTNAME=node$N _EOF
cat >/mnt/hda3/etc/sysconfig/network-scripts/ifcfg-eth0 <<_EOF
DEVICE=eth0
BOOTPROTO=static
BROADCAST=10.14.255.255
HWADDR=`ifconfig eth0 | head -n 1 | awk '{print $5}'`
IPADDR=10.14.2.$N
NETMASK=255.255.0.0
NETWORK=10.14.0.0
ONBOOT=yes
TYPE=Ethernet
_EOF
Which will then need to be placed in the memory image of RIP:
Dumping and undumping rootfs.cgz:
gzip -dc ../rootfs.cgz | cpio -iumdv find . | cpio -v -o -H newc | gzip -9 >../rootfs.cgz
If you want to have RIP boot without prompting add these lines to the top of menu.lst:
default=0 timeout=5