Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 5/6] dist-kernel-utils.eclass: Support dracut's uefi=yes option
Date: Wed, 13 Jan 2021 14:37:17
Message-Id: 20210113143516.1766-6-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 0/6] kernel-install.eclass: dracut uefi=yes support + improved error handling by "Michał Górny"
1 Support dracut's uefi=yes configuration option that creates a combined
2 UEFI stub, kernel and initramfs in a single UEFI executable. If such
3 an output is detected, install it in place of the actual kernel image
4 and stub out the duplicate initrd to save space.
5
6 Signed-off-by: Michał Górny <mgorny@g.o>
7 ---
8 eclass/dist-kernel-utils.eclass | 31 ++++++++++++++++++++++++++++++-
9 1 file changed, 30 insertions(+), 1 deletion(-)
10
11 diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
12 index d65dc0924b40..50ad15f8b1fd 100644
13 --- a/eclass/dist-kernel-utils.eclass
14 +++ b/eclass/dist-kernel-utils.eclass
15 @@ -41,8 +41,20 @@ dist-kernel_build_initramfs() {
16 local output=${1}
17 local version=${2}
18
19 + local rel_image_path=$(dist-kernel_get_image_path)
20 + local image=${output%/*}/${rel_image_path##*/}
21 +
22 + local args=(
23 + --force
24 + # if uefi=yes is used, dracut needs to locate the kernel image
25 + --kernel-image "${image}"
26 +
27 + # positional arguments
28 + "${output}" "${version}"
29 + )
30 +
31 ebegin "Building initramfs via dracut"
32 - dracut --force "${output}" "${version}"
33 + dracut "${args[@]}"
34 eend ${?} || die -n "Building initramfs failed"
35 }
36
37 @@ -85,6 +97,23 @@ dist-kernel_install_kernel() {
38 local image=${2}
39 local map=${3}
40
41 + # if dracut is used in eufi=yes mode, initrd will actually
42 + # be a combined kernel+initramfs UEFI executable. we can easily
43 + # recognize it by PE magic (vs cpio for a regular initramfs)
44 + local initrd=${image%/*}/initrd
45 + local magic
46 + [[ -s ${initrd} ]] && read -n 2 magic < "${initrd}"
47 + if [[ ${magic} == MZ ]]; then
48 + einfo "Combined UEFI kernel+initramfs executable found"
49 + # install the combined executable in place of kernel
50 + image=${initrd}.uefi
51 + mv "${initrd}" "${image}" || die
52 + # put an empty file in place of initrd. installing a duplicate
53 + # file would waste disk space, and removing it entirely provokes
54 + # kernel-install to regenerate it via dracut.
55 + > "${initrd}"
56 + fi
57 +
58 ebegin "Installing the kernel via installkernel"
59 # note: .config is taken relatively to System.map;
60 # initrd relatively to bzImage
61 --
62 2.30.0

Replies