How to clone or copy your harddisk over the network

From www.ReeltoReel.nl Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Method 1 (tested!)

On the bron/zender/source:

#dd if=/dev/sda | gzip -c | netcat -l -q 0 -p 2222 

On the ontvanger/doel/target:

#netcat <ip van server> 2222 | gzip -cd | dd of=/dev/sda

This way we get a throughput of 14,1 MB/s, 160 GB in 11543 seconds (3,2 hour)

Methode 2 (niet getest!)

How do I use netcat to copy hard disk image?

Our sample setup


HostA // 192.168.1.1
          sda
       NETWORK
          sdb
HostB // 192.168.1.2

Your task is copy HostA /dev/sda to HostB's /dev/sdb using netcat command. First login as root user Command to type on hostB (receiving end ~ write image mode)

You need to open port on hostB using netcat, enter :

# netcat -p 2222 -l |bzip2 -d | dd of=/dev/sdb


Where,

   * -p 2222 : Specifies the source port nc should use, subject to privilege restrictions and availability.   Make sure port 2222 is not used by another process.
   * -l : Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host.
   * bzip2 -d : Compresses image using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. This will speed up network transfer ( -d : force decompression mode)
   * dd of=/dev/sda : /dev/sda is your hard disk. You can also specify partition such as /dev/sda1

Command to type on hostA (send data over a network ~ read image mode)

Now all you have to do is start copying image. Again login as root and enter:

# bzip2 -c /dev/sda | netcat hostA 2222

OR use IP address:

# bzip2 -c /dev/sda | netcat 192.168.1.1 2222

This process takes its own time. A note about latest netcat version 1.84-10 and above

If you are using latest nc / netcat version above syntax will generate an error. It is an error to use -l option in conjunction with the -p, -s, or -z options. Additionally, any timeouts specified with the -w option are ignored. So use nc command as follows.

On hostA, enter:

# nc -l 2222 > /dev/sdb

On hostB, enter:

# nc hostA 2222< /dev/sda

OR

# nc 192.168.1.1 2222< /dev/sda

Using a second machine (hostB), connect to the listening nc process at 2222 (hostA), feeding it the file (/dev/sda)which is to be transferred. You can use bzip2 as follows. On hostA, enter:

# nc -l 2222 | bzip2 -d > /dev/sdb

On hostB, enter:

# bzip2 -c /dev/sda | nc 192.168.1.1 2222