coreos/rpm-ostree

Integrate with kernel-install.d

Opened this issue · 5 comments

Right now our code dealing with the Fedora-derivatives kernel packaging is a mess. I think what would work well is to add /usr/lib/kernel/05-rpmostree.install and:

Detect if the system is actively (rpm-)ostree based (otherwise we could cause problems if people just happen to have the package installed...I think for now the important case is /run/ostree-booted for hosts and detecting our containers); if it's not we just exit 0.

Otherwise, looking at all the stuff in

# ls -al /usr/lib/kernel/install.d/
total 40
drwxr-xr-x. 1 root root   34 Dec 12 16:24 .
drwxr-xr-x. 1 root root   18 Dec 12 16:24 ..
-rwxr-xr-x. 2 root root 8053 Jan  1  1970 20-grub.install
-rwxr-xr-x. 2 root root 1905 Jan  1  1970 20-grubby.install
-rwxr-xr-x. 2 root root 2006 Jan  1  1970 50-depmod.install
-rwxr-xr-x. 2 root root 1895 Jan  1  1970 50-dracut.install
-rwxr-xr-x. 2 root root  791 Jan  1  1970 60-kdump.install
-rwxr-xr-x. 2 root root 5635 Jan  1  1970 90-loaderentry.install
-rwxr-xr-x. 2 root root  204 Jan  1  1970 92-crashkernel.install
-rwxr-xr-x. 2 root root 1989 Jan  1  1970 99-grub-mkconfig.install

I think except for the crashkernel bits we handle all of that internally and should basically fork off rpm-ostree kernel-install add (we have some cliwrap code for this already).

A crucial detail here is that the docs say if a script does an exit 77 then everything else is skipped, which is what we need.

If we do that well, I think we might be able drop our logic for "ignore kernel postinsts" which would be really nice...well almost except it seems that the kernel posts still directly run dracut...argh. (What is the 50-dracut.install doing then?)

However, there's some important bits we should handle in the container case specifically. With this we'd be really close to having dnf update kernel work - except we need (well, want) to do cleanup like:

  • removing the copies of kernel data in /boot
  • Ensuring there's only one kernel installed

In some experimentation, this is getting pretty close:

$ cat /usr/lib/kernel/install.d/07-rpmostree.install
#!/usr/bin/bash

set -euo pipefail

COMMAND="${1:?}"
KERNEL_VERSION="${2:?}"

[ -w "/lib/modules" ] || exit 0
[ -d "/sysroot/ostree/repo" ] || exit 0

# Call hooks that we want
/usr/lib/kernel/install.d/50-depmod.install "${COMMAND}" "${KERNEL_VERSION}"

case "$COMMAND" in
    add)
        test -n "${KERNEL_VERSION}"
        # We don't need this stuff
        rm -f /boot/*${KERNEL_VERSION}*
        dracut -v -f /usr/lib/modules/${KERNEL_VERSION}/initramfs.img "${KERNEL_VERSION}"
        # And ensure nothing else runs
        exit 77
        ;;
    remove)
        rm -f "/usr/lib/modules/${KERNEL_VERSION}/initramfs.img"
        exit 77
        ;;
    *)
        exit 0
        ;;
esac

From the Automotive perspective, a lot of the people in the community at the moment are kernel hackers, as there is plenty of hardware enablement to do in ARM in general.

In some experimentation, this is getting pretty close:

$ cat /usr/lib/kernel/install.d/07-rpmostree.install
#!/usr/bin/bash

set -euo pipefail

COMMAND="${1:?}"
KERNEL_VERSION="${2:?}"

[ -w "/lib/modules" ] || exit 0
[ -d "/sysroot/ostree/repo" ] || exit 0

# Call hooks that we want
/usr/lib/kernel/install.d/50-depmod.install "${COMMAND}" "${KERNEL_VERSION}"

case "$COMMAND" in
    add)
        test -n "${KERNEL_VERSION}"
        # We don't need this stuff
        rm -f /boot/*${KERNEL_VERSION}*
        dracut -v -f /usr/lib/modules/${KERNEL_VERSION}/initramfs.img "${KERNEL_VERSION}"
        # And ensure nothing else runs
        exit 77
        ;;
    remove)
        rm -f "/usr/lib/modules/${KERNEL_VERSION}/initramfs.img"
        exit 77
        ;;
    *)
        exit 0
        ;;
esac

@cgwalters LGTM, great patch. Just a small suggestion, could you please use a bash constant for the exit 77? I understood this is "common" usage in the similar scripts but what this signal in the end? My guess is: "all tasks for the command parameters are done and success" instead of exit 0 (all script run just fine, success). Linking a documentation here would even be better. :)

xref: #4950