Merge ~juliank/grub/+git/bionic:initrdless-backport into ~ubuntu-core-dev/grub/+git/bionic:master

Proposed by Julian Andres Klode
Status: Merged
Merged at revision: 2e85288d3ad949263a7c628ca36c9efa12f56d0a
Proposed branch: ~juliank/grub/+git/bionic:initrdless-backport
Merge into: ~ubuntu-core-dev/grub/+git/bionic:master
Diff against target: 368 lines (+323/-1)
6 files modified
debian/changelog (+30/-0)
debian/grub-common.service (+15/-0)
debian/patches/series (+2/-0)
debian/patches/ubuntu-add-initrd-less-boot-fallback.patch (+209/-0)
debian/patches/ubuntu-add-initrd-less-boot-messages.patch (+66/-0)
debian/rules (+1/-1)
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+409352@code.launchpad.net

This proposal supersedes a proposal from 2021-09-29.

To post a comment you must log in.
Revision history for this message
Julian Andres Klode (juliank) wrote :

I think this might miss some service enablement somewhere, the grub-common.service was not enabled upon install from PPA

https://launchpad.net/~ubuntu-uefi-team/+archive/ubuntu/ppa

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 59dd791..ef2fee5 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,33 @@
6+grub2 (2.02-2ubuntu8.24) bionic; urgency=medium
7+
8+ [ Julian Andres Klode ]
9+ * Backport initrd-less fallback support as pre-requisite for other patches
10+ (in LP: #1901553)
11+ - debian/patches/add-initrd-less-boot-fallback.patch: add initrd-less
12+ capabilities. If a kernel fails to boot without initrd, grub will
13+ fallback to trying to boot the kernel with an initrd. Patch by Chris Glass.
14+ * systemd backports:
15+ - Use absolute path to grub-editenv in debian/grub-common.service below to
16+ make bionic systemd happy.
17+ - Pass --with systemd to dh
18+
19+ [ Dimitri John Ledkov ]
20+ * 10_linux: emit messages when initrdless boot is configured, attempted and
21+ fails triggering fallback. LP: #1901553
22+ * grub-common.service: port init.d script to systemd unit. Add warning
23+ message, when initrdless boot fails triggering fallback. LP: #1901553
24+ * debian/grub-common.service: change type to oneshot, add wantedby
25+ sleep.target, after sleep.target. The service will now start after resume
26+ from hybernation. (LP: #1929860)
27+ * grub-initrd-fallback.service: add wantedby sleep.target, after
28+ sleep.target. The service will now start after resume from hybernation.
29+ LP: #1929860
30+ * grub-initrd-fallback.service, debian/grub-common.service: only start units
31+ when booted with grub. Use presence of /boot/grub/grub.cfg as proxy.
32+ LP: #1925507
33+
34+ -- Julian Andres Klode <juliank@ubuntu.com> Wed, 29 Sep 2021 12:53:51 +0200
35+
36 grub2 (2.02-2ubuntu8.23) bionic; urgency=medium
37
38 [ Dimitri John Ledkov & Steve Langasek ]
39diff --git a/debian/grub-common.service b/debian/grub-common.service
40new file mode 100644
41index 0000000..0442534
42--- /dev/null
43+++ b/debian/grub-common.service
44@@ -0,0 +1,15 @@
45+[Unit]
46+Description=Record successful boot for GRUB
47+After=sleep.target
48+ConditionPathExists=/boot/grub/grub.cfg
49+
50+[Service]
51+Type=oneshot
52+Restart=no
53+ExecStartPre=/bin/sh -c '[ -s /boot/grub/grubenv ] || rm -f /boot/grub/grubenv; mkdir -p /boot/grub'
54+ExecStart=/usr/bin/grub-editenv /boot/grub/grubenv unset recordfail
55+ExecStartPost=/bin/sh -c 'if grub-editenv /boot/grub/grubenv list | grep -q initrdless_boot_fallback_triggered=1; then echo "grub: GRUB_FORCE_PARTUUID set, initrdless boot paniced, fallback triggered."; fi'
56+StandardOutput=kmsg
57+
58+[Install]
59+WantedBy=multi-user.target sleep.target
60diff --git a/debian/patches/series b/debian/patches/series
61index 14482ec..e11f826 100644
62--- a/debian/patches/series
63+++ b/debian/patches/series
64@@ -120,3 +120,5 @@ grub-install-backup-and-restore.patch
65 ubuntu-linuxefi-arm64-set-base-addr.patch
66 tftp-rollover-block-counter.patch
67 R_X86_64_PLT32.patch
68+ubuntu-add-initrd-less-boot-fallback.patch
69+ubuntu-add-initrd-less-boot-messages.patch
70diff --git a/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch b/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch
71new file mode 100644
72index 0000000..6518a94
73--- /dev/null
74+++ b/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch
75@@ -0,0 +1,209 @@
76+From: Chris Glass <chris.glass@canonical.com>
77+Date: Fri, 9 Mar 2018 13:47:07 +0100
78+Subject: UBUNTU: Added initrd-less boot capabilities.
79+
80+In case the kernel fails to boot without an initrd, grub will fallback
81+to trying to boot the kernel with an initrd.
82+
83+Signed-off-by: Steve Langasek <steve.langasek@canonical.com>
84+
85+Patch-Name: ubuntu-add-initrd-less-boot-fallback.patch
86+---
87+ Makefile.am | 3 ++
88+ configure.ac | 10 +++++++
89+ grub-initrd-fallback.service | 14 ++++++++++
90+ util/grub.d/00_header.in | 27 ++++++++++++++++++
91+ util/grub.d/10_linux.in | 66 +++++++++++++++++++++++++++++++++++---------
92+ 5 files changed, 107 insertions(+), 13 deletions(-)
93+ create mode 100644 grub-initrd-fallback.service
94+
95+diff --git a/Makefile.am b/Makefile.am
96+index f0ab1ad..aaf2bbf 100644
97+--- a/Makefile.am
98++++ b/Makefile.am
99+@@ -472,4 +472,7 @@ ChangeLog: FORCE
100+ touch $@; \
101+ fi
102+
103++systemdsystemunit_DATA = \
104++ grub-initrd-fallback.service
105++
106+ EXTRA_DIST += ChangeLog ChangeLog-2015
107+diff --git a/configure.ac b/configure.ac
108+index 3fbd7b0..05920c2 100644
109+--- a/configure.ac
110++++ b/configure.ac
111+@@ -287,6 +287,16 @@ AC_SUBST(grubdirname)
112+ AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname",
113+ [Default grub directory name])
114+
115++##### systemd unit files
116++AC_ARG_WITH([systemdsystemunitdir],
117++ AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
118++ [],
119++ [with_systemdsystemunitdir=/usr/lib/systemd/system],
120++ [with_systemdsystemunitdir=no])
121++if test "x$with_systemdsystemunitdir" != xno; then
122++ AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
123++fi
124++
125+ #
126+ # Checks for build programs.
127+ #
128+diff --git a/grub-initrd-fallback.service b/grub-initrd-fallback.service
129+new file mode 100644
130+index 0000000..1a0a4e5
131+--- /dev/null
132++++ b/grub-initrd-fallback.service
133+@@ -0,0 +1,14 @@
134++[Unit]
135++Description=GRUB failed boot detection
136++After=local-fs.target
137++After=grub-common.service
138++After=sleep.target
139++
140++[Service]
141++Type=oneshot
142++ExecStart=/usr/bin/grub-editenv /boot/grub/grubenv unset initrdfail
143++ExecStart=/usr/bin/grub-editenv /boot/grub/grubenv unset prev_entry
144++TimeoutSec=0
145++
146++[Install]
147++WantedBy=multi-user.target rescue.target emergency.target sleep.target
148+diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
149+index b7135b6..2642f66 100644
150+--- a/util/grub.d/00_header.in
151++++ b/util/grub.d/00_header.in
152+@@ -50,6 +50,18 @@ if [ -s \$prefix/grubenv ]; then
153+ load_env
154+ fi
155+ EOF
156++cat <<EOF
157++if [ "\${initrdfail}" = 2 ]; then
158++ set initrdfail=
159++elif [ "\${initrdfail}" = 1 ]; then
160++ set next_entry="\${prev_entry}"
161++ set prev_entry=
162++ save_env prev_entry
163++ if [ "\${next_entry}" ]; then
164++ set initrdfail=2
165++ fi
166++fi
167++EOF
168+ if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
169+ cat <<EOF
170+ if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
171+@@ -101,6 +113,21 @@ function savedefault {
172+ }
173+ EOF
174+
175++cat <<"EOF"
176++function initrdfail {
177++ if [ -n "${have_grubenv}" ]; then if [ -n "${partuuid}" ]; then
178++ if [ -z "${initrdfail}" ]; then
179++ set initrdfail=1
180++ if [ -n "${boot_once}" ]; then
181++ set prev_entry="${default}"
182++ save_env prev_entry
183++ fi
184++ fi
185++ save_env initrdfail
186++ fi; fi
187++}
188++EOF
189++
190+ if [ "$quick_boot" = 1 ]; then
191+ cat <<EOF
192+ function recordfail {
193+diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
194+index 82fd19f..6fe1377 100644
195+--- a/util/grub.d/10_linux.in
196++++ b/util/grub.d/10_linux.in
197+@@ -104,6 +104,10 @@ if [ "$vt_handoff" = 1 ]; then
198+ done
199+ fi
200+
201++if [ x"$GRUB_FORCE_PARTUUID" != x ]; then
202++ echo "set partuuid=${GRUB_FORCE_PARTUUID}"
203++fi
204++
205+ linux_entry ()
206+ {
207+ os="$1"
208+@@ -179,27 +183,63 @@ EOF
209+ linux ${rel_dirname}/${basename}.efi.signed root=${linux_root_device_thisversion} ro ${args}
210+ EOF
211+ else
212+- if [ x"$GRUB_FORCE_PARTUUID" = x ]; then
213++ # We have initrd and PARTUUID is set - we try to boot without initrd, and fallback to using it
214++ # if it fails.
215++ # "panic=-1" means "on panic reboot immediately". "panic=0" disables the reboot behavior.
216++ if [ x"$GRUB_FORCE_PARTUUID" != x ]; then
217++ linux_root_device_thisversion="PARTUUID=${GRUB_FORCE_PARTUUID}"
218++ fi
219++ message="$(gettext_printf "Loading initial ramdisk ...")"
220++ initrd_path=
221++ for i in ${initrd}; do
222++ initrd_path="${initrd_path} ${rel_dirname}/${i}"
223++ done
224++ initrd_path_only_early=
225++ for i in ${initrd_early}; do
226++ initrd_path_only_early="${initrd_path_only_early} ${rel_dirname}/${i}"
227++ done
228++ if test -n "${initrd}" && [ x"$GRUB_FORCE_PARTUUID" != x ]; then
229++ sed "s/^/$submenu_indentation/" << EOF
230++ if [ "\${initrdfail}" = 1 ]; then
231++ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
232++EOF
233++ if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
234++ sed "s/^/$submenu_indentation/" << EOF
235++ echo '$(echo "$message" | grub_quote)'
236++EOF
237++ fi
238++ sed "s/^/$submenu_indentation/" << EOF
239++ initrd $(echo $initrd_path)
240++ else
241++ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} panic=-1
242++EOF
243++ if [ -n "$initrd_path_only_early" ]; then
244++ sed "s/^/$submenu_indentation/" << EOF
245++ initrd $(echo $initrd_path_only_early)
246++EOF
247++ fi
248+ sed "s/^/$submenu_indentation/" << EOF
249+- linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
250++ fi
251++ initrdfail
252+ EOF
253+ else
254++ # We don't have initrd or we don't want to set PARTUUID. Don't try initrd-less boot with fallback.
255+ sed "s/^/$submenu_indentation/" << EOF
256+- linux ${rel_dirname}/${basename} root=PARTUUID=${GRUB_FORCE_PARTUUID} ro ${args}
257++ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
258+ EOF
259+- fi
260+- fi
261+- if test -n "${initrd}" && [ x"$GRUB_DISABLE_INITRD" != xtrue ]; then
262+- # TRANSLATORS: ramdisk isn't identifier. Should be translated.
263+- if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
264+- message="$(gettext_printf "Loading initial ramdisk ...")"
265+- sed "s/^/$submenu_indentation/" << EOF
266++ if test -n "${initrd}"; then
267++ # We do have initrd - let's use it at boot.
268++ # TRANSLATORS: ramdisk isn't identifier. Should be translated.
269++ if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
270++ sed "s/^/$submenu_indentation/" << EOF
271+ echo '$(echo "$message" | grub_quote)'
272+ EOF
273+- fi
274+- sed "s/^/$submenu_indentation/" << EOF
275+- initrd ${rel_dirname}/${initrd}
276++ fi
277++ sed "s/^/$submenu_indentation/" << EOF
278++ initrd $(echo $initrd_path)
279+ EOF
280++ fi
281++ fi
282+ fi
283+ sed "s/^/$submenu_indentation/" << EOF
284+ }
285diff --git a/debian/patches/ubuntu-add-initrd-less-boot-messages.patch b/debian/patches/ubuntu-add-initrd-less-boot-messages.patch
286new file mode 100644
287index 0000000..2dbd7e6
288--- /dev/null
289+++ b/debian/patches/ubuntu-add-initrd-less-boot-messages.patch
290@@ -0,0 +1,66 @@
291+From: Dimitri John Ledkov <xnox@ubuntu.com>
292+Date: Mon, 26 Oct 2020 11:38:34 +0000
293+Subject: Ubuntu: add initrd-less-boot informational messages
294+
295+Add additional messages when initrd-less boot is attempted or
296+fails. As otherwise it is not obvious why boot seems to panic and
297+reboot by default.
298+---
299+ grub-initrd-fallback.service | 1 +
300+ util/grub.d/10_linux.in | 10 ++++++++++
301+ 2 files changed, 11 insertions(+)
302+
303+diff --git a/grub-initrd-fallback.service b/grub-initrd-fallback.service
304+index 1a0a4e5..59d1a62 100644
305+--- a/grub-initrd-fallback.service
306++++ b/grub-initrd-fallback.service
307+@@ -3,6 +3,7 @@ Description=GRUB failed boot detection
308+ After=local-fs.target
309+ After=grub-common.service
310+ After=sleep.target
311++ConditionPathExists=/boot/grub/grub.cfg
312+
313+ [Service]
314+ Type=oneshot
315+diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
316+index 6fe1377..3eeda4e 100644
317+--- a/util/grub.d/10_linux.in
318++++ b/util/grub.d/10_linux.in
319+@@ -105,6 +105,12 @@ if [ "$vt_handoff" = 1 ]; then
320+ fi
321+
322+ if [ x"$GRUB_FORCE_PARTUUID" != x ]; then
323++ gettext_printf "GRUB_FORCE_PARTUUID is set, will attempt initrdless boot\n" >&2
324++ cat << EOF
325++#
326++# GRUB_FORCE_PARTUUID is set, will attempt initrdless boot
327++# Upon panic fallback to booting with initrd
328++EOF
329+ echo "set partuuid=${GRUB_FORCE_PARTUUID}"
330+ fi
331+
332+@@ -190,6 +196,8 @@ EOF
333+ linux_root_device_thisversion="PARTUUID=${GRUB_FORCE_PARTUUID}"
334+ fi
335+ message="$(gettext_printf "Loading initial ramdisk ...")"
336++ initrdlessfail_msg="$(gettext_printf "GRUB_FORCE_PARTUUID set, initrdless boot failed. Attempting with initrd.")"
337++ initrdlesstry_msg="$(gettext_printf "GRUB_FORCE_PARTUUID set, attempting initrdless boot.")"
338+ initrd_path=
339+ for i in ${initrd}; do
340+ initrd_path="${initrd_path} ${rel_dirname}/${i}"
341+@@ -201,6 +209,7 @@ EOF
342+ if test -n "${initrd}" && [ x"$GRUB_FORCE_PARTUUID" != x ]; then
343+ sed "s/^/$submenu_indentation/" << EOF
344+ if [ "\${initrdfail}" = 1 ]; then
345++ echo '$(echo "$initrdlessfail_msg" | grub_quote)'
346+ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
347+ EOF
348+ if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
349+@@ -211,6 +220,7 @@ EOF
350+ sed "s/^/$submenu_indentation/" << EOF
351+ initrd $(echo $initrd_path)
352+ else
353++ echo '$(echo "$initrdlesstry_msg" | grub_quote)'
354+ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} panic=-1
355+ EOF
356+ if [ -n "$initrd_path_only_early" ]; then
357diff --git a/debian/rules b/debian/rules
358index 41b72e4..ef83834 100755
359--- a/debian/rules
360+++ b/debian/rules
361@@ -115,7 +115,7 @@ endif
362 endif
363
364 %:
365- dh $@ --parallel
366+ dh $@ --with systemd --parallel
367
368 override_dh_auto_configure: $(patsubst %,configure/%,$(BUILD_PACKAGES))
369

Subscribers

People subscribed via source and target branches