[K12OSN] Server Clone

J. Theriault administrator at maginetworks.com
Fri May 28 14:32:37 UTC 2004


Josiah Ritchie wrote:

> I've heard of people managing to do this between 2 different machines,
> but don't recall how it was done. Think it had something to do with ssh.
> I'm sure it was even slower...


Hmm, I haven't done this in awhile, but...

Using dd along with netcat (without ssh if it's a local network), you 
can use netcat to listen on a port on a second "receiving" machine and 
write the input of the listening port to a drive:

  nc -l -p <port number> | dd of=/dev/sda (output can be a file or clean 
drive)

The "sending" computer would reading from the source drive and pipe it's 
data into netcat to the port on the "receiving" computer:

  dd if=/dev/sda | nc <ip address> <port number>

Actually, searching Google (for "dd netcat drive cloning"), I found this 
shell script that runs on the "sending" computer to simplify this 
tranfer, this script assumes the listening port is 9000 and the netmask 
is 255.255.255.0:

(From http://www.rajeevnet.com/hacks_hints/os_clone/os_cloning.html)

=================================================
cloneme.sh :: Shell script for slave machine.
=================================================

#!/bin/sh
############### Edit variables below ######################
FLOPPY_PATH=/mnt/floppy
MYSTUFF_PATH=/mnt/sources/mystuff

# Uncomment only One of the options below.
#### OPTION ==> 1 if using floppy ################
#NC=$FLOPPY_PATH/nc
#### OPTION ==> 2 if using mystuff/ on CD #########
NC=$MYSTUFF_PATH/nc

LPORT=9000
DEST=/dev/sda
SRC=$DEST
############# No need to edit after this in general ###########

if [ $# -eq 1 ]
then
  IPADDR=$1
   echo "###############################################################"
   echo "   If there are no errors here. You need to run following"
   echo "                     command on Master Box."
   echo ""
   echo "dd if=$SRC | nc $IPADDR $LPORT"
   echo "###############################################################"

  echo ""
   echo "##>>  Preparing /etc/hosts  ##"
   rm /etc/hosts
   echo "127.0.0.1 localhost" > /etc/hosts
   echo "$IPADDR fakehost" >> /etc/hosts

  echo 
"#===================================================================="
  echo "NOTE:: If you need to create routes"
  echo " #route add -net <DEST_NET> netmask 255.255.255.0 gw $IPADDR 
metric 0"
  echo 
"#===================================================================="

  echo "##>> Preparing interfaces lo and eth0 ##"
  ifconfig lo 127.0.0.1 up
  ifconfig eth0 $IPADDR up

  echo ""
  echo ">>> Now start listening(at $LPORT) for traffic from Master :-)"
  echo "$NC -l -p $LPORT | dd of=$DEST"
  $NC -l -p $LPORT | dd of=$DEST

  echo ""
  echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
  echo " Cloning Process completed..... :-) Reboot Now"
  echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"

else
   echo "Usage:: cloneme <IP_ADDR_OF_THIS_MACHINE>"
fi


Hope this helps :)



J. Theriault
administrator at maginetworks.com





More information about the K12OSN mailing list