1. rc.cgconfig which uses the configuration file at /etc/cgconfig.conf to run the cgconfigparser utility to parse and setup the control group filesystem.These services are enabled by making them executable (run: sudo chmod a+x /etc/rc.d/rc.cg{config,red}).
2. rc.cgred, the CGroups Rules Engine Daemon, which uses the rules found in /etc/cgrules.conf to automatically assign processes into cgroups based on UID/GID.
Step 0. But first ...
Step 1. Setting up /etc/cgconfig.conf
The /etc/rc.d/rc.cgconfig service uses the /etc/cgconfig.conf file to insert control group branches into the control group filesystem. We will define, in /etc/cgconfig.conf, the control groups we want added to enable the ordinary user chris to run unprivileged containers. Add the following lines to /etc/cgconfig.conf:
This specifies that a control group with name qwerty (the name itself is not important), with administrative permissions granted to system user chris, should be created in each of the control groups mentioned (cpuset, cpu, cpuacct, blkio, ...). A full description of the possibilities is available by running man cgconfig.conf.group qwerty {
perm {
task {
uid = chris;
gid = users;
}
admin {
uid = chris;
gid = users;
}
}
cpuset {
cgroup.clone_children = 1;
cpuset.mems = 0;
cpuset.cpus = 0-3;
}
cpu {}
cpuacct {}
blkio {}
memory { memory.use_hierarchy = 1; }
devices {}
freezer {}
net_cls {}
perf_event {}
net_prio {}
pids {}
}
After any changes to /etc/cgconfig.conf, it's worth checking that the syntax is still all good by running the command:
cgconfigparser -l /etc/cgconfig.conf
Step 2. Setting up /etc/cgrules.conf
chris * qwerty/which grants user chris access to all controllers (*) mentioned in the control group named qwerty. Run man cgrules.conf for more details.
Step 3. Setting up the user
sudo /usr/sbin/usermod --add-subuids 100000-165536 chris
sudo /usr/sbin/usermod --add-subgids 100000-165536 chris
lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536
Confirming the setup
sudo /etc/rc.d/rc.cgconfig startThey should run without error. Now inspect the available control groups by running the lscgroup command, which will display a tree of available control groups. If our new control group qwerty appears as a child of all the controllers specified in the configuration file e.g. freezer:/qwerty, that's a good start.
sudo /etc/rc.d/rc.cgred start
# Start libcgroup servicesAlternatively, add the same lines anywhere in /etc/rc.d/rc.local
if [ -x /etc/rc.d/rc.cgconfig -a -x /etc/rc.d/rc.cgred -a -d /sys/fs/cgroup ]; then
echo "Starting libcgroup services"
/etc/rc.d/rc.cgconfig start
/etc/rc.d/rc.cgred start
fi
Next step: Part 2 - Running unprivileged containers
Contact
Please send any questions, comments, advice etc., to Chris
Willing <chris.willing (at) linux.com>