LXC - Cgroup memory controller: missing - linux

I'm trying install LXC (0.7.4.1) on my Debian 6 but when I run the lxc-checkconfig I get "Cgroup memory controller: missing"
root#lxcsrv01:~# lxc-checkconfig
Kernel config /proc/config.gz not found, looking in other places...
Found kernel config file /boot/config-2.6.32-5-686
--- 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 namespace: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: missing
Cgroup cpuset: enabled
--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled
enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig
According google search I need to recompile my kernel but I don't know how.
Someone can explain me how to do this?
Best regards

The kernel of Debian 6 has no memory cgroup feature.
However you can run lxc without it.
If you NEED memory cgroup, it's easy to install the new kernel
from backports.
Add apt-line of backports
Run "apt-get install linux-image-3.2.0-0.bpo.4-amd64" (or -686 for i386)
Add a kernel boot option "cgroup_enable=memory" to your bootloader setting
(e.g. /etc/default/grub) to enable it.
reboot
Or, if you'd like to re-compile the kernel, you can use kernel-package system of Debian;
http://newbiedoc.sourceforge.net/system/kernel-pkg.html

I am having similar memory cgroup issues, and have looked into it quite a bit. I wrote a blog entry about here:
http://blog.raymond.burkholder.net/index.php?/archives/639-Debian-Stretch-LXC-Memory-Controller.html
In summary, the kernel is compiled with the necessary memory cgroup support. The fly-in-the-ointment: lxc-checkconfig has a bug in it, and will not properly show the status of the memory cgroup. CONFIG_CGROUP_MEM_RES_CTLR=y is applicable for older kernels only (sometime before 3.6, I believe).
I end up making two adjustments: one adjustment to the /boot/config-$version, and one adjustment to /etc/default/grub. Both are explained in the article.
But bottom line, the general recommendation appears to be: don't enable it if you really don't need to perform memory limitation management on containers. There is some performance and memory overhead.

Update kernel from here.
Then reboot your system. This problem is solved automatically, but if not go to /boot/config-<versionnumber>-generic. For instance: /boot/config-3.11.0-13-generic
Here see if CONFIG_CGROUP_MEM_RES_CTLR=y is available or not. If 'yes' then ok, otherwise paste it that in.

Related

hidepid=2 stopped working after an update. Kernel don't suppport "per-mount point"?

I am running arch linux hardened (5.11.13-hardened1-1-hardened) and have been setting hidepid=2 thru the fstab:
proc /proc proc nosuid,nodev,noexec,hidepid=2,gid=proc 0 0
and in the and override file for systemd-logind.service as hidepid.conf:
[Service]
SupplementaryGroups=proc
All accordning to the arch wiki security and everything has been working fine up until a while ago after an update, and I think it is because of systemd-248 update, but I am obviously not sure.
When reading up on systemd changes a came across this section about "ProtectProc=invisible" which is being set in the systemd-logind.service now by default and should obsolete the fstab setting of hidepid=2 but in the description of "ProtectProc=" here freedesktop.org systemd protectproc=
If the kernel doesn't support per-mount point hidepid= mount options this setting remains without effect, and the unit's processes will be able to access and see other process as if the option was not used. This option is only available for system services and is not supported for services running in per-user instances of the service manager.
So what is the meaning of this? Is this something I can fix thru kernel parameters in the hardened kernel?
Best regards

Difference between `--privileged` and `--cap-add=all` in docker

Background: I am running a docker container which needs to load/remove a kernel module which makes USB devices attached to a remote server available on the host which I then want to make available in the container.
It works when running the container with —-privileged and bind mounts for /lib/modules and /dev.
Now I want to remove privileged mode and just allow the minimum necessary access. I tried —-cap-add=all as a start, but that doesn’t seem enough. What else does —-privileged allow?
Setting privileged should modify:
capabilities: removing any capability restrictions
devices: the host devices will be visible
seccomp: removing restrictions on allowed syscalls
apparmor/selinux: policies aren't applied
cgroups: I don't believe the container is limited within a cgroup
That's from memory, I might be able to find some more digging in the code if this doesn't point you too your issue.

Mounting cgroups for Resource Management in Docker

This is in reference to https://docs.docker.com/config/containers/resource_constraints/#limit-a-containers-access-to-memory. I have already created working containers, running Docker version 18.05.0-ce on a Raspberry Pi (64-bit) using Raspbian Jessie Lite (essentially GUI-less Debian Jessie).
The documentation claims that you can just pass memory/cpu flags on the docker run command. But when I try something like docker run -it --name test --memory=512m container_os, it says:
WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap
I get a similar message about not having cpuset mounted if I pass a cpu-based flag, such as --cpuset-cpus. This obviously means that I don't have these different cgroups mounted for Docker to manage resources correctly, right?
Now referring to https://docs.docker.com/config/containers/runmetrics/#control-groups, I read the section about cgroups, but it wasn't super helpful to my understanding of the situation. So rather than just trying random kernel commands, does anyone with experience have a step-by-step explanation of how to do this the right way?
After quite a bit of research, I figured this out, in-case anyone else out there has this same problem.
In reference to https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt, which is extremely helpful on understanding cgroups, a kernel with all of the proper support should have most of the cgroups for docker mounted by default. If not, there's a command to do so:
From section 2.1 - Basic Usage
"To mount a cgroup hierarchy with all available subsystems, type:
mount -t cgroup xxx /sys/fs/cgroup
The "xxx" is not interpreted by the cgroup code, but will appear in
/proc/mounts so may be any useful identifying string that you like.
Note: Some subsystems do not work without some user input first. For instance,
if cpusets are enabled the user will have to populate the cpus and mems files
for each new cgroup created before that group can be used."
For this particular case, however, trying to mount an individual cgroup, such as cpuset, results in an error saying that the "cpuset special device does not exist". This is because the devs of Raspbian Jessie 8 didn't configure the kernel to support the cgroups that Docker uses for resource management by default. This can easily be determined by typing the docker info command, and seeing this at the bottom of the output:
WARNING: No swap limit support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
WARNING: No cpuset support
These are all of the cgroups that are needed for Docker to manage memory and CPU resources for containers. Testing to see if your kernel supports something like cpuset is easy. If the file /proc/filesystems has an entry that says nodev cpuset, then that means your kernel has cpuset support, but if you're reading this then it probably means it's just not configured in your kernel. That would call for a kernel reconfiguration and rebuild however, which is not so easy.
With the right kernel configurations, it just works automatically like it seems from the Docker Docs.

Kernel configurations for lxc

I am configuring Linux kernel 3.10.31ltsi and want to add the needed support for LXC, as far as I understood, cgroups and namespaces shall be available for LXC, but what are the configurations in menuconfig that need to be included?
You should use a script called "lxc-checkconfig" (which is part of LXC) to check whether your kernel supports or not all required settings; see
https://linuxcontainers.org/lxc/manpages/man1/lxc-checkconfig.1.html
As a side note, I think that LXC uses by default all namespaces; this means that you should set
CONFIG_UTS_NS, CONFIG_IPC_NS, CONFIG_USER_NS, CONFIG_PID_NS,
CONFIG_NET_NS, and the mount namesapces (forgot it's config entry).
Regarding cgroups - not sure, probably the memory, cpu and I/O cgroups controllers are mandatory, and maybe some more; use the lxc-checkconfig script.

Mounting cgroups inside a docker container

I dockerized a component that follows a process model. The master process forks itself many times. I want to establish a cgroup hierarchy inside the docker container to vary the CPU and memory limit on a per process basis.
Is there a way I can do this without using '--privileged' or 'CAP_SYTEM_ADMIN'?
Is there a way I can make the cgroup that the container belongs to as the root of the cgroup subsytem that I am implementing for the processes? (Divide the resources allocated to the container among the processes).
The conclusion that I came to was that there is no current solution for this since Docker does not support cgroup virtualization nor does the Linux kernel. We need some form of cgroup virtualization in order to implement cgroups inside a container.
lxc does this using a FUSE based solution called lxcfs : https://linuxcontainers.org/lxcfs/introduction/
Also, there is a kernel patch that supports cgroup namespaces which as far as I can see have not been approved : https://lwn.net/Articles/605903/.

Resources