I use unprivileged lxc
containers in Arch Linux
. Here are the basic system infos:
[chb@conventiont ~]$ uname -a
Linux conventiont 3.17.4-Chb #1 SMP PREEMPT Fri Nov 28 12:39:54 UTC 2014 x86_64 GNU/Linux
It's a custom/compiled kernel with user namespace enabled
:
[chb@conventiont ~]$ lxc-checkconfig
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled
--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled
--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig
[chb@conventiont ~]$ systemctl --version
systemd 217
+PAM -AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID -ELFUTILS +KMOD +IDN
Unfortunately, systemd
does not play well with lxc
currently. Especially setting up cgroups
for a non-root user seems to be working not well or I am just too unfamiliar how to do this. lxc
will only start a container in unprivileged mode when it can create the necessary cgroups in /sys/fs/cgroup/XXX/*
. This however is not possible for lxc
because systemd
mounts the root
cgroup hierarchy in /sys/fs/cgroup/*
. A workaround seems to be to do the following:
for d in /sys/fs/cgroup/*; do
f=$(basename $d)
echo "looking at $f"
if [ "$f" = "cpuset" ]; then
echo 1 | sudo tee -a $d/cgroup.clone_children;
elif [ "$f" = "memory" ]; then
echo 1 | sudo tee -a $d/memory.use_hierarchy;
fi
sudo mkdir -p $d/$USER
sudo chown -R $USER $d/$USER
echo $$ > $d/$USER/tasks
done
This code creates the corresponding cgroup
directories in the cgroup
hierarchy for an unprivileged user. However, something which I don't understand happens. Before executing the aforementioned I will see this:
[chb@conventiont ~]$ cat /proc/self/cgroup
8:blkio:/
7:net_cls:/
6:freezer:/
5:devices:/
4:memory:/
3:cpu,cpuacct:/
2:cpuset:/
1:name=systemd:/user.slice/user-1000.slice/session-c1.scope
After executing the aforementioned code I see in the shell I ran it in:
[chb@conventiont ~]$ cat /proc/self/cgroup
8:blkio:/chb
7:net_cls:/chb
6:freezer:/chb
5:devices:/chb
4:memory:/chb
3:cpu,cpuacct:/chb
2:cpuset:/chb
1:name=systemd:/chb
But in any other shell I still see:
[chb@conventiont ~]$ cat /proc/self/cgroup
8:blkio:/
7:net_cls:/
6:freezer:/
5:devices:/
4:memory:/
3:cpu,cpuacct:/
2:cpuset:/
1:name=systemd:/user.slice/user-1000.slice/session-c1.scope
Hence, I can start my unprivileged lxc
container in the shell I executed the code mentioned above but not in any other.
Can someone explain this behaviour?
Has someone found a better way to set up the required
cgroups
with a current version ofsystemd
(>= 217
)?