Easier creation of libvirt lxc containers

LXC, from lxc.sf.net, is a very advanced and flexible toolset
and library for managing linux containers. It is very
actively maintained, provides for both system and application
containers, and in particular has really nice ‘templates’ for
creating fedora, lxc, or debian containers, or minimal containers
based on busybox or only offering sshd.

Libvirt-lxc, on the other hand, is very inflexible due to
having to follow the same API as all other libvirt-supported
hypervisors. It is very sparsely documented, and I’m not
sure there is anyone out there actually using libvirt-lxc to run
anything. In the past, I’ve stuck to tiny, hand-built containers
using only debootstrap and ‘/bin/sh’ (-> debootstrap) as the
init task.

I use libvirt, and even virt-manager, quite a bit nowadays to
keep my many VMs straight. It’d be nice to also use it for
some containers. That also opens the door to having UEC
create nodes as contaienrs. So I whipped up a pair of scripts to
leverage the great work from the LXC team in building something I
can use with libvirt. You can get them with

	bzr branch lp:~serge-hallyn/+junk/lxc-libvirt-scripts

There is a README to show how to use them and how they work.
Basically you just

	lxc-libvirt-create.sh u1

to create a container ‘u1’, and then

	virsh -c lxc:// start u1

to start it. If you haven’t used the lxc ubuntu template before,
the first build takes awhile as the system is debootstrapped.
Future ones are very fast.

And container startup is lightning-fast. I created one and
installed apache to play around a bit. VNC as a user is
trivial, but I’d like to set up a template (through a
lxc ubuntu-vnc template) to automatically set up a vnc
session running gdm. (Mind you, shutdown from inside a
container doesn’t work – you have to just kill init from
the outside.)

But then I noticed that virt-manager doesn’t support
connections to the lxc driver. That’s no good! Fortunately
it didn’t take too much work to shoehorn that in, so you
can get a package at ppa:serge-hallyn/virt.

	add-apt-repository ppa:serge-hallyn/virt
	apt-get update
	apt-get install virt-manager

I’ll send the diff for that upstream, though I think I should
make the VM creation window work with LXC before I do that.

Advertisements
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

7 Responses to Easier creation of libvirt lxc containers

  1. Tarjei Huse says:

    Do you have to be at a special place in your directory tree to get this to work?

  2. Pingback: Create an LXC Application Container using libvirt » Philipp Klaus's Computing Blog

  3. Olivier Berger says:

    For the curious ones, the scripts are in : https://code.launchpad.net/~serge-hallyn/+junk/lxc-libvirt-scripts

  4. Dan Kegel says:

    What’s the status of this – is this kind of thing going to get rolled into ubuntu 12.10? Or is it already there?

  5. jjmerelo says:

    Thanks, it’s been quite useful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s