Merge ~ubuntu-core-dev/grub/+git/ubuntu:fresh-initrd-less-boot into ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu

Proposed by Łukasz Zemczak
Status: Merged
Merge reported by: Mathieu Trudel-Lapierre
Merged at revision: 17de3728e3656c78ff18885495cef5a44946f4ed
Proposed branch: ~ubuntu-core-dev/grub/+git/ubuntu:fresh-initrd-less-boot
Merge into: ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu
Diff against target: 421 lines (+290/-15)
10 files modified
Makefile.am (+3/-0)
configure.ac (+10/-0)
debian/.git-dpm (+2/-2)
debian/control (+1/-0)
debian/patches/add-initrd-less-boot-fallback.patch (+194/-0)
debian/patches/series (+1/-0)
debian/rules (+1/-1)
grub-initrd-fallback.service (+13/-0)
util/grub.d/00_header.in (+27/-0)
util/grub.d/10_linux.in (+38/-12)
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+355456@code.launchpad.net

Description of the change

Support for automatically trying to boot Linux without an initramfs, and automatically falling back to a boot with initramfs, in cases that we can detect that the kernel may not need an initramfs in order to resolve the root disk name.

This is a cleaned-up version of Steve's and Chris's branch: https://code.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/+merge/341272

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile.am b/Makefile.am
2index b47b4b1..d6d8b09 100644
3--- a/Makefile.am
4+++ b/Makefile.am
5@@ -472,4 +472,7 @@ ChangeLog: FORCE
6 touch $@; \
7 fi
8
9+systemdsystemunit_DATA = \
10+ grub-initrd-fallback.service
11+
12 EXTRA_DIST += ChangeLog ChangeLog-2015
13diff --git a/configure.ac b/configure.ac
14index f102b70..bf7335a 100644
15--- a/configure.ac
16+++ b/configure.ac
17@@ -291,6 +291,16 @@ AC_SUBST(grubdirname)
18 AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname",
19 [Default grub directory name])
20
21+##### systemd unit files
22+AC_ARG_WITH([systemdsystemunitdir],
23+ AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
24+ [],
25+ [with_systemdsystemunitdir=/usr/lib/systemd/system],
26+ [with_systemdsystemunitdir=no])
27+if test "x$with_systemdsystemunitdir" != xno; then
28+ AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
29+fi
30+
31 #
32 # Checks for build programs.
33 #
34diff --git a/debian/.git-dpm b/debian/.git-dpm
35index 95ac429..d05a4d6 100644
36--- a/debian/.git-dpm
37+++ b/debian/.git-dpm
38@@ -1,6 +1,6 @@
39 # see git-dpm(1) from git-dpm package
40-bfe7c890db05f79d34752498991b5e40bc11e263
41-bfe7c890db05f79d34752498991b5e40bc11e263
42+55c1502e2697605a5532b04ca32df2f06b8eeb53
43+55c1502e2697605a5532b04ca32df2f06b8eeb53
44 59aeb1cfaa3d5bfd7bbeeee0f0d37f6d9eed51fe
45 59aeb1cfaa3d5bfd7bbeeee0f0d37f6d9eed51fe
46 grub2_2.02+dfsg1.orig.tar.xz
47diff --git a/debian/control b/debian/control
48index ce7d53b..56ccf93 100644
49--- a/debian/control
50+++ b/debian/control
51@@ -7,6 +7,7 @@ Uploaders: Felix Zielcke <fzielcke@z-51.de>, Jordi Mallach <jordi@debian.org>, C
52 Build-Depends: debhelper (>= 7.4.2~),
53 patchutils,
54 dh-autoreconf,
55+ dh-systemd,
56 automake,
57 python,
58 flex,
59diff --git a/debian/patches/add-initrd-less-boot-fallback.patch b/debian/patches/add-initrd-less-boot-fallback.patch
60new file mode 100644
61index 0000000..9f499bf
62--- /dev/null
63+++ b/debian/patches/add-initrd-less-boot-fallback.patch
64@@ -0,0 +1,194 @@
65+From 55c1502e2697605a5532b04ca32df2f06b8eeb53 Mon Sep 17 00:00:00 2001
66+From: Chris Glass <chris.glass@canonical.com>
67+Date: Fri, 9 Mar 2018 13:47:07 +0100
68+Subject: Added initrd-less boot capabilities.
69+
70+In case the kernel fails to boot without an initrd, grub will fallback
71+to trying to boot the kernel with an initrd.
72+
73+Signed-off-by: Steve Langasek <steve.langasek@canonical.com>
74+
75+Patch-Name: add-initrd-less-boot-fallback.patch
76+---
77+ Makefile.am | 3 +++
78+ configure.ac | 10 ++++++++
79+ grub-initrd-fallback.service | 13 ++++++++++
80+ util/grub.d/00_header.in | 27 +++++++++++++++++++
81+ util/grub.d/10_linux.in | 50 +++++++++++++++++++++++++++---------
82+ 5 files changed, 91 insertions(+), 12 deletions(-)
83+ create mode 100644 grub-initrd-fallback.service
84+
85+diff --git a/Makefile.am b/Makefile.am
86+index b47b4b1ac..d6d8b0966 100644
87+--- a/Makefile.am
88++++ b/Makefile.am
89+@@ -472,4 +472,7 @@ ChangeLog: FORCE
90+ touch $@; \
91+ fi
92+
93++systemdsystemunit_DATA = \
94++ grub-initrd-fallback.service
95++
96+ EXTRA_DIST += ChangeLog ChangeLog-2015
97+diff --git a/configure.ac b/configure.ac
98+index f102b7024..bf7335af8 100644
99+--- a/configure.ac
100++++ b/configure.ac
101+@@ -291,6 +291,16 @@ AC_SUBST(grubdirname)
102+ AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname",
103+ [Default grub directory name])
104+
105++##### systemd unit files
106++AC_ARG_WITH([systemdsystemunitdir],
107++ AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
108++ [],
109++ [with_systemdsystemunitdir=/usr/lib/systemd/system],
110++ [with_systemdsystemunitdir=no])
111++if test "x$with_systemdsystemunitdir" != xno; then
112++ AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
113++fi
114++
115+ #
116+ # Checks for build programs.
117+ #
118+diff --git a/grub-initrd-fallback.service b/grub-initrd-fallback.service
119+new file mode 100644
120+index 000000000..258853800
121+--- /dev/null
122++++ b/grub-initrd-fallback.service
123+@@ -0,0 +1,13 @@
124++[Unit]
125++Description=GRUB failed boot detection
126++DefaultDependencies=no
127++After=local-fs.target
128++
129++[Service]
130++Type=oneshot
131++ExecStart=/usr/bin/grub-editenv /boot/grub/grubenv unset initrdfail
132++ExecStart=/usr/bin/grub-editenv /boot/grub/grubenv unset prev_entry
133++TimeoutSec=0
134++
135++[Install]
136++WantedBy=sysinit.target
137+diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
138+index 674a76140..23322458a 100644
139+--- a/util/grub.d/00_header.in
140++++ b/util/grub.d/00_header.in
141+@@ -50,6 +50,18 @@ if [ -s \$prefix/grubenv ]; then
142+ load_env
143+ fi
144+ EOF
145++cat <<EOF
146++if [ "\${initrdfail}" = 2 ]; then
147++ set initrdfail=
148++elif [ "\${initrdfail}" = 1 ]; then
149++ set next_entry="\${prev_entry}"
150++ set prev_entry=
151++ save_env prev_entry
152++ if [ "\${next_entry}" ]; then
153++ set initrdfail=2
154++ fi
155++fi
156++EOF
157+ if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
158+ cat <<EOF
159+ if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
160+@@ -101,6 +113,21 @@ function savedefault {
161+ }
162+ EOF
163+
164++cat <<"EOF"
165++function initrdfail {
166++ if [ -n "${have_grubenv}" ]; then if [ -n "${partuuid}" ]; then
167++ if [ -z "${initrdfail}" ]; then
168++ set initrdfail=1
169++ if [ -n "${boot_once}" ]; then
170++ set prev_entry="${default}"
171++ save_env prev_entry
172++ fi
173++ fi
174++ save_env initrdfail
175++ fi; fi
176++}
177++EOF
178++
179+ if [ "$quick_boot" = 1 ]; then
180+ cat <<EOF
181+ function recordfail {
182+diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
183+index 76d4f31bf..01d96f5d0 100644
184+--- a/util/grub.d/10_linux.in
185++++ b/util/grub.d/10_linux.in
186+@@ -104,6 +104,10 @@ if [ "$vt_handoff" = 1 ]; then
187+ done
188+ fi
189+
190++if [ x"$GRUB_FORCE_PARTUUID" != x ]; then
191++ echo "set partuuid=${GRUB_FORCE_PARTUUID}"
192++fi
193++
194+ linux_entry ()
195+ {
196+ os="$1"
197+@@ -179,27 +183,49 @@ EOF
198+ linux ${rel_dirname}/${basename}.efi.signed root=${linux_root_device_thisversion} ro ${args}
199+ EOF
200+ else
201+- if [ x"$GRUB_FORCE_PARTUUID" = x ]; then
202++ # We have initrd and PARTUUID is set - we try to boot without initrd, and fallback to using it
203++ # if it fails.
204++ # "panic=-1" means "on panic reboot immediately". "panic=0" disables the reboot behavior.
205++ if [ x"$GRUB_FORCE_PARTUUID" != x ]; then
206++ linux_root_device_thisversion="PARTUUID=${GRUB_FORCE_PARTUUID}"
207++ fi
208++ message="$(gettext_printf "Loading initial ramdisk ...")"
209++ if test -n "${initrd}" && [ x"$GRUB_FORCE_PARTUUID" != x ]; then
210++ sed "s/^/$submenu_indentation/" << EOF
211++ if [ "\${initrdfail}" = 1 ]; then
212++ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
213++EOF
214++ if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
215++ sed "s/^/$submenu_indentation/" << EOF
216++ echo '$(echo "$message" | grub_quote)'
217++EOF
218++ fi
219++
220+ sed "s/^/$submenu_indentation/" << EOF
221+- linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
222++ initrd ${rel_dirname}/${initrd}
223++ else
224++ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} panic=-1
225++ fi
226++ initrdfail
227+ EOF
228+ else
229++ # We don't have initrd or we don't want to set PARTUUID. Don't try initrd-less boot with fallback.
230+ sed "s/^/$submenu_indentation/" << EOF
231+- linux ${rel_dirname}/${basename} root=PARTUUID=${GRUB_FORCE_PARTUUID} ro ${args}
232++ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
233+ EOF
234+- fi
235+- fi
236+- if test -n "${initrd}" && [ x"$GRUB_DISABLE_INITRD" != xtrue ]; then
237+- # TRANSLATORS: ramdisk isn't identifier. Should be translated.
238+- if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
239+- message="$(gettext_printf "Loading initial ramdisk ...")"
240+- sed "s/^/$submenu_indentation/" << EOF
241++ if test -n "${initrd}"; then
242++ # We do have initrd - let's use it at boot.
243++ # TRANSLATORS: ramdisk isn't identifier. Should be translated.
244++ if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
245++ sed "s/^/$submenu_indentation/" << EOF
246+ echo '$(echo "$message" | grub_quote)'
247+ EOF
248+- fi
249+- sed "s/^/$submenu_indentation/" << EOF
250++ fi
251++ sed "s/^/$submenu_indentation/" << EOF
252+ initrd ${rel_dirname}/${initrd}
253+ EOF
254++ fi
255++ fi
256+ fi
257+ sed "s/^/$submenu_indentation/" << EOF
258+ }
259diff --git a/debian/patches/series b/debian/patches/series
260index 0438b66..ea4ecb7 100644
261--- a/debian/patches/series
262+++ b/debian/patches/series
263@@ -90,3 +90,4 @@ ofnet-init-structs-in-bootpath-parser.patch
264 add_ext_lfb_base_support.patch
265 grub-reboot-warn.patch
266 linuxefi_fix_relocate_coff.patch
267+add-initrd-less-boot-fallback.patch
268diff --git a/debian/rules b/debian/rules
269index 647b4a0..e63f368 100755
270--- a/debian/rules
271+++ b/debian/rules
272@@ -126,7 +126,7 @@ endif
273 SB_EFI_VENDOR ?= $(shell dpkg-vendor --query vendor | tr '[:upper:]' '[:lower:]')
274
275 %:
276- dh $@ --parallel
277+ dh $@ --parallel --with systemd
278
279 override_dh_auto_configure: $(patsubst %,configure/%,$(BUILD_PACKAGES))
280
281diff --git a/grub-initrd-fallback.service b/grub-initrd-fallback.service
282new file mode 100644
283index 0000000..2588538
284--- /dev/null
285+++ b/grub-initrd-fallback.service
286@@ -0,0 +1,13 @@
287+[Unit]
288+Description=GRUB failed boot detection
289+DefaultDependencies=no
290+After=local-fs.target
291+
292+[Service]
293+Type=oneshot
294+ExecStart=/usr/bin/grub-editenv /boot/grub/grubenv unset initrdfail
295+ExecStart=/usr/bin/grub-editenv /boot/grub/grubenv unset prev_entry
296+TimeoutSec=0
297+
298+[Install]
299+WantedBy=sysinit.target
300diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
301index 674a761..2332245 100644
302--- a/util/grub.d/00_header.in
303+++ b/util/grub.d/00_header.in
304@@ -50,6 +50,18 @@ if [ -s \$prefix/grubenv ]; then
305 load_env
306 fi
307 EOF
308+cat <<EOF
309+if [ "\${initrdfail}" = 2 ]; then
310+ set initrdfail=
311+elif [ "\${initrdfail}" = 1 ]; then
312+ set next_entry="\${prev_entry}"
313+ set prev_entry=
314+ save_env prev_entry
315+ if [ "\${next_entry}" ]; then
316+ set initrdfail=2
317+ fi
318+fi
319+EOF
320 if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
321 cat <<EOF
322 if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
323@@ -101,6 +113,21 @@ function savedefault {
324 }
325 EOF
326
327+cat <<"EOF"
328+function initrdfail {
329+ if [ -n "${have_grubenv}" ]; then if [ -n "${partuuid}" ]; then
330+ if [ -z "${initrdfail}" ]; then
331+ set initrdfail=1
332+ if [ -n "${boot_once}" ]; then
333+ set prev_entry="${default}"
334+ save_env prev_entry
335+ fi
336+ fi
337+ save_env initrdfail
338+ fi; fi
339+}
340+EOF
341+
342 if [ "$quick_boot" = 1 ]; then
343 cat <<EOF
344 function recordfail {
345diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
346index 76d4f31..01d96f5 100644
347--- a/util/grub.d/10_linux.in
348+++ b/util/grub.d/10_linux.in
349@@ -104,6 +104,10 @@ if [ "$vt_handoff" = 1 ]; then
350 done
351 fi
352
353+if [ x"$GRUB_FORCE_PARTUUID" != x ]; then
354+ echo "set partuuid=${GRUB_FORCE_PARTUUID}"
355+fi
356+
357 linux_entry ()
358 {
359 os="$1"
360@@ -179,27 +183,49 @@ EOF
361 linux ${rel_dirname}/${basename}.efi.signed root=${linux_root_device_thisversion} ro ${args}
362 EOF
363 else
364- if [ x"$GRUB_FORCE_PARTUUID" = x ]; then
365+ # We have initrd and PARTUUID is set - we try to boot without initrd, and fallback to using it
366+ # if it fails.
367+ # "panic=-1" means "on panic reboot immediately". "panic=0" disables the reboot behavior.
368+ if [ x"$GRUB_FORCE_PARTUUID" != x ]; then
369+ linux_root_device_thisversion="PARTUUID=${GRUB_FORCE_PARTUUID}"
370+ fi
371+ message="$(gettext_printf "Loading initial ramdisk ...")"
372+ if test -n "${initrd}" && [ x"$GRUB_FORCE_PARTUUID" != x ]; then
373+ sed "s/^/$submenu_indentation/" << EOF
374+ if [ "\${initrdfail}" = 1 ]; then
375+ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
376+EOF
377+ if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
378+ sed "s/^/$submenu_indentation/" << EOF
379+ echo '$(echo "$message" | grub_quote)'
380+EOF
381+ fi
382+
383 sed "s/^/$submenu_indentation/" << EOF
384- linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
385+ initrd ${rel_dirname}/${initrd}
386+ else
387+ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} panic=-1
388+ fi
389+ initrdfail
390 EOF
391 else
392+ # We don't have initrd or we don't want to set PARTUUID. Don't try initrd-less boot with fallback.
393 sed "s/^/$submenu_indentation/" << EOF
394- linux ${rel_dirname}/${basename} root=PARTUUID=${GRUB_FORCE_PARTUUID} ro ${args}
395+ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
396 EOF
397- fi
398- fi
399- if test -n "${initrd}" && [ x"$GRUB_DISABLE_INITRD" != xtrue ]; then
400- # TRANSLATORS: ramdisk isn't identifier. Should be translated.
401- if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
402- message="$(gettext_printf "Loading initial ramdisk ...")"
403- sed "s/^/$submenu_indentation/" << EOF
404+ if test -n "${initrd}"; then
405+ # We do have initrd - let's use it at boot.
406+ # TRANSLATORS: ramdisk isn't identifier. Should be translated.
407+ if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
408+ sed "s/^/$submenu_indentation/" << EOF
409 echo '$(echo "$message" | grub_quote)'
410 EOF
411- fi
412- sed "s/^/$submenu_indentation/" << EOF
413+ fi
414+ sed "s/^/$submenu_indentation/" << EOF
415 initrd ${rel_dirname}/${initrd}
416 EOF
417+ fi
418+ fi
419 fi
420 sed "s/^/$submenu_indentation/" << EOF
421 }

Subscribers

People subscribed via source and target branches