Overview
This is a detailed guide on how to check for and enable cGroups on a modern
Linux operating system.
The standard method involves modifying the kernel's boot parameters,
which requires root access and a system reboot
Procedure to enable cGroups v2
- Step 1: Check the Current cgroup Version, if any
Before making any changes, first identify which cGroup version, if any, is currently active on your
server.
Run the following command to know what cGroup versions are supported.
grep cgroup /proc/filesystems
Above command shows that cGroups v1 and v2 both are supported by the OS.
Now to check which version is enabled on the server.
stat -fc %T /sys/fs/cgroup
If cGroups v1 is enabled and cGroups v2 is disabled then it will show below output:
[root@dev ~]# stat -fc %T /sys/fs/cgroup
tmpfs
If cGroups v2 is enabled then it will show below output:
[root@dev ~]# stat -fc %T /sys/fs/cgroup
cgroup2fs
If the output is cgroup2fs, then it means the cGroup version 2 is enabled on your server.
If its not cgroup2fs then you need to enabled it.
- Step 2: Enable cGroup v2
Most modern Linux distributions, such as Ubuntu 22.04, Debian 11, and RHEL 9, use cgroup
v2 by default. If your system is on v1 and you need to switch to v2, you can do so by editing the
kernel boot parameters.
Open the GRUB default configuration file with a text editor:
sudo vi /etc/default/grub
Find the line beginning with GRUB_CMDLINE_LINUX
.
You need to add systemd.unified_cgroup_hierarchy=1
to this line. If the line already has other parameters,
add it to the end, inside the quotes
# Example before:
GRUB_CMDLINE_LINUX="quiet splash"
# Example after:
GRUB_CMDLINE_LINUX="quiet splash systemd.unified_cgroup_hierarchy=1"
Save the file and exit the editor. Now, update the GRUB bootloader configuration and reboot
the server.
On Debian/Ubuntu:
sudo update-grub
sudo reboot
On RHEL/CentOS/Fedora:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
sudo reboot
After the server reboots, run the check command again. The output should now be
cgroup2fs.