Linux Containers (LXC), libvirt and Slackware

I’ve spent the last few days getting very frustrated with trying to make a Linux Container (LXC) run via libvirt on Slackware – various weird and wonderful error messages about being unable to mount cgroups (LXC depends on cgroups to provide the networking and namespace isolation).

The short answer is that by default, Slackware mounts a cgroup type filesystem onto /sys/fs/cgroup, which causes every cgroup to be mounted into that directory. Libvirt does not like this for LXC – it expects each different cgroup type to be mounted in a separate directory. I’ve therefore put together the following init script that remounts the cgroups into the format that Libvirt expects (which I’ve based off the contents of fstab for another machine running Ubuntu):

# /etc/rc.d/rc.cgroup: Cgroup mounting script
# Remount cgroups under a tmpfs directory in /sys. By default,
# Slackware mounts /sys/fs/cgroup - however, this does not work
# with using libvirt for Linux Containers, because it expects each
# cgroup to have its own directory. So, let's do that.

# Unmount the existing /sys/fs/cgroup
umount /sys/fs/cgroup

# Create a tmpfs structure to hold all the new mounts
mount -t tmpfs -o mode=755,noatime tmpfs /sys/fs/cgroup

for cgroup in cpu cpuset cpuacct memory devices freezer blkio perf_event; do
    mkdir /sys/fs/cgroup/$cgroup
    mount -t cgroup -o $cgroup,noatime cgroup /sys/fs/cgroup/$cgroup

To use this, add it to rc.local before rc.libvirt is called (as libvirt needs to use the cgroups).

Posted on October 18, 2012 at 10:09 pm by Carlos Corbacho · Permalink
In: Linux, Slackware

Leave a Reply

You must be logged in to post a comment.