How can I remove cgroup version 1 mount points such that I only cgroup version 2 in my /sys/fs/
?
Cgroups – How to Unmount Cgroup Version 1
cgroupsmount
Related Solutions
The easiest way is to attempt to mount the pseudo-filesystem. If you can mount it to a location, then you can attempt to manage processes with the interface:
mount -t cgroup2 none $MOUNT_POINT
I see that you cited the documentation above. One of the points you may be missing is that the paths still need to be created. There's no reason you must manage cgroup resources at any particular location. It's just convention.
For example, you could totally present procfs
at /usr/monkeys
... as long as the directory /usr/monkeys
exists:
$ sudo mkdir /usr/monkeys
$ sudo mount -t proc none /usr/monkeys
$ ls -l /usr/monkeys
...
...
-r--r--r--. 1 root root 0 Sep 25 19:00 uptime
-r--r--r--. 1 root root 0 Sep 25 23:17 version
-r--------. 1 root root 0 Sep 25 23:17 vmallocinfo
-r--r--r--. 1 root root 0 Sep 25 18:57 vmstat
-r--r--r--. 1 root root 0 Sep 25 23:17 zoneinfo
$ sudo umount /usr/monkeys
In the same way I can do this with the cgroup v2 pseudo-filesystem:
$ sudo mount -t cgroup2 none /usr/monkeys
$ ls -l /usr/monkeys
total 0
-r--r--r--. 1 root root 0 Sep 23 16:58 cgroup.controllers
-rw-r--r--. 1 root root 0 Sep 23 16:58 cgroup.max.depth
-rw-r--r--. 1 root root 0 Sep 23 16:58 cgroup.max.descendants
-rw-r--r--. 1 root root 0 Sep 23 16:58 cgroup.procs
-r--r--r--. 1 root root 0 Sep 23 16:58 cgroup.stat
-rw-r--r--. 1 root root 0 Sep 23 16:58 cgroup.subtree_control
-rw-r--r--. 1 root root 0 Sep 23 16:58 cgroup.threads
drwxr-xr-x. 2 root root 0 Sep 23 16:58 init.scope
drwxr-xr-x. 2 root root 0 Sep 23 16:58 machine.slice
drwxr-xr-x. 59 root root 0 Sep 23 16:58 system.slice
drwxr-xr-x. 4 root root 0 Sep 23 16:58 user.slice
$ sudo umount /usr/monkeys
It's actually very simple. All cgroup
mounts must be done on top of a directory. Before you had,
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
When you unmounted all these, you left the underlying directories there. Alas, these can be removed by remounting /sys/fs/cgroup
as rw
and simply deleting them.
sudo mount -o remount,rw /sys/fs/cgroup
# Delete the symlinks
sudo find /sys/fs/cgroup -maxdepth 1 -type l -exec rm {} \;
# Delete the empty directories
sudo find /sys/fs/cgroup/ -links 2 -type d -not -path '/sys/fs/cgroup/unified/*' -exec rmdir -v {} \;
sudo mount -o remount,ro /sys/fs/cgroup
After which you should just see your beautiful and clean cgroup2
remaining,
$ ls /sys/fs/cgroup
unified
Best Answer
One easy way to do it is like this,
This will select only the mounts that are part of
cgroup
version 1, taking just their mount points and then unmounting them.Update: You may also want to clean up the remaining relics on
tmpsfs
mount at/sys/fs/cgroup
(taken from the answer there),