• [gentoo-dev] [PATCH] eclass/(dist-)kernel{-utils,-install}: More flexib

    From Andrew Ammerlaan@21:1/5 to All on Mon Nov 27 10:20:01 2023
    Hi all,

    This patch is intended to be merged alongside the introduction of sys-kernel/installkernel-gentoo-8. Version 8 introduces:
    - UKI compatibility
    - The ability to use /etc/kernel/preinst.d plugins, to complement the
    existing /etc/kernel/postinst.d plugins
    - An optional dracut preinst.d plugin that is intended to be toggle-able
    with USE=dracut, similar to the existing GRUB postinst.d plugin that is toggle-able with USE=grub

    This last change is what the eclass patch below is for. This patch
    encapsulates the initrd related code from the dist-kernel-utils and kernel-install eclasses in a "if has_version "<=sys-kernel/installkernel-gentoo-7";".
    Offloading the initrd/uki generation to installkernel plugins gives
    users the ability to use initrd generators other than dracut. And also
    allows users of manually configured and compiled kernels to
    automatically generate an accompanying initrd/uki if desired (make
    install calls installkernel which can call an initrd/uki plugin if one
    is installed).

    Note that sys-kernel/installkernel-systemd already has a plugin to run
    dracut on kernel installation, installed by sys-kernel/dracut itself, so
    no further changes are required there.

    I'm aware some people have strong feelings about what installkernel
    should and should not do, and what should be automagic and what not.
    I've done my very best to accommodate all needs and concerns, and I
    believe the latest iteration[1] should make everyone happy. Nonetheless,
    I'll give everyone some more time to complain, provided there are no insurmountable objections I'll merge [1] in about 7-10 days and release
    the new version 8 shortly after.

    A follow-up eclass patch that cleans-up the eclasses and drops support
    for <=sys-kernel/installkernel-gentoo-7 will follow later once version 8
    is stable, a sneak-preview of this patch can already be found in my PR[2].

    [1] https://github.com/projg2/installkernel-gentoo/pull/10
    [2] https://github.com/gentoo/gentoo/pull/33727


    From 948a66a862f29b1356e530f95078c48c5bedbae0 Mon Sep 17 00:00:00 2001
    From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
    Date: Wed, 8 Nov 2023 14:46:19 +0100
    Subject: [PATCH] eclass/(dist-)kernel{-utils,-install}: More flexible
    initrd generation

    We only need to call dracut to generate an initrd/uki if we are using <=sys-kernel/installkernel-gentoo-7. sys-kernel/installkernel-systemd
    already calls dracut via its plugin system if it is installed. sys-kernel/installkernel-gentoo-8[dracut] now also contains the code
    required to generate an initrd or uki.

    This change makes it possible for users to use other/custom initrd
    generators with our dist kernels.

    Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
    ---
    eclass/dist-kernel-utils.eclass | 50 ++++++++++++++++++++-------------
    eclass/kernel-install.eclass | 30 ++++++++++++++------
    2 files changed, 52 insertions(+), 28 deletions(-)

    diff --git a/eclass/dist-kernel-utils.eclass
    b/eclass/dist-kernel-utils.eclass
    index 76a2f8d48cdf1..62750d1721a2c 100644
    --- a/eclass/dist-kernel-utils.eclass
    +++ b/eclass/dist-kernel-utils.eclass
    @@ -116,21 +116,23 @@ dist-kernel_install_kernel() {
    local image=${2}
    local map=${3}

    - # if dracut is used in uefi=yes mode, initrd will actually
    - # be a combined kernel+initramfs UEFI executable. we can easily
    - # recognize it by PE magic (vs cpio for a regular initramfs)
    - local initrd=${image%/*}/initrd
    - local magic
    - [[ -s ${initrd} ]] && read -n 2 magic < "${initrd}"
    - if [[ ${magic} == MZ ]]; then
    - einfo "Combined UEFI kernel+initramfs executable found"
    - # install the combined executable in place of kernel
    - image=${initrd%/*}/uki.efi
    - mv "${initrd}" "${image}" || die
    -
    - if [[ $