Gentoo Archives: gentoo-dev

From: Matthew Thode <prometheanfire@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 5/6] dist-kernel-utils.eclass: Support dracut's uefi=yes option
Date: Wed, 13 Jan 2021 17:47:45
Message-Id: 20210113174737.acsrytyyqcdyvljo@gentoo.org
In Reply to: [gentoo-dev] [PATCH 5/6] dist-kernel-utils.eclass: Support dracut's uefi=yes option by "Michał Górny"
1 On 21-01-13 15:35:15, Michał Górny wrote:
2 > Support dracut's uefi=yes configuration option that creates a combined
3 > UEFI stub, kernel and initramfs in a single UEFI executable. If such
4 > an output is detected, install it in place of the actual kernel image
5 > and stub out the duplicate initrd to save space.
6 >
7 > Signed-off-by: Michał Górny <mgorny@g.o>
8 > ---
9 > eclass/dist-kernel-utils.eclass | 31 ++++++++++++++++++++++++++++++-
10 > 1 file changed, 30 insertions(+), 1 deletion(-)
11 >
12 > diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
13 > index d65dc0924b40..50ad15f8b1fd 100644
14 > --- a/eclass/dist-kernel-utils.eclass
15 > +++ b/eclass/dist-kernel-utils.eclass
16 > @@ -41,8 +41,20 @@ dist-kernel_build_initramfs() {
17 > local output=${1}
18 > local version=${2}
19 >
20 > + local rel_image_path=$(dist-kernel_get_image_path)
21 > + local image=${output%/*}/${rel_image_path##*/}
22 > +
23 > + local args=(
24 > + --force
25 > + # if uefi=yes is used, dracut needs to locate the kernel image
26 > + --kernel-image "${image}"
27 > +
28 > + # positional arguments
29 > + "${output}" "${version}"
30 > + )
31 > +
32 > ebegin "Building initramfs via dracut"
33 > - dracut --force "${output}" "${version}"
34 > + dracut "${args[@]}"
35 > eend ${?} || die -n "Building initramfs failed"
36 > }
37 >
38 > @@ -85,6 +97,23 @@ dist-kernel_install_kernel() {
39 > local image=${2}
40 > local map=${3}
41 >
42 > + # if dracut is used in eufi=yes mode, initrd will actually
43 > + # be a combined kernel+initramfs UEFI executable. we can easily
44 > + # recognize it by PE magic (vs cpio for a regular initramfs)
45 > + local initrd=${image%/*}/initrd
46 > + local magic
47 > + [[ -s ${initrd} ]] && read -n 2 magic < "${initrd}"
48 > + if [[ ${magic} == MZ ]]; then
49
50 This magic header is matched by both the kernel and the new uefi
51 executible. I think a better check would be...
52
53 if file "${image_path}" | grep -q 'EFI application'; then
54
55 > + einfo "Combined UEFI kernel+initramfs executable found"
56 > + # install the combined executable in place of kernel
57 > + image=${initrd}.uefi
58 > + mv "${initrd}" "${image}" || die
59 > + # put an empty file in place of initrd. installing a duplicate
60 > + # file would waste disk space, and removing it entirely provokes
61 > + # kernel-install to regenerate it via dracut.
62 > + > "${initrd}"
63 > + fi
64 > +
65 > ebegin "Installing the kernel via installkernel"
66 > # note: .config is taken relatively to System.map;
67 > # initrd relatively to bzImage
68 > --
69 > 2.30.0
70
71 I want to make sure you are not overwriting the original kernel image,
72 if you do then subsiquent --config runs will include the kernel image,
73 making the final image grow.
74
75 In order to avoid that I did some file juggling, but it looks like it's
76 cleaner here.
77
78 https://gist.github.com/prometheanfire/aeffa1c3f92d3d2af312b3b6915051fb
79 'worked' but was kinda unclean.
80
81
82 --
83 Matthew Thode (prometheanfire)

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies