From ca4955101d3ca912bf2c030ba77285212a2e149d Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 7 Aug 2024 08:40:10 -0400 Subject: [PATCH] Improve "realness" of imgutil exec context Utilities that expected /dev/pts will now be satisfied, as a new /dev/pts is mounted. Further, systemd added a check in various utilities that was fouled by the previous method of appearing to have a root filesystem. Before, after chroot, we would bind mount / to itself, and this made things using /proc/mounts, /proc/self/mountinfo, df, mount, etc happy that there is a real looking root filesystem. However, by doing it after the chroot, systemd could statx on '..' and get a different mnt id than /. So it had to be done prior to the chroot. However it also had to be done before other mounts as bind mounting over it would block the submounts. This more closely imitates the initramfs behavior, where '/' starts life as a 'real' filesystem before being mounted up and switched into. This behavior was made to imitate the 'start_root.c' behavior as that seems to be more broadly successful. --- imgutil/imgutil | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/imgutil/imgutil b/imgutil/imgutil index 5b5de0b2..c5446069 100644 --- a/imgutil/imgutil +++ b/imgutil/imgutil @@ -963,7 +963,6 @@ def fancy_chroot(args, installroot): _mount('none', dstresolv, flags=MS_RDONLY|MS_REMOUNT|MS_BIND) os.chroot(installroot) os.chdir('/') - _mount('/', '/', flags=MS_BIND) # Make / manifest as a mounted filesystem in exec os.environ['PS1'] = '[\x1b[1m\x1b[4mIMGUTIL EXEC {0}\x1b[0m \\W]$ '.format(imgname) os.environ['CONFLUENT_IMGUTIL_MODE'] = 'exec' if oshandler: @@ -1004,7 +1003,13 @@ def build_root_backend(optargs): def _mount_constrained_fs(args, installroot): + # This is prepping for a chroot. + # For the target environment to be content with having a root + # filesystem, installroot must be a 'mount' entry of it's own, + # so bind mount to itself to satisfy + _mount(installroot, installroot, flags=MS_BIND) _mount('/dev', os.path.join(installroot, 'dev'), flags=MS_BIND|MS_RDONLY) + _mount('/dev/pts', os.path.join(installroot, 'dev/pts'), flags=MS_BIND|MS_RDONLY) _mount('proc', os.path.join(installroot, 'proc'), fstype='proc') _mount('sys', os.path.join(installroot, 'sys'), fstype='sysfs') _mount('runfs', os.path.join(installroot, 'run'), fstype='tmpfs')