[lxc-users] Can LVM be used in an LXC container?

Serge Hallyn serge.hallyn at ubuntu.com
Thu Jan 16 18:51:56 UTC 2014


Quoting Jeremiah Snapp (jeremiah.snapp at gmail.com):
> Hello I'm trying to lvcreate a small volume in an LXC container as part of
> a testing environment but I get the following error.
> 
> root at test:~# lvcreate -L 1G --name example vg01
> >   /dev/mapper/control: open failed: Operation not permitted
> >   Failure to communicate with kernel device-mapper driver.
> >   striped: Required device-mapper target(s) not detected in your kernel
> >   Run `lvcreate --help' for more information.
> 
> 
> Is there a way to make this work?
> 
> My host is Ubuntu 13.04 with LXC 1.0.0~beta1 and the container is Ubuntu
> 12.04 with LVM2 installed.
> 
> Thanks in advance!

It's not really a sane thing to do, but it shoudl work if you add
the needed devices to the container's devices whitelist.  That
means at least

lxc.cgroup.devices.allow = c 10:236 rwm
lxc.cgroup.devices.allow = b 252:* rwm

and maybe just giving full device access by removing all
lxc.cgroup.devices lines from the config.

You'll also want to make your container unconfined or modify your
apparmor profile to allow the mounting you need.  Simplest (and least
safe) is to do

lxc.aa_profile = unconfined

-serge


More information about the lxc-users mailing list