I am now working on libvirt and the tools gravitating around it for almost a year and still haven't blogged about anything related to it. As a first post on virtualization, I'll tell you how to migrate your LXC container to use the libvirt goodness.

In order to achieve the migration, the host machine needs to be upgraded to openSUSE 13.1 or later. Quite some of the required features are only in Factory, so those of you running 13.1 will need to add the Virtualization repository like this:

host ~# zypper ar -f http://download.opensuse.org/repositories/Virtualization/openSUSE_13.1/Virtualization.repo

The first thing to do is to install libvirt-daemon-lxc, to drag all the needed packages to run containers on libvirt. Of course, installing virt-manager will also provide you a convenient GUI to handle them.

host ~# zypper in libvirt-daemon-lxc

The LXC container files are usually living in the /var/lib/lxc/ folder. Let's assument for this example, that we have an lxc container named mycontainer to migrate.

To avoid the boring task of creating a similar configuration for the libvirt container, use the virt-lxc-convert to generate an equivalent libvirt domain configuration for the container.

host ~# virt-lxc-convert /var/lib/lxc/mycontainer/config >mycontainer.xml

The dumped configuration file, needs to be reviewed before feeding it to libvirt. Most of the configuration will be OK, but the network configuration may need some adjustments. For example, for now, libvirt doesn't have any equivalent to lxc.network.ipv*.

When the configuration is ready, define the libvirt container using the following command:

host ~# virsh -c lxc:/// define mycontainer.xml

To be able to connect as root on the console, /dev/pts/0 needs to be added to the container securetty:

host ~# echo "pts/0" >> /var/lib/lxc/mycontainer/rootfs/etc/securetty

Due to rhbz#966807, the kernel 3.14 or later is required to be able to login on the container.

After this you should be able to start and connect to the container console using virsh or virt-manager.

Updating the openSUSE in the container

This is just normal zypper manipulation, just that the --root parameter needs to be added to tell zypper to work on the container's root file system. In the following command this will just be aliased as zypper-mycont.

The following example commands will just replace the container repositories by openSUSE 13.1 repositories, refresh them and run a dist upgrade.

host ~# alias zypper-mycont="zypper --root=/var/lib/lxc/mycontainer/rootfs"
host ~# zypper-mycont lr
# | Alias    | Name     | Enabled | Refresh
--+----------+----------+---------+--------
1 | repo-oss | repo-oss | Yes     | No
2 | update   | update   | Yes     | No
host ~# zypper-mycont rr repo-oss
host ~# zypper-mycont rr update
host ~# zypper-mycont ar http://download.opensuse.org/distribution/13.1/repo/oss repo-oss
host ~# zypper-mycont ar http://download.opensuse.org/update/13.1/ udpate
host ~# zypper-mycont ref
host ~# zypper-mycont dup