Create CentOS 6 System As “clone” Of Another – With LVM And Different Disk Sizes

Home » CentOS » Create CentOS 6 System As “clone” Of Another – With LVM And Different Disk Sizes
CentOS 5 Comments

Hi,

I just found myself having to set up a new CentOS 6 system with a nearly identical configuration to an existing host, so I thought I would just

1. Do a minimal install to set up partitions etc. on the new system.
2. Create an image of the existing system using Clonezilla
(http://www.clonezilla.org)
3. Run a Clonezilla restore on the new system.

– as I though it would be a lot simpler than replicating the exact package selection, installing the same users, doing the same manual config edits (which are required) etc.

It turns out that it wasn’t quite as easy, though. The problem is that the system use LVM2 volumes for the filesystems, and the new host has a slightly smaller disk than the other, and Clonezilla seems unable to restore to a volume that’s smaller than the one that was cloned – even if the actual data fits.

I guess I could temporarily reduce the LVM volume sizes on the existing units and clone again, but I’d rather not if I can avoid it. Just copying file-by-file could be an option, too, but I somehow feel less comfortable doing that than the above; there is something about the way I could end up with a mixture of my “minimal install” and the “cloned”
data, I suppose.

Does anyone have any other ideas about how I might achieve what I want?

– Toralf

5 thoughts on - Create CentOS 6 System As “clone” Of Another – With LVM And Different Disk Sizes

  • Hi,

    You can simply boot a live system to create your partition layout and copy it over the existing system with rsync.

  • Actually, I don’t believe that’s quite true. I’ve “cloned” to dissimilar hardware in the same manner before, and found that there was special handling of various hardware dependent config files, so that I didn’t get set-up  for the “wrong” type.

    – Toralf

  • Hi,

    I could be wrong, but afaik clonezilla makes bit-accurate copies of the file system like dd does. Therefore, no configurations should be adapted. Usually Linux doesn’t care where it runs, as long as the underlying ‘hardware’ (or virtual hardware) architecture matches.

    However, there are a number of configuration files that need to be modified for such clones, including network settings (local or on your dhcp server),
    {crypt,fs}tab (if no bit-accurate copy of the filesystem was used),
    /etc/host{s,name} depending on your network setup.

    best regards,
     – Markus

  • Toralf Lund wrote:

    Manually clone it.

    On the new machine:
    mkdir /new mkdir /boot/new rsync -HPavzx –exclude=/old –exclude=/var/log/wtmp $machine:/. /new/. rsync -HPavzx $machine:/boot/. /boot/new/.

    where $machine is the system you’re cloning from. You might want to exclude other logfiles.

    To prevent problems with the Ethernet interfaces:

    rsync -HPavzx /etc/sysconfig/network-scripts/ifcfg-eth*
    /new/etc/sysconfig/network-scripts rsync -HPavzx /etc/sysconfig/hwconf /new/etc/sysconfig rsync -HPavzx /boot/grub/device.map /boot/new/grub/
    rsync -HPavzx /etc/udev/rules.d/70-persistent-net.rules
    /new/etc/udev/rules.d/

    Clean log files – you don’t really want any of the old systems:

    find /new/var/log/ -type f -exec cp /dev/null {} \;

    Copy the original SSH keys – you do *not* want the keys of the system you’re cloning from:

    rsync -HPavzx /etc/ssh/ssh_host* /new/etc/ssh

    Now rotate: zsh, because it lets you load it’s builtin-s, so mv works

    zsh zmodload zsh/files

    cd /boot mkdir old mv * old mv old/lost+found . mv old/new/* .

    # Root partition. cd /
    mkdir old mv * old mv old/lost+found .
    #mv old/root . — WHY?
    mv old/scratch . mv old/new/* .

    sync sync

    Also you might want to

    touch /.autorelabel

    to shut up selinux.

    Note that this assumes the same CPU, etc, Otherwise, you might need to make a new initrd.

    mark

  • You are wrong. Not only is it unlike “dd” in that it will copy only the used space, and also let you to restore to a filesystem of a different size (while keeping that size), but it certainly changes config files, too – although I suspect it can only do simple edits to get around some obvious issues. I’ll for instance get lines like

    #HWADDR= # Commented out by Clonezilla

    after restoring ifcfg files that originally had just

    HWADDR=

    – T