Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Tip of the Day: "ghosting" a machine with nc and dd



You can also find this TotD on the wiki:

http://www.tlug.jp/wiki/Linux_Help:Tip_of_the_Day:Cloning_a_machine_with_nc_and_dd

If you have two more-or-less similar machines (meaning mainly that the
target machine has a hard drive at least as large as the source; the
kernel seems to cope with most other differences as "trivial",
assuming you have a pretty modular one like most distros give you
these days, ya damn kids![1]) and you want to clone one:

1. Plug both machines into a fast hub, or use a crossover cable[2] to
connect them directly
2. Boot up both machines from a LiveCD like Gentoo[3] or KNOPPIX[4]
3. Bring up networking on both machines. I would advise giving them
both private addresses, say 192.168.1.1 for the source and
192.168.1.254 for the target (and thus that is how my examples will
work)
4. Determine the device name of the hard drive on each machine. If you
have an IDE (Wikipedia) drive, your device will almost certainly be
/dev/hda, and if you have a SCSI (Wikipedia) (or SATA (Wikipedia)? can
someone confirm this) drive, it will be /dev/sda. To verify this, run:

sudo fdisk /dev/hda

or

sudo fdisk /dev/sda

If you have the right drive, the output should look something like this:

Disk /dev/hda: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1        13    104391   83  Linux
/dev/hda2            14      7042  56460442+  83  Linux
/dev/hda3          7043      7296   2040255   82  Linux swap

5. On the target machine, run:
HDD_DEV=/dev/sda
# (replace /dev/sda with the appropriate device name from the previous step)
TARGET_PORT=2727
nc -l -p ${TARGET_PORT} | dd of=${HDD_DEV}

6. On the source machine, run:
HDD_DEV=/dev/hda
# (replace /dev/hda with the appropriate device name)
TARGET_IP=192.168.1.254
# (replace 192.168.1.254 with the correct IP address if you did not
follow my advice)
TARGET_PORT=2727
dd if=${HDD_DEV} | nc ${TARGET_IP} ${TARGET_PORT}

7. Wait for a while
8. Once the transfer finishes (you will know when you get dropped back
to a command prompt; switch to a different virtual terminal and run
top if you'd like to monitor the procedure--dd and nc processes should
be consistently near the top until completion), reboot the target
machine off its hard drive

Cheers,
Josh

[1] Get off mah lawn!
[2] http://en.wikipedia.org/wiki/Ethernet_crossover_cable
[3] ftp://ftp.ecc.u-tokyo.ac.jp/GENTOO/releases/x86/current/livecd/livecd-i686-installer-2007.0.iso
[4] ftp://ftp.kernel.org/pub/dist/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links