How to clone a Linux server (either for disaster recovery/ bare metal restore or to stand up a virtual instance)
Posted by rbTech Staff on 08 March 2013 11:25 AM
Through this document, I'll use the terms target and production to describe the new clone and existing servers, respectively.
To clone a physical instance of CentOS, the biggest trick is the fact that the filesystem layout will not be the same on the target system. This means that you'll clone your files over but then when you reboot the system will kernel panic and crash on your.
That said, the easiest way to get a working copy of a machine is to prep the target server (be it a virtual or physical instance) by spinning an installation CD that is the same version *or older* than the production server. Partition your disks and get a working, basic system.
Reboot the target into Linux rescue mode. Mount your filesystems and set up your network adapter so you can communicate with the machine you're cloning (production). Mount your filesystems at /mnt/sysimage (the rescue image will prompt you for this and will do it automatically).
chroot . (this will put you 'into' the new machine).
perform ssh key exchange between the target and production servers.
Perform a full rsync of the entire filesystem from the production machine:
You'll notice I exlcluded the ssh key folder and the /etc/fstab from the rsync...
Once the rsync is complete, you'll need to modify your boot loader: In /boot/grub/grub.conf change the filesystems (often /dev/mapper/VolGroup00/LogVol00 or similar) to be reflective of the target server's filesystem layout. You can cheat and do this at the grub command line as well!
Delete the /boot/initrd from the old server, and re-run mkinitrd:
Before you reboot one more time, you *must* update your MBR:
If you've done it all right, you'll reboot and the server will stand up on the new filesystem!