How to create a LXC container on LVM from an OpenVZ template

centos6lxcopenvzubuntu-12.04

I have a lot of experience using OpenVZ, but I want to give LXC a try on a server where perfect isolation is not a concern. The main reason for the switch is preferring Ubuntu Server LTS as the base OS, but the OpenVZ project currently only supports the RHEL kernel and the latest kernel patch is for 2.6.32.

This new server is running Ubuntu 12.04 LTS. I found it's very simple to create a container using the provided container templates, i.e., lxc-create -t ubuntu -n testvps -B lvm --vgname vps --fssize 20G --fstype ext4. However, I have yet to find any substantial information that explains how to take a precreated OpenVZ template and use it as the base for a LXC container. The articles I've seen basically recommend OpenVZ templates as a good option for LXC containers. But how? This article comes close, but it uses paths Ubuntu 12.04 does not and extracts directly to the filesystem instead of a LVM logical volume. Being so new to LXC, I'm sure I must be missing something. I need to know where I should put the OpenVZ template tarball (or extract it) so the lxc-create -t` command can initialize from it.

I need to create a LXC container, on a LVM volume, under Ubuntu 12.04 from the OpenVZ precreated CentOS 6 template. Any help pointing me in the right direction would be greatly appreciated. Thank you!

Best Answer

I do this all the time using LXC and the OpenVZ CentOS templates.

The two guides I followed initially are here and here.

I usually place my containers under /srv/ or /srv/lxc/. I don't bother with LVM, but if you want to, just mount your new LVM volume under /srv/lxc/container_name per-container. That makes sense, right?

In this example, I have a ZFS-on-Linux mount at the place where I want the container to reside under /srv:

[root@Lancaster_Mirror1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p2      12G  1.9G  9.4G  17% /
tmpfs                 7.8G     0  7.8G   0% /dev/shm
/dev/cciss/c0d0p1     291M   59M  218M  22% /boot
/dev/cciss/c0d0p7     2.0G  119M  1.8G   7% /tmp
/dev/cciss/c0d0p3     9.9G  1.9G  7.5G  20% /usr
/dev/cciss/c0d0p6     6.0G  321M  5.3G   6% /var
vol2/images            98G   43G   56G  44% /images
vol3/Lancaster_Test    98G   22G   77G  22% /srv/Lancaster_Test <<--container

As for the LXC installation, I take the prebuilt OpenVZ image and put it in the destination container directory, then unpack it - tar -ztvf centos-6-x86_64-devel.tar.gz. Nothing needs to be modified on the template to make this work.

  426  wget http://downloads.sourceforge.net/project/lxc/lxc/lxc-0.7.3/lxc-0.7.3.tar.gz
  427  rpmbuild -ta lxc-0.7.3.tar.gz
  429  rpmbuild -ta lxc-0.7.3.tar.gz
  434  yum --nogpg install lxc-0.7.3-1.x86_64.rpm libvirt
  437  lxc-create -f /etc/lxc/Lancaster_Test.conf -n Lancaster_Test
  438  lxc-checkconfig
  441  screen -dmS init-Lancaster_Test /usr/bin/lxc-start -n Lancaster_Test
  442  screen -dmS console-Lancaster_Test /usr/bin/lxc-console -n Lancaster_Test

Maybe I'm off, but I choose to use the containers directly on a filesystem. Are you doing something different?

I can provide excerpts of the lxc config files, but you don't seem to have an issue with that.

Related Topic