Easy cloning of a linux workstation or router (Debian)
I made a pretty complicated dev box / router for a client, which has three ethernet network cards and a wireless card, some complicated routing and bridging setup, an asterisk sip server, http server, ftp, smtp and pop3. Also, a lot of perl CPAN modules are installed and C and kernel development libraries.
Then I was asked make another one. I'm paid by the hour as a contractor, but even if it brings money into the bank I didn't want to spend another two days going to the process of reinstalling and configuring everything again.
I finished the job in one hour in a half using just netcat and dd (with some help for sfdisk for fixing partitions after that).
Boot with a live CD on the slave box, and open a listening socket:
slave# ip address add 192.168.0.254/24 dev eth0
slave# nc -l -p 8823 | dd of=/dev/sda
Then on the master, go to runlevel 1:
master# init 1
The bring up the interface:
master# ip address add 192.168.0.253/24 dev eth0
master# ip link set eth0 up
master# dd if=/dev/sda | nc 192.168.0.254 8823
In my situation, the slave disk was 20gig and the master was 40gig. Fortunately, I just needed the first 10 gigs. Unfortunately, the partition table was invalid and linux complained every time it booted. Fdisk and Cfdisk refuse to work on an invalid partition, so I had to use sfdisk
slave# sfdisk -d /dev/hda > partitions
This command will write the current tables on the file "partitions". Edit the file and feed it back to sfdisk
slave# sfdisk /dev/hda < partitions
Then, just edit the /etc/udev/rules.d/z25_persistent-net.rules for the new ethernet cards (This is on Debian testing, which uses udev).
That's it. Full cloning, over the network with basic tools. No Norton Ghost or other black box software.
