Replicating Linux Machines across a Network

This command will replicate a running machine into a remote machine container.
The source machine can be online and running, the remote machine should be booted via a Linux Live Image.   The destination machine should also have the same or larger disk size than the source machine.

Sending Machine
dd if=/dev/sda bs=16M conv=sync,noerror status=progress | gzip –9 -cf | nc destinationmachineip preferredport -q 10

Receiving Machine
nc –l –p preferredport | gzip –dfc | dd bs=16M of=/dev/sda

It is worth doing some test copies if you have a large image to send, or are on a slow network, altering the block size (bs=) and gzip compression amount (-9).  Particularly on the latter, on a fast network, you may be better off using lower compression, as the CPU cycles required for compression may in fact take longer than sending the data uncompressed or at a lower compression rate.

You can also use other compression programs like pigz to achieve better performance.

iPXE CloneZilla

CloneZilla is a linux toolset that allows you to clone either a partition or whole disk to another location;  either a connected storage device,  or remotely to the network.   This is a great tool for imaging systems before you work on them and lets you have a copy in case the worst should happen.    It has a variety of bundled tools in order to read from most of the popular filesystems in use,  falling back to DD to copy each disk sector if you’re using some obscure or proprietorial filer.   This is the FOSS alternative to Norton Ghost!

The great thing about CloneZilla is that its quick and easy to get it booting via iPXE,  so is worth investing a small amount of time in setting up so that you have it ready to go should you need it.

These instructions are based on release clonezilla-live-20121217-quantal.iso which seems to be versioned 2.0.1-15.  

Download the ISO from the CloneZilla site.  Use 7zip or your favourite image opening tool to open the ISO.  You need to extract the following files:

  • vmlinuz
  • initrd.img
  • filesystem.squashfs

and put them onto your boot webserver.  In this example,  I have created a folder called CloneZilla.

############ CloneZilla ############
echo Starting CloneZilla with default options
kernel http://boot.server/CloneZilla/vmlinuz
initrd http://boot.server/CloneZilla/initrd.img

imgargs vmlinuz boot=live config noswap nolocales edd=on nomodeset ocs_live_run=”ocs-live-general” ocs_live_extra_param=”” ocs_live_keymap=”” ocs_live_batch=”no” ocs_daemonon=”ssh” usercrypted=Kb/VNchPYhuf6 ocs_lang=”” vga=788 nosplash noprompt fetch=http://boot.server/CloneZilla/filesystem.squashfs
boot || goto failed
goto start

And that is really about it! You’ll notice we pass a few arguments which set various options. The most important option is the ‘fetch=’ command which tells the image where to download the main file system from. The other option I set was ‘usercrypted=’ which uses the Linux mkpasswd command to set the root password on boot – in this example iloveclonezilla.

A really easy one this week, but one worth trying. I’m fighting to get Backtrack5 booting over iPXE without using the ISO method, but this is proving troublesome. I think the image simply isn’t able to cope with being booted from a http network source.