sonic-buildimage/files
Konstantin Vasin 8a3fad2891
[Build] mount cgroup2 in chroot to fix build on ubuntu 22.04 (#13030)
Why I did it
Ubuntu 22.04 uses cgroup2 by default, but docker.sh doesn't mount it.
As a result we get an error when trying to run docker info in chroot env:

ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

How I did it
mount cgroup2 in chroot if all enabled kernel cgroup controllers are currently not in use by cgroup1

So we need to mount cgroup in chroot environment on /sys/fs/cgroup.
Because inside chroot we don't know which cgroup version is used by the host we have two possible solutions:

cgroup tree for chroot is mounted by the host (it was my 1st version of this fix)
cgroup tree is mounted inside chroot based on info from /proc/cgroups (it's current version of this fix)
My 2nd version based on this code from systemd: 5c6c587ce2/src/shared/cgroup-setup.c (L35-L74)

We parse info from /proc/cgroups
Skip header line started from #
Skip controller if it's disabled (4th column = 0)
Count number of controllers with non-zero of hierarchy_id (2nd column)
If this number is not zero then we assume some of controllers are used by host system and the host system uses hybrid or legacy cgroup tree. In this case we can't use unified cgroup tree inside chroot and mount old cgroup tree (v1).
If this number is zero then we assume host system uses unified cgroup tree and we need to mount cgroup2 inside chroot.

Signed-off-by: Konstantin Vasin <k.vasin@yadro.com>
2022-12-17 12:16:45 -08:00
..
Aboot Fix extraction of platform.tar.gz for firsttime (#11935) 2022-10-21 18:27:32 -07:00
apt [Build] set apt Acquire::Retries to 3 for bullseye (#12758) 2022-11-21 08:05:16 +08:00
build_scripts [hostcfgd]: Add Ability To Configure Feature During Run-time (#6700) 2021-03-13 05:56:27 -08:00
build_templates Replace logrotate cron file with (adapted) systemd timer file (#12921) 2022-12-08 14:13:11 -08:00
dhcp ZTP infrastructure changes to support DHCP discovery provisioning data (#3298) 2019-12-10 08:16:56 -08:00
docker [Build] mount cgroup2 in chroot to fix build on ubuntu 22.04 (#13030) 2022-12-17 12:16:45 -08:00
image_config Replace logrotate cron file with (adapted) systemd timer file (#12921) 2022-12-08 14:13:11 -08:00
initramfs-tools [Arista] Add initial support for 720DT-48S (#10656) 2022-06-29 09:56:24 -07:00
scripts [build] Add the possibility to disable compilation of teamd and radv containers. (#12920) 2022-12-13 12:06:30 +02:00
sshd Remove SSH host keys after installing the custom version of sshd (#10633) 2022-04-25 10:38:52 -07:00