Friday, February 25, 2005

Wonders of 'dd' and 'netcat': Cloning OS harddrives

The other day, I needed to clone a Linux system again. I had done cloning before, to an identical drive in the same computer. The dd command makes that boringly easy:

dd if=/dev/sda of=/dev/sdb

Wait a while, and your second SCSI disk (/dev/sdb) is an exact copy of the first (/dev/sda): boot record, partitions, everything. And by the way, the system on /dev/sda need not be Linux. If it is Windows or whatever else, just reboot to some Live Linux CD to make the copy.

But this time, the problem was a little different: I wanted the copy to go to an identical disk, but on another (also identical) computer. Not only did I not want to stop the system during the copy, but I didn't even have the cable to attach my disk to the "master" computer. Well it turned out to be almost as boringly easy than the previous example.

This page (from which this blog entry got it's title) goes into a lot of details, but to sum it up for the impatient, my simple problem was solved like this:

  • Boot the machine (which we will call Slave) with some Linux media like a Knoppix live CD. My DHCP server assigned it the IP address 192.168.1.220.

  • On Slave, run
    nc -l -p 9000 | dd of=/dev/sda
    (note that it is important to start with Slave)

  • On Master, run
    dd if=/dev/sda | nc 192.168.1.220 9000

  • Go have a drink


That was it. If you enjoy drinks and want to also take a nap or something, replace your Gigabit switch with an old 10-Base-T hub between the 2 machines.

Don't forget to disconnect the network cable before rebooting Slave into it's brand new system, or you will have an IP address conflict if Master uses fixed IP addresses. And find more interesting names for the poor machines before the PC police gets you.

Update: now that I have used this method several times, I would like to do it with multicast to several machines at once. If you know how to do that, please leave a comment...

8 Comments:

Anonymous Anonymous said...

Thanks VERY much!

This concise summary of the problem and solution was extremely helpful to me.

:)

David, as system administrator

18 October, 2006 00:02  
Anonymous Anonymous said...

A great, short solution driven article. Thanks. Too bad real cloning wasn't this easy!

I've bookmarked this article for future reference.

02 November, 2006 16:51  
Anonymous Anonymous said...

Thanks for simplifying the original article. Downtime doesn't lend itself to reading long docs. Much appreciated.

25 May, 2007 19:32  
Anonymous Anonymous said...

use UDPCast to clone to multiple machines.

20 August, 2007 22:05  
Anonymous Anonymous said...

so so useful.

i love you

28 September, 2007 23:06  
Anonymous Anonymous said...

you could pipe it through pv to get the transfer speed/progress.
ie nc -l -p 9000 | pv | dd of=/dev/sda

25 January, 2008 19:56  
Anonymous Anonymous said...

Like David said, for multicast look at udpcast.

On the master:
udp-sender --file /dev/sda

On the clients:
udp-receiver --file /dev/sda

09 June, 2008 10:09  
Anonymous Anonymous said...

Hi Everyboady,

I'm a new in linux, I've installed FC9 on my pc with windows OS with different HDD, Both OS are working fine, but we have requirement for adding 01 HDD in my PC So I have add 01 PC. Time of Connecting HDD I have change the IDE Port of boot loader HDD (may be). After Connecting my PC has not booting in any OS. It is showing only GRUB and hang on it. I have try to re-install GRUB boot loader through FC8 Rescue CD. but cant do.
If anybody know about it then please inform me how to solve this problem.
Plz. mail me at my mail ids "jvd.sddq@gmail.com" n "jvd.sddq@yahoo.com"

Thanks in advance

17 October, 2008 15:04  

Post a Comment

<< Home