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
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.
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.
14 There are two environment variables provided for declaring the early
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
22 * GRUB_EARLY_INITRD_LINUX_CUSTOM is for user created images. User
23 images will be loaded after the stock images.
25 These separate configurations allow the distribution and user to
26 declare different image sets without clobbering each other.
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
32 This is a continuation of a previous patch published by Christian
34 http://lists.gnu.org/archive/html/grub-devel/2016-02/msg00025.html
36 Down stream Gentoo bug:
37 https://bugs.gentoo.org/645088
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>
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(-)
48 diff --git a/docs/grub.texi b/docs/grub.texi
49 index 137b894..65b4bbe 100644
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.
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.
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.
67 +@samp{GRUB_EARLY_INITRD_LINUX_CUSTOM} is for your custom created images.
69 +The default stock images are as follows, though they may be overridden by
72 +intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode.cpio
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)"
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"
92 if test -f ${sysconfdir}/default/grub ; then
93 . ${sysconfdir}/default/grub
95 @@ -211,6 +217,8 @@ export GRUB_DEFAULT \
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 ...")"
113 + for i in ${initrd}; do
114 + initrd_path="${initrd_path} ${rel_dirname}/${i}"
116 sed "s/^/$submenu_indentation/" << EOF
117 echo '$(echo "$message" | grub_quote)'
118 - initrd ${rel_dirname}/${initrd}
119 + initrd $(echo $initrd_path)
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}"
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}"
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
151 + if test -n "${initrd_early}" || test -n "${initrd_real}"; then
152 + initrd="${initrd_early} ${initrd_real}"
155 + for i in ${initrd}; do
156 + initrd_display="${initrd_display} ${dirname}/${i}"
158 + gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
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 \"`
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}