Cloning a Linux software RAID and LVM setup to another computer

1

I need to create a number of (almost) identical Linux machines (Debian Wheezy) with software RAID and LVM. I'm thinking of creating a base installation and cloning that one to all machines.

I tried googling for instructions or things to consider when cloning software RAID and/or LVM, but could not find anything specific. So, my question is, is it possible to clone such a setup at all? And what thing do I need to consider?

zacura

Posted 2015-03-31T17:51:42.550

Reputation: 11

Answers

0

You could try using disk destroyer as follows:

dd if=/dev/sdb of=/image.iso bs=16M #if is input drive bs is byte size to handle at once

Otherwise, you could plug both drives into one computer amd use if=/path/to/master of=/path/to/slave

Not sure if you would have to use a live os to make the image though.

Wilhelm Erasmus

Posted 2015-03-31T17:51:42.550

Reputation: 151

0

I won't go into deep detail, but I've migrated a few servers and workstations by "cloning" the disks, and my personal favorite is using rsync. Note that you'll need very good understanding of the boot up process to figure out any unexpected issues.

  1. Boot up the target from a CD, USB or otherwise so you have unrestricted access to the disks. Try to use the same kernel, mdadm, lvm and filesystem tool versions or get them as close as possible. Sometimes changes in newer versions can make things incompatible.

  2. Set up networking on the dest so it can communicate freely with the source. Start sshd (you can also ssh from the dest console, but it's usually more handy to have a terminal emulator connected over ssh so you can copy-paste the commands).

  3. Set up partitions, raid, lvm and filesystems as it is on the source disk. You'll need to either clone the various uuid's too, or take note of the changes to update the relevant configuration files (bootloader, fstab, etc.) later.

  4. If your source is already running, you may do a first run live (with the OS running, then the final run will be much faster). Use rsync with pretty much all possible options to copy every files as is... from memory, this command will do:

    rsync -axAHSX --delete / dest:/

    Repeat for every on-disk filesystems.

  5. Stop all processes on the source and remount all filesystems RO (Leave sshd up if you're connected over it, it won't prevent you from remounting RO). Re-run the rsync commands one last time.

  6. Shutdown the source computer.

  7. On the dest, chroot to the newly copied system (you many need to mount --bind /dev, /proc and /sys first). Fix up configuration files (device paths, uuid's etc.) Update your initrd and re-install the bootloader. Make any other required customization you need there such as re-creating sshd keys, changing IP's, hostnames... (you may put a script in the source in advance to perform these tasks...)

  8. Reboot dest; If boot fails or kernel panics re-boot from CD/USB and fix up anything missed in step 7. You may also be able to fix some errors from the emergency initrd shell if you get it, but you'll be a bit more limited than using a bootdisk.

Thomas Guyot-Sionnest

Posted 2015-03-31T17:51:42.550

Reputation: 465

Thanks, I will give rsync a try when I have more time, but for now this does not look like it would be much faster than installing debian and copying over config files manually. – zacura – 2015-04-01T05:25:25.980