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
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:
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...
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:
Thanks VERY much!
This concise summary of the problem and solution was extremely helpful to me.
:)
David, as system administrator
A great, short solution driven article. Thanks. Too bad real cloning wasn't this easy!
I've bookmarked this article for future reference.
Thanks for simplifying the original article. Downtime doesn't lend itself to reading long docs. Much appreciated.
use UDPCast to clone to multiple machines.
so so useful.
i love you
you could pipe it through pv to get the transfer speed/progress.
ie nc -l -p 9000 | pv | dd of=/dev/sda
Like David said, for multicast look at udpcast.
On the master:
udp-sender --file /dev/sda
On the clients:
udp-receiver --file /dev/sda
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
Post a Comment
<< Home