Home > linux, ubuntu > cloning harddrives over network

cloning harddrives over network

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: , , ,
  1. skeldoy
    December 31, 2008 at 4:15 pm

    bs=1024k will speed that up for you

  2. minicoder
    January 6, 2009 at 5:19 am

    Very Interesting

  3. October 13, 2013 at 7:59 pm

    does this work with partitions only?

  1. December 30, 2008 at 5:21 pm
  2. February 2, 2009 at 7:43 am
  3. July 23, 2010 at 4:25 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: