HOWTO_Clone_a_Gentoo_Server_or_Workstation
Contents |
About
This article deals with the case where you want to install a machine with exactly the same configuration as another machine by cloning the device over network. Assuming you're on the same network, boot both machines using a Linux Live CD.
Note: You may need to get yourself a copy of Netcat the easiest way to do this is jump onto an existing Gentoo box and build netcat:
emerge gnu-netcat
Once netcat has been built on your Gentoo box copy the binary over to both the box you want to clone (the server) and the client (box you want to create.) of course replace the IP address with the IP address of the appropriate machine.
scp /usr/bin/netcat 192.168.1.1:/tmp/nc
If you did not already have nc on your livecd you can now use it by replacing nc with /tmp/nc throughout the rest of the guide.
Now on the machine you are copying from (assuming the hard drive you want to clone is /dev/hda):
dd if=/dev/hda conv=sync,noerror bs=64k | nc -l -q 0 -p 5000
This begins a low level read of the hard drive and pipes it to netcat, which just listens on port 5000 for a connection.
Next, we must setup the client:
nc 192.168.1.1 5000 | dd of=/dev/hda bs=64k
Replace "192.168.1.1" with the IP address of the machine you are copying from.
This will take a long time.
Problems
This only really works well when both machines are exactly the same or you are using a less customized OS, such as Fedora or Microsoft Windows. Gentoo Linux Kernels are generally customized to the exact spec of the machine. If the kernel is the only problem and not the partition layout, you could just compile a new kernel on the server and copy it to /boot on the client in place of the current one.
If however your partitions are different you could copy the / partition and make a new /boot wherever you want.
A good way to get around this is to only copy the / partition. Instead of the above use:
dd if=/dev/hda3 conv=sync,noerror bs=64k | nc -l -q 0 -p 5000
Replace "hda3" with your / partition.
You must then setup the partitions on your client machine to be similar to the server. The / partition must be the same or larger than the original.
Then type this on your client:
nc 192.168.1.1 5000 | dd of=/dev/hda3 bs=64k
You can then do the same for /boot and copy a new kernel across like above. You will also need a new Master Boot Record so that the client knows to boot using Grub.
To do this, you'll need to chroot into your new / partition, which hopefully has grub installed if it came from a Linux machine.
From the Live CD:
mkdir /mnt/hda3 mount /dev/hda3 /mnt/hda3 chroot /mnt/hda3 /bin/bash grub root (hd0,0) setup (hd0)
Substitute (hd0,0) for the location of /boot (don't forget grub's weird naming habits) and (hd0) for the hard drive itself.
The only thing left to do is edit /boot/grub/grub.conf to make sure the settings are correct for the new machine.
Extras
Compression
It is also possible to compress the output during transfer using gzip. This may or may not make a real difference to the transfer rate but you would use something like this:
dd if=/dev/hda conv=sync,noerror bs=64k | gzip -c | nc -l -q 0 -p 5000 nc 192.168.1.1 5000 | gzip -cd | dd of=/dev/hda bs=64k
Resizing the / partition after the clone
- Context:
- The destination partition is larger from the source partition
- The partition type (in my example) is reiserfs
- You want to resize the partition to it's maximum size (as partitioned)
- The partition you want to resize is not mounted
First get the relevant information using fdisk -l (of course, your information will be different):
| Code: fdisk -l /dev/hda |
Disk /dev/hdb: 20.0 GB, 20003880960 bytes 255 heads, 63 sectors/track, 2432 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 1 5 40131 83 Linux /dev/hda2 6 68 506047+ 82 Linux swap / Solaris /dev/hda3 69 2432 18988830 83 Linux |
Useful information is:
- The Unit size (in the present case, Units = 8225280)
- The size of the hda3 partition (in Units): 2432-69 (side note: I am just a user reading this howto and will not modify the text to the left of this note, but glancing at the math, I think 2432 - 68 would be the correct equation in the above example, since the drive has 2432 total cylinders, and cylinder 1 to 68 is used by the first two partitions (note it doesn't start at 0, so count(1 to 68) = 68 I believe), please correct me if I'm wrong, and simply remove this comment if its incorrect, and don't forget to modify the below equations if I am correct, maybe someone that has experience can simply verify this information, and make the appropriate corrections and then remove this note, maybe just mentioning it was adjusted as suggested by an anonymous reader)
We can now call reiserfs_resize as follows (in a BASH console... so that we can let BASH do the calculations):
resize_reiserfs -s $[(2432-69)*8225280] /dev/hda3
The output should look something like this:
| Code: resize_reiserfs 3.6.19 |
ReiserFS report: blocksize 4096 block count 4745199 (1118512) free blocks 4295716 (669139) bitmap block count 145 (35) Syncing..done resize_reiserfs: Resizing finished successfully. |
Resizing the / partition after the clone (GUI method)
if you don't feel confortable with units size and cylinders, you can take a live-cd and launch gparted.
Gparted is a graphic utility that allow you to resize easily your partitions; in my expirience was pretty stable, but take your backup near you ;-)
Obviuosly exist also a qt version named qtparted; and almost every live-cd has one of this tool.
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should be using interactive floor plans and list their apartments, townhouses and units.
