Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
Are you trying to go directly to a raw volume, or are you trying to use a filesystem? –  ewwhite Dec 13 '12 at 22:38
    
@ewwhite With OpenVZ, I have always made a volume per container and edited the config to point to the appropriate mounted volume (OpenVZ didn't know it was a volume). I like that LXC has support for LVM, but when the container is running (created with the command above) I cannot see the volume mounted anywhere with df. Does that mean I'm using a raw volume? I basically want the benefits of LVM, and I am fine with LXC managing it, but it would be nice to have direct file access too IMO. –  jimp Dec 18 '12 at 4:58
add comment

1 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.

share|improve this answer
    
The config part might be where I'm stuck. With OpenVZ, there are sample configs in /etc/vz/conf and the command vzctl create --ostemplate {something-in-/vz/template/cache/} --config {something-in-/etc/vz/conf} handles everything. Does lxc-create not have anything similar, other than a "script" template (-t)? And are there any included sample configs? I can do all the extracting, no problem, but I guess you had to make /etc/lxc/Lancaster_Test.conf from scratch originally? –  jimp Dec 18 '12 at 5:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.