From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 2492A158099 for ; Mon, 27 Nov 2023 09:17:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B2F642BC05F; Mon, 27 Nov 2023 09:17:18 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3B8CC2BC02C for ; Mon, 27 Nov 2023 09:17:18 +0000 (UTC) Message-ID: <54e6d0f8-a229-48fb-871e-036dcf75c012@gentoo.org> Date: Mon, 27 Nov 2023 10:17:14 +0100 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US, nl-NL To: gentoo-dev@lists.gentoo.org From: Andrew Ammerlaan Subject: [gentoo-dev] [PATCH] eclass/(dist-)kernel{-utils,-install}: More flexible initrd generation Autocrypt: addr=andrewammerlaan@gentoo.org; keydata= xsBNBF3n3cUBCAC6uoDZ0XzaO29l8AzUblXQ5rxZI7nbGEnfFqjEQCK3oEXxsDa9Ez1myx3M ir53Vyx64Iz1Bq/TOS/PttgguPpiLggCpTTD2vavp5SwFmg272+P8bUJVJF2mMRm0OR/YPiA B5dNfcoLqKIj+ZMOtrZ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2CRAJY7la7TSv1lTD1cAEQEAAcLAfAQYAQgAJgIbDBYhBAb/U0G9gF2wvH0HpqGfY2zU7bzR BQJlNiHABQkJL3d7AAoJEKGfY2zU7bzRjDwH/1fp/87km2YYVgrfP1aWLjAA/TwcEVycRJQQ S9Q6xuzgD5AYhjzBSONoN46cwf+gla6xndY0lCawsZN7whtJ/DhqSZEfL0HgHkJ6T8FCXexf n1s6XmIAxqIrMmfsuOkAPLJIHzAAGzQX8DXcRSj1cIDUpa1Uy7ncVvI4EzJBRtJVJXIbl+53 NGauXU8ZuprPYkMSPuW3eHATFc0F5DhmlFUXh+HYYK+2QTO73TENMhngkrYcw63je5bRp/+f 72XFKlf1gXHK1ivg8nYueyUfrxZTBGKagusOiQeOao2I1uYcHoFhPYJrQWePMyZiYyB6PR0K DR4B/Ulo3v0eBXaaYzo= Organization: Gentoo Linux Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Archives-Salt: 6fdb3296-b7e5-4e0c-a599-730c2ea140e6 X-Archives-Hash: 412a9879392412008b183bb5b4be2ccb 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 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 --- 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 [[ ${KERNEL_IUSE_SECUREBOOT} ]]; then - # Ensure the uki is signed if dracut hasn't already done so. - secureboot_sign_efi_file "${image}" + if has_version "<=sys-kernel/installkernel-gentoo-7"; then + # 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 [[ ${KERNEL_IUSE_SECUREBOOT} ]]; then + # Ensure the uki is signed if dracut hasn't already done so. + secureboot_sign_efi_file "${image}" + fi fi fi @@ -150,6 +152,10 @@ dist-kernel_install_kernel() { # The function will determine whether is actually # a dist-kernel, and whether initramfs was used. # +# With sys-kernel/installkernel-systemd, or version 8 or greater of +# sys-kernel/installkernel-gentoo, the generation of the initrd via dracut +# is handled by kernel-install instead. +# # This function is to be used in pkg_postinst() of ebuilds installing # kernel modules that are included in the initramfs. dist-kernel_reinstall_initramfs() { @@ -160,19 +166,23 @@ dist-kernel_reinstall_initramfs() { local ver=${2} local image_path=${kernel_dir}/$(dist-kernel_get_image_path) - local initramfs_path=${image_path%/*}/initrd if [[ ! -f ${image_path} ]]; then eerror "Kernel install missing, image not found:" eerror " ${image_path}" eerror "Initramfs will not be updated. Please reinstall your kernel." return fi - if [[ ! -f ${initramfs_path} && ! -f ${initramfs_path%/*}/uki.efi ]]; then - einfo "No initramfs or uki found at ${image_path}" - return + + if has_version "<=sys-kernel/installkernel-gentoo-7"; then + local initramfs_path=${image_path%/*}/initrd + if [[ ! -f ${initramfs_path} && ! -f ${initramfs_path%/*}/uki.efi ]]; then + einfo "No initramfs or uki found at ${image_path}" + return + fi + + dist-kernel_build_initramfs "${initramfs_path}" "${ver}" fi - dist-kernel_build_initramfs "${initramfs_path}" "${ver}" dist-kernel_install_kernel "${ver}" "${image_path}" \ "${kernel_dir}/System.map" } diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass index a0eceae8280bb..b4d84f3986c0d 100644 --- a/eclass/kernel-install.eclass +++ b/eclass/kernel-install.eclass @@ -48,11 +48,21 @@ RESTRICT+=" # note: we need installkernel with initramfs support! IDEPEND=" - || ( - sys-kernel/installkernel-gentoo - sys-kernel/installkernel-systemd + !initramfs? ( + || ( + sys-kernel/installkernel-gentoo + sys-kernel/installkernel-systemd + ) ) - initramfs? ( >=sys-kernel/dracut-059-r4 )" + initramfs? ( + >=sys-kernel/dracut-059-r4 + || ( + <=sys-kernel/installkernel-gentoo-7 + >=sys-kernel/installkernel-gentoo-8[dracut(-)] + sys-kernel/installkernel-systemd + ) + ) +" # needed by objtool that is installed along with the kernel and used # to build external modules # NB: linux-mod.eclass also adds this dep but it's cleaner to have @@ -429,9 +439,13 @@ kernel-install_pkg_preinst() { # @FUNCTION: kernel-install_install_all # @USAGE: # @DESCRIPTION: -# Build an initramfs for the kernel and install the kernel. This is -# called from pkg_postinst() and pkg_config(). is the full -# kernel version. +# Build an initramfs for the kernel if required and install the kernel. +# This is called from pkg_postinst() and pkg_config(). is the +# full kernel version. +# +# With sys-kernel/installkernel-systemd, or version 8 or greater of +# sys-kernel/installkernel-gentoo, the generation of the initrd via dracut +# is handled by kernel-install instead. kernel-install_install_all() { debug-print-function ${FUNCNAME} "${@}" @@ -448,7 +462,7 @@ kernel-install_install_all() { nonfatal mount-boot_check_status || break local image_path=$(dist-kernel_get_image_path) - if use initramfs; then + if use initramfs && has_version "<=sys-kernel/installkernel-gentoo-7"; then # putting it alongside kernel image as 'initrd' makes # kernel-install happier nonfatal dist-kernel_build_initramfs \