diff --git a/confluent_client/doc/man/imgutil.ronn b/confluent_client/doc/man/imgutil.ronn index b3a82da7..b32598b2 100644 --- a/confluent_client/doc/man/imgutil.ronn +++ b/confluent_client/doc/man/imgutil.ronn @@ -29,7 +29,9 @@ While it runs, `/proc`, `/sys`, `/dev`, an empty `/run` and the build system's `/etc/resolv.conf` are mounted, without changing the scratch directory. A plain `chroot` lacks them (no DNS, no `/dev/null`), so run - chroot based tools through `imgutil exec`, see EXAMPLES. + chroot based tools through `imgutil exec`, see EXAMPLES. `uname` and + `/proc` report the newest kernel of the image, so DKMS builds for it, + see `-k`. * `unpack`: Unpack a diskless image profile to a scratch directory for modification. @@ -133,12 +135,21 @@ the OS (AlmaLinux for EL, the official Ubuntu image, openSUSE Leap for SUSE). +* `-k`, `--kernel` : + Kernel version that `uname` and `/proc` report in the image. Defaults to + the newest kernel of the image, `host` for the build system kernel. Needs + Linux 5.0 or later on x86_64 or aarch64, otherwise a warning is printed. + * : Directory to build new diskless root in. With `--containerfile`, the file to write, or `-` for standard output. ## EXEC OPTIONS +* `-k`, `--kernel` : + As for `build`. dnf keeps the newest kernel of the image as the running + one, use `-k host` to remove it. + * `-v`, `--volume` : Directory to make available in the build environment. `-v /` will cause it to be mounted in image as `/run/external/`. `-v /:/run/root` will override the target to be `/run/root`. May be specified multiple times. diff --git a/imgutil/imgutil b/imgutil/imgutil index 869f4bcb..9b173004 100644 --- a/imgutil/imgutil +++ b/imgutil/imgutil @@ -17,7 +17,9 @@ import argparse import os import pwd import re +import select import shutil +import signal import stat import struct import subprocess @@ -1416,6 +1418,144 @@ def _exitcode_from_status(status): return 128 + os.WTERMSIG(status) return 1 + +# uname() in the chroot reports the newest kernel of the image instead of the +# one of this system, so DKMS, kernel Makefiles and scriptlets build for the +# kernel the image boots. A seccomp filter hands each uname() to the process +# waiting for the chroot, which writes the answer into the caller. +SECCOMP_ARCH = {'x86_64': (0xc000003e, 63, 317), 'aarch64': (0xc00000b7, 160, 277)} + + +class _IoVec(ctypes.Structure): + _fields_ = [('base', ctypes.c_void_p), ('len', ctypes.c_size_t)] + + +class FakeUname(object): + def __init__(self, installroot, release=None): + self.installroot = os.path.abspath(installroot) + self.fixed = release + self.procdir = None + self.fd = None + self.current = None + self.host = os.uname().release + self.machine = os.uname().machine + uts = ctypes.create_string_buffer(390) + libc.uname(uts) + self.uts = uts.raw + with open('/proc/version') as versin: + self.version = versin.read() + + @classmethod + def for_args(cls, args): + args.fakeuname = None + if args.kernel != 'host': + args.fakeuname = cls(args.scratchdir, args.kernel) + return args.fakeuname + + def release(self): + # no uname() here, the filter would have it wait for itself + return self.fixed or image_kernel(self.installroot) or self.host + + def install(self): + fd = -1 + if self.machine in SECCOMP_ARCH: + arch, nruname, nrseccomp = SECCOMP_ARCH[self.machine] + filt = b''.join(struct.pack('