10

docker can only use cgroupv1, but fedora by default only use cgroupv2. How do I check if system is cgroupv1 compatible?

So far answer in this question can only determine if cgroupv2 is installed. But it cannot determine if unified_cgroup_hierarchy set to 0 or 1. Is there any uniform way to determine if system is cgroupv1 compatible regardless whether the cgroupv2 installed or not?

So far I use mount -l to check if there is cgroup2 on /sys/fs/cgroup. If there is, that means cgroupv2 only. Is this method universally applicable in all distros? So far I only tested on Fedora and ubuntu. If not, is there an universal way to determine this?

Wang
  • 1,296

3 Answers3

11

I would follow the approach used by systemd:

  • if /sys/fs/cgroup exists and is on a cgroup2 file system, the system is running with a full unified hierarchy;
  • if /sys/fs/cgroup exists and is on a tmpfs file system,
    • if either /sys/fs/cgroup/unified or /sys/fs/cgroup/systemd exist and are on cgroup2 file systems, the system is using a unified hierarchy for the systemd controller only;
    • if /sys/fs/cgroup/systemd exists and is on a cgroup file system (or, as a fallback, if it exists and isn’t on a cgroup2 file system), the system is using a legacy hierarchy.
Stephen Kitt
  • 434,908
1

"If /sys/fs/cgroup/cgroup.controllers is present on your system, you are using v2, otherwise you are using v1".

Source: https://rootlesscontaine.rs/getting-started/common/cgroup2/#checking-whether-cgroup-v2-is-already-enabled

-2

if /sys/fs/cgroup/unified is on cgroup2 and /sys/fs/cgroup/systemd/ is on cgroup , both exists with this configuration on my linux. Then which is currently being used ?