Make identical copy of Centos

Solution 1:

While dd will copy one mounted drive to another, the copy will be inconsistent. The filesystem is constantly changing, and if you are using a journaled filesystem, even more so. Using dd works best when the drive is static, i.e. read-only. Most of the time, this isn't an option, but if you do have it read-only, this will work fine.

There are other tools to perform this cloning function. But the easiest is to simply use LVM's mirror functionality. The caveat is that you will need to have the existing filesystem on LVM already. Using an LVM mirror, you can make hot copies of the filesystem, and when you break the mirror to obtain your second drive, the filesystem image will be in a consistent state, because all the recorded changes will be sent consistently. It requires little work other than starting the mirror process and stopping it once the original has replicated completely.

If for some reason you don't want to use the mirror function, you can always create a snapshot of the filesystem and replicate the read-only snapshot to another drive. While this is not as automatic as mirroring, and it is a bit messy (extra steps), it can be made to work just fine.

Last, you can always try to rsync your way into this. This sounds like a strange way to do it, but I've used this to successfully replicate a server 400 miles away to a local drive. The catch was that I had to make a manual change to the /etc/fstab file (the paritions were different) but otherwise it boots fine.

That leaves a single sore point: making the drive bootable. Using dd will copy the boot loader over (as it is a block-by-block copy) but if you use the LVM or rsync methods, you'll need to re-install the bootloader. Fortunately, this isn't too hard and can be easily done to drives other than the current (original?) root filesystmem.

Solution 2:

I think 'dd' will do what you are looking for -- check out the below articles.

Linux Backup: Hard Disk Clone with "dd"

dd: the ultimate disk cloning tool

Wikipedia: dd

[edit]

If what you're looking for is more of a system template, where multiple systems are setup and configured the same way, instead of an exact copy then Cobbler may be what you are looking for:

Cobbler is a Linux installation server that allows for rapid setup of network installation environments. It glues together and automates many associated Linux tasks so you do not have to hop between lots of various commands and applications when rolling out new systems, and, in some cases, changing existing ones.

Solution 3:

I read about Hotcopy in Linux format a few issues back. Should do the trick.

Solution 4:

To build a server as was from the original install you can use the anaconda provided kickstart file in /root/anaconda-ks.cfg, you'll need to edit it for the partitioning and probably the networking/hostname.

This will give you a good reproducible baseline server config, and makes it easy to rapidly build machines. See the CentOS Installation Guide for more details. I can't advocate enough how automating your build process is a great practice.

For software/configuration you want done on top of that, you can use the %packages section and the %post scripts in kickstart but I personally use a configuration management tool - for me this is principally puppet. This allows you to alter things across the life of a machine and will ensure those changes are made to a system are preserved (most usually in source control). Even if you only have a few servers this can help hugely in a DR scenario as you ensure all changes are captured in configuration.

To get started puppet provides a tool called ralsh that can take the resources of a system (such as users or packages) and spit out snippets of the puppet language that can be used to build a replica of the system.

Moving to configuration management can be a big step and involves changing the way that you work. For a direct clone you might also take look at SystemImager

Solution 5:

More details would help...

If this is a production, public facing system, I would recommend doing a fresh install, and figuring out how to clone it manually. The reasoning is that you will know how your system works, and can probably design better fail over once you have that knowledge. For instance, if this is a web app with a database back end, having two installations won't really give you a good mirror, you will want to look into various database replication.

The other main options I am aware of are:

  1. Image the partition using something like dd
  2. Do a fresh CentOS install, and just rsync the old install over the new one with the -a option. This actually works pretty well, you will want to exclude the /proc directory and maybe a couple others