Copy a Linux system over the network, with no intermediate files

I had an old Red Had Linux system I wanted to convert to a Virtual Machine. The typical method recommended by most people is to back up the system, then restore it inside the VM. The problem I had with that is that you end up wasting a lot of time creating an image you don’t need, plus you need a storage device large enough to hold the image which can be accessed from both systems.

My solution was to create the VM with a virtual drive the size I needed. Then use a Knoppix image to initially boot the VM, once you get to a command line, use the commands below.

On the receiving server:

sudo nc -p 2222 -l | dd of=/dev/hda

On the system to be copied:

sudo dd if=/dev/hda | nc 2222

If your CPU on each device is faster than the network, you could also gain some speed by piping the data stream through bzip2. E.g. “sudo nc -p 2222 -l | bzip2 -d | dd of=/dev/hda” and “sudo dd if=/dev/hda | bzip2 -c | nc 2222”. Whether or not it’s worth it depends on the speed of your CPUs and the speed of your network.

It’s not a requirement that you boot the system being imaged from a CD, nor that you shut down any services. But, if you don’t, it’s possible you might end up with some files that aren’t in a valid state from the application’s point of view. There’s no real method I know of to monitor the progress of the copy, but you can run “fdisk /dev/hda” to verify the copy at least got started. If the copy started OK, then you’ll see partition information the same as on the system being imaged. You can also run “ifconfig” and watch the “RX bytes” field to get an idea of how much data has been transferred, but the counter will eventually overflow and start back at 0.