April 16, 2012

How to: clone an hard disk/partition via network

Some days ago I had to clone an hard disk of a computer into another one but all the hd connections were used... so I decided to clone it via lan!

The process is quite simple and it requires only two linux live cd and a working ethernet connection.

First we  start each computer with the linux live cd and assign an ip to each computer. Obviously the ips have to be in the same subnet (ex. ip1: 192.168.1.10 and ip2: 192.168.1.20). The subnet must be the same (ex. 255.255.255.0).
To be bullet-proof is better to test if the computers see each other using the command ping (from comp1: ping 192.168.1.20 and from comp2: ping 192.168.1.10).

Now, assuming that sda is the hd in the destination computer, let's digit (as root) the command:

# nc -l 10000 > /dev/sda

where
nc is the command netcat
-l 10000 means "listen to the port 10000"
> means "into"
/dev/sda is the destination disk

On the source pc, assuming that sda is the hd to clone, let's digit (as root) the command:

# nc 192.168.1.20 10000 < /dev/sda

where
nc is the command netcat
192.168.1.20 is the destination ip
10000 is the destination port
< means "from"
/dev/sda is the source disk

If we want to clone a partition instead of the entire disk the commands to give are:
  • on the destination pc: # nc -l -p 10000 > /dev/sda1
  • on the source pc: # nc 192.168.1.20 10000 < /dev/sda1
The netcat clone solution is very fast but the informations via network aren't cripted, if you want a more complete solution you should try clonezilla