Tuesday, October 3, 2017

Clone "Container" Type Linux VM to Full VM



Clone "Container" Type Linux VM to Full VM


There are various forms of "virtualization"; broadly speaking there are types that emulate an entire x86 machine (VMware, KVM, RHEV, Xen), and "lighter" varieties like OpenVZ, Linux LXC, and Solaris Zones. The latter types present special challenges for converting to VMware, as you can't reboot them from "external" media as with a fully virtualized PC. Here is one example of how to move a Linux (RHEL) machine running on OpenVZ (via Proxmox VE) to VMware.
I refer to "source" machine as the one you want to copy or convert, and the "target" machine as the new clone of that machine which you'll host in VMware vSphere, RHEV, or some other hypervisor.
Create a new VM (your target machine), as similar as possible to your source machine. Install your OS (RHEL 5, 6), preferably at the same point release (e.g. RHEL 5.9). Give this machine a static IP address different from your source machine, but on the same network or subnet. That IP will only be used during the data transfer.
Login to your source machine and run:
yum install mingetty
Then edit /etc/inittab, adding the following to the end:
#   Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:resspawn:/sbin/mingetty tty2

3:2345:respawn:/sbin/mingetty tty3

4:2345:respawn:/sbin/mingetty tty4

5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6
Create this file at root (/):
/exclude-list.txt
It should have the following contents:
etc/fstab/
boot/
proc/
lib/modules/
etc/udev/
lib/udev/
sys/
Change directory into / and run this:
rsync –-delete –-numeric-ids --exclude-from 'exclude-list.txt' -e ssh -avpogtStlHz / [email protected]<IP_of_target_machine>:/
(Prior to this you may need to edit sshd config on target to allow root access.) This will copy over everything to your target machine except the kernel files that it needs to keep. When the rsync completes, shut down your source machine and power on your target machine. You should have a bootable system that is for the most part an identical copy of your original. You may need to tweak the network configuration as the NIC (and MAC address) will be different.

This could be described as a blunt-force way to clone any (running and network-accessible) Linux based machine to different hardware, virtual or otherwise. Using virt-v2v, virt-p2v, or VMware Converter is certainly a cleaner method to use and is preferable whenever possible.

No comments: