grub2/0309-Fix-prefix-and-root-on...

55 lines
2.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Robbie Harwood <rharwood@redhat.com>
Date: Fri, 13 Jan 2023 12:36:29 -0500
Subject: [PATCH] Fix prefix and root on ppc64le CDs
CHRP requires grub at /boot/grub. On CDs, this means any other prefix
will be invalid. In particular, a distro grub might prefer /grub2 - but
prefix is hardcoded into the signed core.elf, and will always be wrong
here.
Also work around a conflict between OF naming and that used by
part_msdos: on CDs, we always want the raw device. This fixes an issue
where grub would successfully load the menu from an image, but then
produce the error:
error: ../../grub-core/net/net.c:1552:disk `ieee1275/cdrom,0' not found.
and fail to boot further.
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
(cherry picked from commit 68e5981a5e808a32350aca4a2414717fa4605ca0)
(cherry picked from commit 19c45257cc29845adedc3931eed577e97534f8f1)
---
grub-core/kern/main.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
index 4c4e6912f9..6989da5618 100644
--- a/grub-core/kern/main.c
+++ b/grub-core/kern/main.c
@@ -278,6 +278,23 @@ grub_set_prefix_and_root (void)
}
grub_env_set ("root", device);
+
+#ifdef __powerpc__
+ /* When booting from a CD, if part_msdos is enabled, grub will detect
+ and create access points starting at (ieee1275/cdrom,msdos1).
+ However, the device detection and OF name transformation will produce
+ a device named (ieee1275/cdrom,0) - i.e., missing the msdos and also
+ differently indexed. Furthermore, CHRP mandates boot/grub as prefix,
+ but our signed images are built with /grub2 to reflect installed
+ systems. Just ignore both messes.
+ */
+ if (!grub_strncmp (device[0] == '(' ? device + 1 : device,
+ "ieee1275/cdrom", grub_strlen ("ieee1275/cdrom")))
+ {
+ grub_env_set ("prefix", "/boot/grub");
+ grub_env_set ("root", "ieee1275/cdrom");
+ }
+#endif
}
grub_free (device);