Skip to contentSkip to conversation

Fix installation issues on ppc64le

PATCH Superseded Ismael Luceno 2 participants 5 messages Aug 24, 2022 – Aug 29, 2022

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Fix installation issues on ppc64le

When the /dev/nvram device is unavailable, the installation fails and leaves the system in an unbootable state.

The patches in this series introduce a handler for the boilerplate code and make sure nvram is available.

Ismael Luceno (2):
Add helper to load linux kmods
Ensure nvram is available and functional on IEEE1275

 grub-core/osdep/unix/platform.c | 42 +++++++++++++++++++++++++++++----
 1 file changed, 38 insertions(+), 4 deletions(-)
Signature · 1 line
2.37.1
#1 lore raw

PATCH 1/2 Add helper to load linux kmods

The function checks for already loaded (incl. built-in) modules first at /sys/module/, then tries to load it.

Abort when unable to load efivarfs/efivars.

---
 grub-core/osdep/unix/platform.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
grub-core/osdep/unix/platform.c +20 -4
index de712211cf09..a5bf064b7cf5 100644
@@ -26,8 +26,25 @@
 #include <grub/emu/exec.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <unistd.h>
+
+static int
+linux_kmod_load (const char *name)
+{
+#ifdef __linux__
+  char path[64];
+  if (snprintf (path, sizeof(path), "/sys/module/%s", name) >= sizeof(path))
+    grub_util_error (_("module name `%s' too long"), name);
+  if (!access (path, F_OK))
+    return 0;
+  return grub_util_exec ((const char * []){ "modprobe", "-q", name, NULL });
+#else
+  return 0;
+#endif
+}
 
 static char *
 get_ofpathname (const char *dev)
@@ -149,10 +166,9 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
       grub_util_error (_("%s: not found"), "efibootmgr");
     }
 
-  /* On Linux, we need the efivars kernel modules.  */
-#ifdef __linux__
-  grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
-#endif
+  /* On Linux, we need efivarfs (or the legacy efivars).  */
+  linux_kmod_load ("efivars");
+
   /* Delete old entries from the same distributor.  */
   ret = grub_install_remove_efi_entries_by_distributor (efi_distributor);
   if (ret)
Signature · 1 line
2.37.1
#2 lore raw

PATCH 2/2 Ensure nvram is available and functional on IEEE1275

In reply to Ismael Luceno

Otherwise the installation will fail, and the system will be left in an unbootable state.

On ppc64le, the boot process shows:

Welcome to GRUB!

error: ../../grub-core/kern/dl.c:380:symbol `grub_disk_get_size' not found. Entering rescue mode...
grub rescue>

---
 grub-core/osdep/unix/platform.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
grub-core/osdep/unix/platform.c +18 -0
index a5bf064b7cf5..fd23176e58a0 100644
@@ -192,12 +192,30 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
   return ret;
 }
 
+static void
+linux_ensure_nvram (void)
+{
+  int fd;
+#ifndef __linux__
+  return 0;
+#endif
+  if (linux_kmod_load("nvram"))
+    grub_util_error (_("%s: kernel module not found"), "nvram");
+  fd = open ("/dev/nvram", O_RDWR);
+  if (fd == -1)
+    grub_util_error ("/dev/nvram: %s", strerror(errno));
+  close (fd);
+}
+
 void
 grub_install_register_ieee1275 (int is_prep, const char *install_device,
 				int partno, const char *relpath)
 {
   char *boot_device;
 
+  /* On Linux, ensure nvram is available and functional.  */
+  linux_ensure_nvram ();
+
   if (grub_util_exec_redirect_null ((const char * []){ "ofpathname", "--version", NULL }))
     {
       /* TRANSLATORS: This message is shown when required executable `%s'
Signature · 1 line
2.37.1
#3 lore raw

Re: [PATCH 2/2] Ensure nvram is available and functional on IEEE1275

Quoted 10 lines · Ismael Luceno

Otherwise the installation will fail, and the system will be left in an unbootable state.

On ppc64le, the boot process shows:

Welcome to GRUB!

error: ../../grub-core/kern/dl.c:380:symbol `grub_disk_get_size' not found. Entering rescue mode...
grub rescue>

The symbol looking up failure due to failed grub-install attempt should not happen in the first place given this commit should bail it out.

8ddbdc3bc2 grub-install: Add backup and restore

Apparently there's missing grub_set_install_backup_ponr between successful image embedding and grub_install_register_ieee1275 and we should fix that as well.

Quoted 19 lines
---
 grub-core/osdep/unix/platform.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
grub-core/osdep/unix/platform.c +5 -0
index a5bf064b7cf5..fd23176e58a0 100644
@@ -192,12 +192,30 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
   return ret;
 }
 
+static void
+linux_ensure_nvram (void)
+{
+  int fd;
+#ifndef __linux__

grub-core/osdep/unix/platform.c grub_install_register_efi (grub_device_t efidir_grub_dev, · line 209

Quoted 10 lines
grub-core/osdep/unix/platform.c +10 -0
+  return 0;
+#endif
+  if (linux_kmod_load("nvram"))
+    grub_util_error (_("%s: kernel module not found"), "nvram");
+  fd = open ("/dev/nvram", O_RDWR);
+  if (fd == -1)
+    grub_util_error ("/dev/nvram: %s", strerror(errno));
+  close (fd);
+}
+

I'm wondering why it is needed. The nvram module should be loaded on-demand via linux kernel's request_module() and modalias trick whever /dev/nvram is accessed.

Thanks,
Michael

Quoted 20 lines
grub-core/osdep/unix/platform.c +3 -0
 void
 grub_install_register_ieee1275 (int is_prep, const char *install_device,
 				int partno, const char *relpath)
 {
   char *boot_device;
 
+  /* On Linux, ensure nvram is available and functional.  */
+  linux_ensure_nvram ();
+
   if (grub_util_exec_redirect_null ((const char * []){ "ofpathname", "--version", NULL }))
     {
       /* TRANSLATORS: This message is shown when required executable `%s'
Signature · 7 lines
2.37.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#4 lore raw

Re: [PATCH 2/2] Ensure nvram is available and functional on IEEE1275

On Thu, 25 Aug 2022 12:24:17 +0800
Michael Chang <[email protected]> wrote:
<...>

Quoted 3 lines

Apparently there's missing grub_set_install_backup_ponr between successful image embedding and grub_install_register_ieee1275 and we should fix that as well.

Thanks for the feedback; I've sent v2.

<...>

Quoted 5 lines
Quoted 5 lines
grub-core/osdep/unix/platform.c +5 -0
+  if (linux_kmod_load("nvram"))
+    grub_util_error (_("%s: kernel module not found"), "nvram");
+  fd = open ("/dev/nvram", O_RDWR);
+  if (fd == -1)
+    grub_util_error ("/dev/nvram: %s", strerror(errno));

<...>

Quoted 3 lines

I'm wondering why it is needed. The nvram module should be loaded on-demand via linux kernel's request_module() and modalias trick whever /dev/nvram is accessed.

It was based on another patch that did so but without the extra checking, I guess both are wrong.

It's enough checking /dev/nvram is operational; it's necessary to fail early because other commands down the line may get ENODEV if the module fails to load (e.g. the file may have been removed). I moved this to an earlier point in grub-install.