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 841F3158013 for ; Tue, 5 Dec 2023 10:27:55 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6E0F52BC019; Tue, 5 Dec 2023 10:27:54 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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 52B902BC019 for ; Tue, 5 Dec 2023 10:27:54 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (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 smtp.gentoo.org (Postfix) with ESMTPS id 81550335DCC for ; Tue, 5 Dec 2023 10:27:53 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 984221192 for ; Tue, 5 Dec 2023 10:27:51 +0000 (UTC) From: "Andrew Ammerlaan" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Andrew Ammerlaan" Message-ID: <1701772061.db0195c3d66fc9ca1ee966b2177b2174a7d7bd02.andrewammerlaan@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/dist-kernel-utils.eclass eclass/kernel-install.eclass X-VCS-Directories: eclass/ X-VCS-Committer: andrewammerlaan X-VCS-Committer-Name: Andrew Ammerlaan X-VCS-Revision: db0195c3d66fc9ca1ee966b2177b2174a7d7bd02 X-VCS-Branch: master Date: Tue, 5 Dec 2023 10:27:51 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 0bbbd350-432f-45d5-855c-b6fce0af8195 X-Archives-Hash: 4cf098a006f92f8f26d030ff8e4e00f7 commit: db0195c3d66fc9ca1ee966b2177b2174a7d7bd02 Author: Andrew Ammerlaan gentoo org> AuthorDate: Wed Nov 8 13:46:19 2023 +0000 Commit: Andrew Ammerlaan gentoo org> CommitDate: Tue Dec 5 10:27:41 2023 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=db0195c3 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 if they are using installkernel-systemd. Signed-off-by: Andrew Ammerlaan 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 76a2f8d48cdf..62750d1721a2 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 a0eceae8280b..b4d84f3986c0 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 \