Bug#820838: os-prober: 40grub2 does not handle multiple initrd paths

2021-06-09 Thread Simon McVittie
Control: unmerge 820838 838177
Control: forwarded 820838 
https://salsa.debian.org/installer-team/os-prober/-/merge_requests/8
Control: retitle 838177 grub-common: grub.d/30_os-prober does not handle 
multiple initrd paths
Control: reassign 838177 grub-common 2.02+dfsg1-20
Control: forwarded 838177 https://savannah.gnu.org/bugs/index.php?47681

A recap of this bug for maintainers, since it has been a while:

In Arch Linux and its derivatives like Manjaro, instead of concatenating
CPU microcode and early user-space into a single initrd blob like we
do in Debian, the CPU microcode and the rest of early user-space are
supplied as two separate initrd archives. When Debian's grub integration
scripts detect other operating systems, they successfully identify Arch
Linux and add it to Debian's grub menu, but only the first initrd gets
added to grub.cfg, resulting in boot failure for the Arch menu entry
(because the first initrd happens to be the CPU microcode, so early
user-space is missing).

I can reproduce this on a Debian 11 test system that dual-boots into Arch,
by running update-grub and grub-install while booted into Debian 11.

Solving this requires changes in two packages: os-prober and grub-common.
I have verified that with the patches attached here, Debian's grub menu
boots Arch successfully. Unfortunately, I think we might be in a situation
where grub is waiting for os-prober and os-prober is waiting for grub.

For os-prober, the patch supplied by "General Chaos" in 2016 seems good.
I attach a clean version without the change to the Maintainer field, and
a follow-up patch that just reindents it to match the prevailing style.
Please see attached os-prober-*.patch or the merge request
.

On Thu, 23 Feb 2017 at 10:56:22 +0100, Johannes Rohr wrote:
> I've tested the patch. The initrd stanza generated is not totally correct:
> 
> іnitrd /boot/intel-ucode.img^/boot/initramfs-linux-pf.img
> 
> (note the ^ where there should be a blank)

This is a bug in integration scripts supplied by grub2: after
modifying os-prober to be able to emit more than one initrd, it
is also necessary to modify the corresponding script in grub2 to
be able to consume more than one initrd. "General Chaos" proposed
a patch upstream in 2016, which upstream said would be OK to apply
after os-prober was fixed, but there was never a Debian bug report
specifically for this. I'm repurposing 838177 to be that Debian
bug report. Please see attached grub2-*.patch or the merge request
.

At this stage in the freeze these changes seem unlikely to make it into
Debian 11, but it would be great if they can be landed at the beginning
of the Debian 12 cycle, or perhaps even incorporated into a Debian 11
point release.

Thanks,
smcv
>From 1f982e2a7c35e14d5a92c76db998afafd1bd9e87 Mon Sep 17 00:00:00 2001
From: General Chaos 
Date: Tue, 12 Apr 2016 22:28:52 +
Subject: [PATCH] os-prober: Allow initrd to contain spaces

linux-boot-prober produces structured output with newline-terminated rows
representing kernels, each with colon-delimited columns. We translate
this into a sequence of space-separated words representing kernels,
each containing colon-delimited fields where spaces are represented by
carets.

When we parse each of those words into colon-delimited fields, if the
field could conceivably contain spaces then we need to translate
carets back into spaces. We did this for label and parameters, but not
for the initrd.

In particular, when CPU microcode is installed on Arch Linux or its
derivatives, they write CPU microcode into one initrd archive and the
rest of early user-space into another, instead of concatenating the
archives into a single file like Debian derivatives do. To boot Arch
successfully from the grub menu, we need to add all of their initrds
to the grub menu entry (detecting this situation requires an os-prober
patch, for which see ).

[Commit message added by Simon McVittie ]

Bug: https://savannah.gnu.org/bugs/index.php?47681
Bug-Debian: https://bugs.debian.org/838177
Forwarded: https://savannah.gnu.org/bugs/index.php?47681
Closes: #838177
---
 util/grub.d/30_os-prober.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
index da5f28876..d0609d9a4 100644
--- a/util/grub.d/30_os-prober.in
+++ b/util/grub.d/30_os-prober.in
@@ -243,7 +243,7 @@ EOF
 LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
 LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '^' ' '`"
 LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
-LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
+LINITRD="`echo ${LINUX} | cut -d ':' -f 5 | tr '^' ' '`"
 LPARAMS="`echo ${LINUX} | cut -d ':' -f 6- | tr '^' ' '`"
 
 if [ -z "${LLABEL}" ] ; then
-- 
2.32.0

>From 7641c2da0c81f78c5f2ee2a66a1c21350cab03fc 

Bug#820838: os-prober: 40grub2 does not handle multiple initrd paths

2019-02-04 Thread sancho . san


Hi,
 
I had the same problem after installing Mint 19 on PCLOS, the new grub.cfg 
initrd line had only the microcode part. Missing the /boot/initrd.img leads to 
kernel panic. 
The linux.boot-prober also reports only the first part, the microcode update.
Is the problem really the caret?

 

On Thu, 23 Feb 2017 10:56:22 +0100 Johannes Rohr  wrote:
> Package: os-prober
> Version: 1.74
> Followup-For: Bug #820838
> 
> I've tested the patch. The initrd stanza generated is not totally correct:
> 
> іnitrd /boot/intel-ucode.img^/boot/initramfs-linux-pf.img
> 
> (note the ^ where there should be a blank)
> 
> -- System Information:
> Debian Release: 9.0
>   APT prefers testing
>   APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable')
> Architecture: amd64 (x86_64)
> Foreign Architectures: i386
> 
> Kernel: Linux 4.9.0-1-amd64 (SMP w/4 CPU cores)
> Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
> Shell: /bin/sh linked to /bin/dash
> Init: systemd (via /run/systemd/system)
> 
> Versions of packages os-prober depends on:
> ii  dmsetup  2:1.02.137-1
> ii  grub-common  2.02~beta3-5
> ii  libc62.24-9
> 
> os-prober recommends no packages.
> 
> os-prober suggests no packages.
> 
> -- no debconf information
 



Bug#820838: os-prober: 40grub2 does not handle multiple initrd paths

2017-02-23 Thread Johannes Rohr
Package: os-prober
Version: 1.74
Followup-For: Bug #820838

I've tested the patch. The initrd stanza generated is not totally correct:

іnitrd /boot/intel-ucode.img^/boot/initramfs-linux-pf.img

(note the ^ where there should be a blank)

-- System Information:
Debian Release: 9.0
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.9.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages os-prober depends on:
ii  dmsetup  2:1.02.137-1
ii  grub-common  2.02~beta3-5
ii  libc62.24-9

os-prober recommends no packages.

os-prober suggests no packages.

-- no debconf information


Bug#820838: os-prober: 40grub2 does not handle multiple initrd paths

2016-04-12 Thread General Chaos
Package: os-prober
Version: 1.63
Severity: important
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu xenial ubuntu-patch

Dear Maintainer,

Having installed Manjaro and Ubuntu on a single machine, I found that 
update-grub2
failed to produce bootable entries for Manjaro (from Ubuntu) because only the 
first
initrd path ended up in the grub.cfg.  Manjaro uses two paths on the initrd 
line,
e.g.:
initrd  /boot/intel-ucode.img /boot/initramfs-4.4-x86_64.img

The problem is partly caused by grub2's 30_os-prober script which can't 
properly handle
multiple initrd paths.  This is reported separately here:
https://savannah.gnu.org/bugs/index.php?47681
But the script still depends on linux-boot-prober's output, which currently 
only gives
the first path on the initrd line, ignoring anything on the line after it.

While the entire system seems hackish to me, a simple fix for this situation is 
given in
the included diff, and it's no more hackish than the rest of the script.

Applying the attached patch, in addition to applying the fix suggested for 
grub2 in the link
above, allows update-grub2 to produce correct, bootable entries for Manjaro.

  * linux-boot-probes/mounted/common/40grub2: must be able to handle
multiple initrd paths, as used in some distros, e.g. Manjaro.

This is my first-ever attempt at reporting a bug to Debian, so please overlook 
anything
I may have done wrong.  (I DO wish Debian just had a NORMAL bug tracker like 
everyone
else.)

Thanks for considering the patch.


-- System Information:
Debian Release: jessie/sid
  APT prefers trusty-updates
  APT policy: (500, 'trusty-updates'), (500, 'trusty-security'), (500, 
'trusty'), (100, 'trusty-backports')
Architecture: i386 (i686)

Kernel: Linux 3.13.0-85-generic (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff -Nru os-prober-1.63ubuntu1.1/debian/changelog os-prober-1.63ubuntu1.1ppa1/debian/changelog
diff -Nru os-prober-1.63ubuntu1.1/debian/control os-prober-1.63ubuntu1.1ppa1/debian/control
--- os-prober-1.63ubuntu1.1/debian/control	2016-01-12 16:29:39.0 +
+++ os-prober-1.63ubuntu1.1ppa1/debian/control	2016-04-12 21:49:05.0 +
@@ -1,8 +1,7 @@
 Source: os-prober
 Section: debian-installer
 Priority: optional
-Maintainer: Ubuntu Developers 
-XSBC-Original-Maintainer: Debian Install System Team 
+Maintainer: Debian Install System Team 
 Uploaders: Colin Watson , Joey Hess , Christian Perrier , Steve McIntyre <93...@debian.org>
 Build-Depends: debhelper (>= 9), dpkg-dev (>= 1.15.7)
 Standards-Version: 3.9.4
diff -Nru os-prober-1.63ubuntu1.1/linux-boot-probes/mounted/common/40grub2 os-prober-1.63ubuntu1.1ppa1/linux-boot-probes/mounted/common/40grub2
--- os-prober-1.63ubuntu1.1/linux-boot-probes/mounted/common/40grub2	2016-01-12 16:29:39.0 +
+++ os-prober-1.63ubuntu1.1ppa1/linux-boot-probes/mounted/common/40grub2	2016-04-12 18:08:04.0 +
@@ -78,11 +78,22 @@
 fi
 			;;
 			initrd)
-initrd="$(echo "$2" | sed 's/(.*)//')"
+shift
+initrd=""
+for initrd_path in "$@"
+do
+# sed hack, as above
+initrd_path="$(echo "$initrd_path" | sed 's/(.*)//')"
 # Initrd same.
 if [ "$partition" != "$bootpart" ]; then
-	initrd="/boot$initrd"
+	initrd_path="/boot$initrd_path"
 fi
+if [ -z "$initrd" ]; then
+	initrd="$initrd_path"
+else
+	initrd="$initrd $initrd_path"
+fi
+done
 			;;
 			"}")
 entry_result