How to Migrate a Virtual Machine From OpenVZ to KVM

Introduction

Our newest VPS platform – KVM – offers support for the latest Linux-based operating systems and Windows, personal SSH keys and most importantly, a lower price than OpenVZ in our case.

OpenVZ is container-based virtualization for Linux. It uses a shared kernel with a layer of virtualization on top of the actual Linux OS. Since this kernel is shared by all VPS users on the node, the kernel is not customizable. KVM (Kernel-based Virtual Machine) is, on the other hand a full virtualization solution. Using KVM, one can have Linux virtual machines running side by side on the same hardware.

This is why it is not possible to convert a VPS automatically from OpenVZ to KVM. Therefore, you basically have to transfer the files to the new KVM server manually. It is important to note that you cannot use the same IP address on the new KVM server. Some legacy applications have hard-coded IP address dependencies and this need to be addressed. Users and passwords, on the other hand, will be moved along.

To complete this guide, technical knowledge is required. If you need help migrating, contact us at support@glesys.se for a consultation and a quote.

Step 1 – Preparations

  • Create a KVM server using the same template with the same specifications as your current OpenVZ server. In general you cannot migrate from bigger kernel versions to smaller ones.
  • Make sure you have at least one good backup of the virtual machine you intend to migrate.

Step 2 – Upgrade your servers

Upgrade both of your servers with the latest packages and install rsync as the tool for synchronizing files and libraries between your servers.

apt-get update && apt-get install rsync && apt-get dist-upgrade -y
reboot

Step 3 – Set up root password

When creating your server on KVM, no root password is set. By default, root login is not allowed using a password via SSH.

Set a root password:

sudo passwd
Enter new UNIX password: 
Retype new UNIX password:

Edit sshd config to allow root login and restart the SSH daemon:

sudo sed -i 's/^PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sudo systemctl restart sshd

Step 4 – Copy files from the old server to the new

Log in as root on your OpenVZ server from where we’ll run rsync. Before proceeding, keep in mind that you need to shut down all applications and services that write to disk, for example: Apache, MariaDB and MySQL. Also make sure to pause any cronjobs running.

Note! Replace $IP below with the IP address of the target server (KVM) when you’re running the rsync syntax to copy the files:

rsync -avz --numeric-ids --delete --exclude /run --exclude /lib/udev --exclude /etc/udev --exclude /lib/modules/ --exclude /aquota.group --exclude /aquota.user --exclude /boot/ --exclude /dev/ --exclude /proc/ --exclude /etc/network/interfaces --exclude /sys/ --exclude /etc/fstab / $IP:/

Step 5 – Install kernel, grub and system management tools

Now the new server has all the data it needs from the OpenVZ server. However, the Debian or Ubuntu package database is also synchronized which is a problem. To fix it we need to reinstall grub.

Log in as root user and run:

Debian

apt-get install linux-image-amd64 linux-headers-amd64 busybox grub-pc acpid acpi-support-base qemu-guest-agent

Ubuntu

apt-get install linux-image-generic linux-headers-generic busybox grub-pc acpid acpi-support qemu-guest-agent

You will be asked where to install the boot loader. Choose /dev/sda.

GRUB install devices:
[*] /dev/sda (21474 MB; ???)

Enable the console (if it’s not already):

systemctl enable getty@tty1.service

Reboot the server:

reboot

Now you are able to log in to the new server (KVM) with the same credentials as you used on the old server (OpenVZ). Keep in mind that you have a new IP address.

Step 6 – Tips

If you have been using DNS or a load balancer for the OpenVZ server it is now time to redirect it to the KVM server.

It’s not recommended to permit root login with password over SSH. We recommend to disable the possibility to log in with password in the SSHd server and only allow SSH keys.

Note! Make sure you can log in with your SSH key before taking this action.

sudo sed -i 's/^PermitRootLogin yes/PermitRootLogin prohibit-password/g' /etc/ssh/sshd_config

sudo systemctl restart sshd

If you don't wish to keep your OpenVZ server after migration, you have to delete it in the control panel after shutdown – otherwise you will still be billed for it.

Need assistance?

If you need help migrating, contact us at support@glesys.se for a consultation and a quote.

Hittar du inte det du söker?

Kontakta oss gärna för mer information. Vi hjälper dig att komma fram till den bästa lösningen för dina behov.

Skicka e-post Ring 0200-23 88 00