[26/06/2017] Smile acquiert Hypertexte, expert en référencement naturel (SEO) et en contenus optimisés

Smile annonce l’acquisition de l’agence Hypertexte, spécialiste du référencement naturel, de la conception et de la réalisation de contenus pensés pour le SEO.

[21/06/2017] Smile dans le top 10 des entreprises où il fait bon travailler !

Smile entre dans le classement très fermé des entreprises où il fait bon débuter sa carrière. Un palmarès publié dans Les échos et réalisé par

[20/06/2017] Smile classé 1er hébergeur en haute disponibilité depuis 3 mois

Depuis début mars, soit 3 mois consécutifs, Smile est à la tête du Classement des Hébergeurs en haute disponibilité, réalisé par ip-label et le Groupe NextRadio TV (01net, BFM, RMC).

Toutes les actualités picto

Vous avez besoin de mettre à jour votre Lecteur Flash Flash 7

Guillemet ouvrant l'actualité des solutions
et des technologies open source Guillemet fermant

Migrate your OpenVZ containers to KVM (OpenStack)

In this article, we are presenting a way to migrate OpenVZ containers to KVM (and OpenStack).

Why migrate ?

The two main reasons are: isolation given by full virtualization, and the kernel features available.

For example, it's not possible to use IPSec tunnels in an OpenVZ container.

Process explanation

An OpenVZ container has no kernel, no grub, no disk. Those 3 elements are mandatory to turn the container into a virtual machine. This tutorial explains how to create a virtual disk and install the kernel and grub inside the container.


The KVM host must have the following packages:

  • qemu-utils
  • qemu-kvm

You must have a VNC client. gvncviewer under gnome works just fine.

The migrated OpenVZ container is a Debian Squeeze.

1st step: creation of the disk for the new VM

Create an image in qcow2 format:

server-kvm:~# IMAGE=/tmp/ma_vm.imgserver-kvm:~# kvm-img create -f qcow $IMAGE 20GFormatting '/tmp/ma_vm.img', fmt=qcow size=21474836480 encryption=off

Mount the new image as a block peripheral:

server-kvm:~# qemu-nbd -c /dev/nbd1 $IMAGE

Create the partition(s):

server-kvm:~# cfdisk /dev/nbd1

Create the filesystem:

server-kvm:~# mkfs.ext3 /dev/nbd1p1

Mount the virtual disk partition:

server-kvm:~# MOUNT_POINT=/mnt/ma_vmserver-kvm:~# mount /dev/nbd1p1 $MOUNT_POINT

2nd step: copy the container to the virtual disk

Copy the container to the mount point:

server-kvm:~# CONTAINER_VZ=/tmp/mon_openvzserver-kvm:~# rsync -avz --numeric-ids ${CONTAINER_VZ}/* ${MOUNT_POINT}/

Note that rsync "numeric-ids" option is important to preserve the owners.

Once the container is transfered, we will use chroot to pre-configure the virtual machine.

3rd step: virtual machine pre-configuration

Chroot into VM:

server-kvm:~# chroot ${MOUNT_POINT} -s /bin/bash

Check that you really are into the chroot by checking that /etc/hosts information is from the OpenVZ container (and not from server-kvm).

server-kvm:~# cat /etc/hosts

Change the PS1 (to avoid using the bad console):

server-kvm:~# export PS1="(chroot) $PS1"

Generally, tty consoles are deactivated in an OpenVZ container. Reactivate them by adding (or uncomment the lines):

(chroot) server-kvm:~# vi /etc/inittab1:2345:respawn:/sbin/getty 38400 tty12:23:respawn:/sbin/getty 38400 tty23:23:respawn:/sbin/getty 38400 tty34:23:respawn:/sbin/getty 38400 tty45:23:respawn:/sbin/getty 38400 tty56:23:respawn:/sbin/getty 38400 tty6

Configure the network as you wish. In our case, we use DHCP:

(chroot) server-kvm:~# cat /etc/network/interfacesauto eth0iface eth0 inet dhcp(chroot) server-kvm:~# cat /etc/resolv.confnameserver

Add the mount point of the VM virtual disk to fstab:

(chroot) server-kvm:~# vi /etc/fstab/dev/vda1 / ext3 rw,relatime 0 0

Be sure to reactivate root password as we will need it for console login:

(chroot) server-kvm:~# passwd

Then, quit the chroot:

(chroot) server-kvm:~# exit

Fourth step: start the Virtual Machine

Before starting the new VM, umount the virtual disk! Caution: if you skip this step you face data corruption of the virtual disk:

server-kvm:~# umount $MOUNT_POINTserver-kvm:~# qemu-nbd -d /dev/nbd1/dev/nbd1 disconnected

Start the VM using KVM command. Note: this command do not return until the VM is stopped.

server-kvm:~# kvm -m 512 -kernel /boot/vmlinuz-$(uname -r) -initrd /boot/initrd.img-$(uname -r) -append "root=/dev/vda1" -drive file=${IMAGE},if=virtio -net nic,model=virtio -net user -vnc :20 -k fr

-kernel and -initrd options are part of KVM magic. This will allow to start the container even if it has no kernel and no grub yet.

Connect to the started VM with VNC:

client:~$ gncviewer server-kvm:20

Note: the keyboard map is probably qwerty.

Install required packages:

container-vz:~# aptitude install linux-image-amd64 grub console-tools console-data acpid acpi-support-basecontainer-vz:~# aptitude reinstall udevcontainer-vz:~# shutdown -h now

console-tools and console-data packages are needed if you want to fix the keyboard mapping.

acpid and acpi-support-base packages are important to handle KVM acpi signals correctly. For instance, if you reboot the KVM server, it will send an ACPI signal to stop the VM in a clean way.

We reinstall udev to be sure that ACPI is working properly.

5th step: VM check

To check that the migration worked fine, restart the VM without the kernel/initrd options:

server-kvm:~# kvm -m 512 -drive file=${IMAGE},if=virtio -net nic,model=virtio -net user -vnc :20 -k fr

6th step: upload image to OpenStack

Add image to OpenStack:

cloud-controller:~# glance image-create --name=my_image --disk-format=raw --container-format=ovf < ${IMAGE}+------------------+--------------------------------------+| Property         | Value                                |+------------------+--------------------------------------+| checksum         | abb4e2ab7ce9cafefeadfa5e1a78d347     || container_format | ovf                                  || created_at       | 2012-12-12T14:26:37                  || deleted          | False                                || deleted_at       | None                                 || disk_format      | raw                                || id               | 62410923-b8a7-4725-99fa-f06ae5cab6b3 || is_public        | False                                || min_disk         | 0                                    || min_ram          | 0                                    || name             | my_image                               || owner            | ab2519fd61b8425da392f228f54dc1c3     || protected        | False                                || size             | 8682160128                           || status           | active                               || updated_at       | 2012-12-12T14:29:39                  |+------------------+--------------------------------------+

Here it is! You migrated you OpenVZ container to a KVM virtual machine.

Marc Maurice


Soyez la premiere personne à ajouter un commentaire sur cet article.
Ecrire un nouveau commentaire