add deprecated sys-boot/grub:0
[portage-squeep] / sys-boot / grub / files / 2.02-multiple-early-initrd.patch
1 From a698240df0c43278b2d1d7259c8e7a6926c63112 Mon Sep 17 00:00:00 2001
2 From: "Matthew S. Turnbull" <sparky@bluefang-logic.com>
3 Date: Sat, 24 Feb 2018 17:44:58 -0500
4 Subject: grub-mkconfig/10_linux: Support multiple early initrd images
5
6 Add support for multiple, shared, early initrd images. These early
7 images will be loaded in the order declared, and all will be loaded
8 before the initrd image.
9
10 While many classes of data can be provided by early images, the
11 immediate use case would be for distributions to provide CPU
12 microcode to mitigate the Meltdown and Spectre vulnerabilities.
13
14 There are two environment variables provided for declaring the early
15 images.
16
17 * GRUB_EARLY_INITRD_LINUX_STOCK is for the distribution declare
18 images that are provided by the distribution or installed packages.
19 If undeclared, this will default to a set of common microcode image
20 names.
21
22 * GRUB_EARLY_INITRD_LINUX_CUSTOM is for user created images. User
23 images will be loaded after the stock images.
24
25 These separate configurations allow the distribution and user to
26 declare different image sets without clobbering each other.
27
28 This also makes a minor update to ensure that UUID partition labels
29 stay disabled when no initrd image is found, even if early images are
30 present.
31
32 This is a continuation of a previous patch published by Christian
33 Hesse in 2016:
34 http://lists.gnu.org/archive/html/grub-devel/2016-02/msg00025.html
35
36 Down stream Gentoo bug:
37 https://bugs.gentoo.org/645088
38
39 Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
40 Signed-off-by: Matthew S. Turnbull <sparky@bluefang-logic.com>
41 Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
42 ---
43 docs/grub.texi | 19 +++++++++++++++++++
44 util/grub-mkconfig.in | 8 ++++++++
45 util/grub.d/10_linux.in | 33 +++++++++++++++++++++++++++------
46 3 files changed, 54 insertions(+), 6 deletions(-)
47
48 diff --git a/docs/grub.texi b/docs/grub.texi
49 index 137b894..65b4bbe 100644
50 --- a/docs/grub.texi
51 +++ b/docs/grub.texi
52 @@ -1398,6 +1398,25 @@ for all respectively normal entries.
53 The values of these options replace the values of @samp{GRUB_CMDLINE_LINUX}
54 and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux and Xen menu entries.
55
56 +@item GRUB_EARLY_INITRD_LINUX_CUSTOM
57 +@itemx GRUB_EARLY_INITRD_LINUX_STOCK
58 +List of space-separated early initrd images to be loaded from @samp{/boot}.
59 +This is for loading things like CPU microcode, firmware, ACPI tables, crypto
60 +keys, and so on. These early images will be loaded in the order declared,
61 +and all will be loaded before the actual functional initrd image.
62 +
63 +@samp{GRUB_EARLY_INITRD_LINUX_STOCK} is for your distribution to declare
64 +images that are provided by the distribution. It should not be modified
65 +without understanding the consequences. They will be loaded first.
66 +
67 +@samp{GRUB_EARLY_INITRD_LINUX_CUSTOM} is for your custom created images.
68 +
69 +The default stock images are as follows, though they may be overridden by
70 +your distribution:
71 +@example
72 +intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode.cpio
73 +@end example
74 +
75 @item GRUB_DISABLE_LINUX_UUID
76 Normally, @command{grub-mkconfig} will generate menu entries that use
77 universally-unique identifiers (UUIDs) to identify the root filesystem to
78 diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
79 index f8496d2..35ef583 100644
80 --- a/util/grub-mkconfig.in
81 +++ b/util/grub-mkconfig.in
82 @@ -147,6 +147,12 @@ if [ x"$GRUB_FS" = xunknown ]; then
83 GRUB_FS="$(stat -f --printf=%T / || echo unknown)"
84 fi
85
86 +# Provide a default set of stock linux early initrd images.
87 +# Define here so the list can be modified in the sourced config file.
88 +if [ "x${GRUB_EARLY_INITRD_LINUX_STOCK}" = "x" ]; then
89 + GRUB_EARLY_INITRD_LINUX_STOCK="intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode.cpio"
90 +fi
91 +
92 if test -f ${sysconfdir}/default/grub ; then
93 . ${sysconfdir}/default/grub
94 fi
95 @@ -211,6 +217,8 @@ export GRUB_DEFAULT \
96 GRUB_CMDLINE_NETBSD \
97 GRUB_CMDLINE_NETBSD_DEFAULT \
98 GRUB_CMDLINE_GNUMACH \
99 + GRUB_EARLY_INITRD_LINUX_CUSTOM \
100 + GRUB_EARLY_INITRD_LINUX_STOCK \
101 GRUB_TERMINAL_INPUT \
102 GRUB_TERMINAL_OUTPUT \
103 GRUB_SERIAL_COMMAND \
104 diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
105 index de9044c..faedf74 100644
106 --- a/util/grub.d/10_linux.in
107 +++ b/util/grub.d/10_linux.in
108 @@ -136,9 +136,13 @@ EOF
109 if test -n "${initrd}" ; then
110 # TRANSLATORS: ramdisk isn't identifier. Should be translated.
111 message="$(gettext_printf "Loading initial ramdisk ...")"
112 + initrd_path=
113 + for i in ${initrd}; do
114 + initrd_path="${initrd_path} ${rel_dirname}/${i}"
115 + done
116 sed "s/^/$submenu_indentation/" << EOF
117 echo '$(echo "$message" | grub_quote)'
118 - initrd ${rel_dirname}/${initrd}
119 + initrd $(echo $initrd_path)
120 EOF
121 fi
122 sed "s/^/$submenu_indentation/" << EOF
123 @@ -188,7 +192,15 @@ while [ "x$list" != "x" ] ; do
124 alt_version=`echo $version | sed -e "s,\.old$,,g"`
125 linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
126
127 - initrd=
128 + initrd_early=
129 + for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
130 + ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
131 + if test -e "${dirname}/${i}" ; then
132 + initrd_early="${initrd_early} ${i}"
133 + fi
134 + done
135 +
136 + initrd_real=
137 for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
138 "initrd-${version}" "initramfs-${version}.img" \
139 "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
140 @@ -198,11 +210,22 @@ while [ "x$list" != "x" ] ; do
141 "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
142 "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
143 if test -e "${dirname}/${i}" ; then
144 - initrd="$i"
145 + initrd_real="${i}"
146 break
147 fi
148 done
149
150 + initrd=
151 + if test -n "${initrd_early}" || test -n "${initrd_real}"; then
152 + initrd="${initrd_early} ${initrd_real}"
153 +
154 + initrd_display=
155 + for i in ${initrd}; do
156 + initrd_display="${initrd_display} ${dirname}/${i}"
157 + done
158 + gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
159 + fi
160 +
161 config=
162 for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
163 if test -e "${i}" ; then
164 @@ -216,9 +239,7 @@ while [ "x$list" != "x" ] ; do
165 initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
166 fi
167
168 - if test -n "${initrd}" ; then
169 - gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
170 - elif test -z "${initramfs}" ; then
171 + if test -z "${initramfs}" && test -z "${initrd_real}" ; then
172 # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
173 # no initrd or builtin initramfs, it can't work here.
174 linux_root_device_thisversion=${GRUB_DEVICE}
175 --
176 cgit v1.0-41-gc330
177