Transfer Linux With DD & Netcat

In this article I would like to share a recent experience I had upgrading a customer server to new hardware. The server being upgraded was originally deployed on desktop hardware (Dell OptiPlex GX520) as a new server for this customer was not an option. This server was built and put in place in early 2010 and has happily been running ever since. Jump ahead to December 2014 when I get a call from the customer asking if we could look into doing a hardware upgrade for this server. At this point I had nearly forgotten all about this server as the customer initially had intended to upgrade the hardware the following year. Like most things “if it ain’t broke don’t fix it” applies. Anyhow, the customer was ready to upgrade the server and his only requirement was minimum downtime (preferably none). Note, the OS (Ubuntu) had been kept up to date over the years and was now running on 14.04LTS. Normally, we would simply image the server using Clonezilla and then apply the image to the new server and be done. Downtime for this customer was not going to work so we set out to find another solution. I vaguely remembered upgrading a disk drive years ago using dd, and a quick dive into my notes revealed the answer. Below are the commands I previously used to copy a disk with dd.

# clone hard disk /dev/hda to /dev/hdb:
dd if=/dev/hda of=/dev/hdb bs=1M conv=noerror

Once I realized how easy that was I figured, why not pipe dd to netcat and copy the drive over the network. Below is the solution that worked for me. This solution resulted in zero downtime for the customer. We didn’t need to do anything other than boot the new server using a live cd, assign a static IP address and run the command below. Note that both the new and old servers need to be on the same network.

nc -l -p 9001 | dd of=/dev/sda bs=1M conv=noerror

Once the new server has been prepared as outlined above, log into the old server, su to root and run the following command.

dd if=/dev/sda | nc 9001

While this did copy the server in its entirety, it is important to note that the hard drive geometry will be the exact same as the source. To deal with this, we simply booted into GParted and resized the partitions as required. It is also important to note that the file /etc/udev/rules.d/70-persistent-net.rules needed to be removed in order to setup our network adapter as eth0.

Did you find this article useful? Why not share it with your friends?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.