Archive

Posts Tagged ‘nc’

cloning harddrives over network

December 30, 2008 6 comments

To clone identical drives in a linux system you can use dd command, dd command makes it really easy.

dd if=/dev/hda of=/dev/hdb

above command will clone hda to hdb (partitions, boot record etc), but what if you have to clone a drive that is not attached to same system?

I found a really interesting way to transfer files over the network simple by using netcat and dd.

  • Boot the machine (where second drive is attached) with a live cd distro like Ubuntu or Knoppix. Setup networking or let the DHCP server assign an ip automatically. My DHCP assigned this machine ip 192.168.0.21
  • run following command on this machine
    nc -l -p 7777 | dd of=/dev/hdb
    (where /dev/hdb is the target drive)
  • Now come to the machine where you have attached the drive to be cloned and issue following command.
    dd if=/dev/hda | nc 192.168.0.21 7777
    (/dev/hda is the drive to be cloned)

It will take time (usually several hours) depending on size of the drive. If you are worried about bandwidth you can pipe through gzip to compress and uncompress the streamed data on source and destination machine respectively, to do this you would run following commands.

On target machine:

nc -l -p 7777 | gzip –dfc | dd of=/dev/hdb

And on source machine.

dd if=/dev/hda | gzip –cf | nc 192.168.0.21 7777

have fun with dd and nc 🙂

Advertisements
Categories: linux, ubuntu Tags: , , ,