KVM stands for Kernel-based Virtual Machine. It is the infrastructure used to turn a Linux kernel into a hypervisor, also called a VNM (virtual machine monitor). Think of the main computer as a host machine, and each virtual instance running on it as a guest machine.
Because KVM is already part of the Linux kernel, is doesn't require additional software installations, so is not as complicated as other hypervisors can be.
KVM also executes full virtualization, as opposed to a virtualizor like OpenVZ in this case, where the host's kernel is shared with guest containers inside it.
Now we you have some background let's get started with the moving process:
- The first step before moving the box is installing a KVM box with the exact same OS as the OpenVZ container. You'll first need to register one with your favorite DPS. If you still need to do so you can follow that tutorial here.
Once you log in with you admin credentials, connect through
dhconnect
Run
yum update
on both VMs to make sure they are at the same point revision.
-
SSH into both VMs
-
In the KVM or OpenVZ box, install mingetty, a minimal getty. Depending on your VM version it may be preinstalled.
getty, short for "get tty", is a Unix program running on the host computer for managic virtual terminals, or TTYs. Mainly it manages the login for you.
- Edit /etc/inittab in the VM installed with mingetty
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/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
As a best practice, it's good to get in the habit of backing up your config file first. Easiest way is to copy the inittab file and name the backup to inittab.bak
cp -pr /etc/inittab /etc/inittab.bak
This will enable the machine to actually get a logon prompt.
- Install rsync on both VMs. Rsync is a file copying tools used for backups and mirroring. It uses a delta-transfer algorithm to reduce sends over a network by calculating only the dfiferences between the source and destination files. Again this may also be preinstalled.
yum install rsync
- In OpenVZ, make a text file containing files to exclude. This will preserve settings in KVM to make sure the VM is bootable.
touch /root/exclude.txt
Add these lines to it:
/boot
/proc
/sys
/tmp
/dev
/var/lock
/etc/fstab
/etc/mtab
/etc/resolv.conf
/etc/conf.d/net
/etc/network/interfaces
/etc/networks
/etc/sysconfig/network*
/etc/sysconfig/hwconf
/etc/sysconfig/ip6tables-config
/etc/sysconfig/kernel
/etc/hostname
/etc/HOSTNAME
/etc/hosts
/etc/modprobe*
/etc/modules
/net
/lib/modules
/etc/rc.conf
/usr/share/nova-agent*
/usr/sbin/nova-agent*
/etc/init.d/nova-agent*
/etc/ips
/etc/ipaddrpool
/etc/ips.dnsmaster
/etc/resolv.conf
/etc/sysconfig/network-scripts/ifcfg-eth0
- Now we just start to sync the OpenVZ box to the KVM box. In OpenVZ, enter
rsync --exclude-from="/root/exclude.txt" --delete --numeric-ids -avpogtStlHz -e "ssh -p <ssh port>" / root@<target ip>
This will likely take a reasonable amount of time, as it's porting over the entire box. There's a chance you get a few broken pipe errors, but the wonderful thing about rsync is you can just reboot and it should continue from where it left off.
And that should be it! To make sure everything’s working, reboot the KVM box when the rsync process has completed. Once your new KVM box is up, you will have to go in there and make the IP changes to cPAnel/WHM, shoutcast, zPanel, or whichever other control panel you're using.