Skip to contentSkip to conversation

Make grub-install check for errors from efibootmgr

PATCH In review Steve McIntyre 2 participants 10 messages Jan 29, 2018 – Feb 14, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make grub-install check for errors from efibootmgr

Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like:

Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform.
Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported.

and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it!

We've been using this patch in Debian now for some time, with no ill effects.

---
 grub-core/osdep/unix/platform.c | 24 +++++++++++++++---------
 include/grub/util/install.h     |  2 +-
 util/grub-install.c             | 14 +++++++++++---
 3 files changed, 27 insertions(+), 13 deletions(-)
grub-core/osdep/unix/platform.c +15 -9
index a3fcfcaca..fdd57a027 100644
@@ -78,19 +78,20 @@ get_ofpathname (const char *dev)
 		   dev);
 }
 
-static void
+static int
 grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
 {
   int fd;
   pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd);
   char *line = NULL;
   size_t len = 0;
+  int error = 0;
 
   if (!pid)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   FILE *fp = fdopen (fd, "r");
@@ -98,7 +99,7 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   line = xmalloc (80);
@@ -119,23 +120,25 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
       bootnum = line + sizeof ("Boot") - 1;
       bootnum[4] = '\0';
       if (!verbosity)
-	grub_util_exec ((const char * []){ "efibootmgr", "-q",
+	error = grub_util_exec ((const char * []){ "efibootmgr", "-q",
 	      "-b", bootnum,  "-B", NULL });
       else
-	grub_util_exec ((const char * []){ "efibootmgr",
+	error = grub_util_exec ((const char * []){ "efibootmgr",
 	      "-b", bootnum, "-B", NULL });
     }
 
   free (line);
+  return error;
 }
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor)
 {
   const char * efidir_disk;
   int efidir_part;
+  int error = 0;
   efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk);
   efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1;
 
@@ -151,23 +154,26 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
   grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
 #endif
   /* Delete old entries from the same distributor.  */
-  grub_install_remove_efi_entries_by_distributor (efi_distributor);
+  error = grub_install_remove_efi_entries_by_distributor (efi_distributor);
+  if (error)
+    return error;
 
   char *efidir_part_str = xasprintf ("%d", efidir_part);
 
   if (!verbosity)
-    grub_util_exec ((const char * []){ "efibootmgr", "-q",
+    error = grub_util_exec ((const char * []){ "efibootmgr", "-q",
 	  "-c", "-d", efidir_disk,
 	  "-p", efidir_part_str, "-w",
 	  "-L", efi_distributor, "-l", 
 	  efifile_path, NULL });
   else
-    grub_util_exec ((const char * []){ "efibootmgr",
+    error = grub_util_exec ((const char * []){ "efibootmgr",
 	  "-c", "-d", efidir_disk,
 	  "-p", efidir_part_str, "-w",
 	  "-L", efi_distributor, "-l", 
 	  efifile_path, NULL });
   free (efidir_part_str);
+  return error;
 }
 
 void
include/grub/util/install.h +1 -1
index 5910b0c09..0dba8b67f 100644
@@ -210,7 +210,7 @@ grub_install_create_envblk_file (const char *name);
 const char *
 grub_install_get_default_x86_platform (void);
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor);
util/grub-install.c +11 -3
index 5e4cdfd2b..e783824ba 100644
@@ -1848,9 +1848,13 @@ main (int argc, char *argv[])
 	  if (!removable && update_nvram)
 	    {
 	      /* Try to make this image bootable using the EFI Boot Manager, if available.  */
-	      grub_install_register_efi (efidir_grub_dev,
+	      int error = 0;
+	      error = grub_install_register_efi (efidir_grub_dev,
 					 "\\System\\Library\\CoreServices",
 					 efi_distributor);
+	      if (error)
+	        grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
+				 strerror (error));
 	    }
 
 	  grub_device_close (ins_dev);
@@ -1871,6 +1875,7 @@ main (int argc, char *argv[])
 	{
 	  char * efifile_path;
 	  char * part;
+	  int error = 0;
 
 	  /* Try to make this image bootable using the EFI Boot Manager, if available.  */
 	  if (!efi_distributor || efi_distributor[0] == '\0')
@@ -1887,8 +1892,11 @@ main (int argc, char *argv[])
 			  efidir_grub_dev->disk->name,
 			  (part ? ",": ""), (part ? : ""));
 	  grub_free (part);
-	  grub_install_register_efi (efidir_grub_dev,
-				     efifile_path, efi_distributor);
+	  error = grub_install_register_efi (efidir_grub_dev,
+					     efifile_path, efi_distributor);
+	  if (error)
+	    grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
+			     strerror (error));
 	}
       break;
 
Signature · 1 line
2.11.0
#1 lore raw
Quoted 29 lines · Steve McIntyre

Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like:

Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform.
Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported.

and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it!

We've been using this patch in Debian now for some time, with no ill effects.

---
 grub-core/osdep/unix/platform.c | 24 +++++++++++++++---------
 include/grub/util/install.h     |  2 +-
 util/grub-install.c             | 14 +++++++++++---
 3 files changed, 27 insertions(+), 13 deletions(-)
grub-core/osdep/unix/platform.c +0 -0
index a3fcfcaca..fdd57a027 100644
@@ -78,19 +78,20 @@ get_ofpathname (const char *dev)
 		   dev);
 }

grub-core/osdep/unix/platform.c get_ofpathname (const char *dev) · line 88

Quoted 10 lines
grub-core/osdep/unix/platform.c +2 -1
 
-static void
+static int
 grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
 {
   int fd;
   pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd);
   char *line = NULL;
   size_t len = 0;
+  int error = 0;

s/error/ret/ or s/error/rc/ or s/error/rv/ here and below please... In that order of preference...

Quoted 95 lines
grub-core/osdep/unix/platform.c +13 -8
   if (!pid)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   FILE *fp = fdopen (fd, "r");
@@ -98,7 +99,7 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   line = xmalloc (80);
@@ -119,23 +120,25 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
       bootnum = line + sizeof ("Boot") - 1;
       bootnum[4] = '\0';
       if (!verbosity)
-	grub_util_exec ((const char * []){ "efibootmgr", "-q",
+	error = grub_util_exec ((const char * []){ "efibootmgr", "-q",
 	      "-b", bootnum,  "-B", NULL });
       else
-	grub_util_exec ((const char * []){ "efibootmgr",
+	error = grub_util_exec ((const char * []){ "efibootmgr",
 	      "-b", bootnum, "-B", NULL });
     }
 
   free (line);
+  return error;
 }
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor)
 {
   const char * efidir_disk;
   int efidir_part;
+  int error = 0;
   efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk);
   efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1;
 
@@ -151,23 +154,26 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
   grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
 #endif
   /* Delete old entries from the same distributor.  */
-  grub_install_remove_efi_entries_by_distributor (efi_distributor);
+  error = grub_install_remove_efi_entries_by_distributor (efi_distributor);
+  if (error)
+    return error;
 
   char *efidir_part_str = xasprintf ("%d", efidir_part);
 
   if (!verbosity)
-    grub_util_exec ((const char * []){ "efibootmgr", "-q",
+    error = grub_util_exec ((const char * []){ "efibootmgr", "-q",
 	  "-c", "-d", efidir_disk,
 	  "-p", efidir_part_str, "-w",
 	  "-L", efi_distributor, "-l",
 	  efifile_path, NULL });
   else
-    grub_util_exec ((const char * []){ "efibootmgr",
+    error = grub_util_exec ((const char * []){ "efibootmgr",
 	  "-c", "-d", efidir_disk,
 	  "-p", efidir_part_str, "-w",
 	  "-L", efi_distributor, "-l",
 	  efifile_path, NULL });
   free (efidir_part_str);
+  return error;
 }
 
 void
include/grub/util/install.h +1 -1
index 5910b0c09..0dba8b67f 100644
@@ -210,7 +210,7 @@ grub_install_create_envblk_file (const char *name);
 const char *
 grub_install_get_default_x86_platform (void);
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor);
util/grub-install.c +0 -0
index 5e4cdfd2b..e783824ba 100644

util/grub-install.c main (int argc, char *argv[]) · line 1851

Quoted 5 lines
util/grub-install.c +1 -1
@@ -1848,9 +1848,13 @@ main (int argc, char *argv[])
 	  if (!removable && update_nvram)
 	    {
 	      /* Try to make this image bootable using the EFI Boot Manager, if available.  */
-	      grub_install_register_efi (efidir_grub_dev,
+	      int error = 0;

I think that you do not need this initialization.

Daniel

#2 lore raw
Quoted 10 lines · Daniel Kiper
Quoted 9 lines · Steve McIntyre
grub-core/osdep/unix/platform.c +0 -0
index a3fcfcaca..fdd57a027 100644
@@ -78,19 +78,20 @@ get_ofpathname (const char *dev)
 		   dev);
 }
 
Quoted 12 lines

grub-core/osdep/unix/platform.c get_ofpathname (const char *dev) · line 88

Quoted 9 lines
grub-core/osdep/unix/platform.c +2 -1
-static void
+static int
 grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
 {
   int fd;
   pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd);
   char *line = NULL;
   size_t len = 0;
+  int error = 0;

s/error/ret/ or s/error/rc/ or s/error/rv/ here and below please... In that order of preference...

ACK.

...

Quoted 17 lines
Quoted 17 lines
include/grub/util/install.h +1 -1
index 5910b0c09..0dba8b67f 100644
@@ -210,7 +210,7 @@ grub_install_create_envblk_file (const char *name);
 const char *
 grub_install_get_default_x86_platform (void);
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor);
util/grub-install.c +0 -0
index 5e4cdfd2b..e783824ba 100644
Quoted 8 lines

util/grub-install.c main (int argc, char *argv[]) · line 1851

Quoted 6 lines
util/grub-install.c +1 -1
@@ -1848,9 +1848,13 @@ main (int argc, char *argv[])
 	  if (!removable && update_nvram)
 	    {
 	      /* Try to make this image bootable using the EFI Boot Manager, if available.  */
-	      grub_install_register_efi (efidir_grub_dev,
+	      int error = 0;

I think that you do not need this initialization.

ACK. Updated patch coming shortly.

Signature · 5 lines
Steve McIntyre, Cambridge, UK.                                [email protected]
The two hard things in computing:
 * naming things
 * cache invalidation
 * off-by-one errors                  -- Stig Sandbeck Mathisen
#3 lore raw

PATCH 1/1 Make grub-install check for errors from efibootmgr

Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like:

Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform.
Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported.

and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it!

We've been using this patch in Debian now for some time, with no ill effects.

---
 grub-core/osdep/unix/platform.c | 25 +++++++++++++++----------
 include/grub/util/install.h     |  2 +-
 util/grub-install.c             | 18 +++++++++++++-----
 3 files changed, 29 insertions(+), 16 deletions(-)
grub-core/osdep/unix/platform.c +15 -10
index a3fcfcaca..b3a617e44 100644
@@ -78,19 +78,20 @@ get_ofpathname (const char *dev)
 		   dev);
 }
 
-static void
+static int
 grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
 {
   int fd;
   pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd);
   char *line = NULL;
   size_t len = 0;
+  int ret;
 
   if (!pid)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   FILE *fp = fdopen (fd, "r");
@@ -98,14 +99,13 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   line = xmalloc (80);
   len = 80;
   while (1)
     {
-      int ret;
       char *bootnum;
       ret = getline (&line, &len, fp);
       if (ret == -1)
@@ -119,23 +119,25 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
       bootnum = line + sizeof ("Boot") - 1;
       bootnum[4] = '\0';
       if (!verbosity)
-	grub_util_exec ((const char * []){ "efibootmgr", "-q",
+	ret = grub_util_exec ((const char * []){ "efibootmgr", "-q",
 	      "-b", bootnum,  "-B", NULL });
       else
-	grub_util_exec ((const char * []){ "efibootmgr",
+	ret = grub_util_exec ((const char * []){ "efibootmgr",
 	      "-b", bootnum, "-B", NULL });
     }
 
   free (line);
+  return ret;
 }
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor)
 {
   const char * efidir_disk;
   int efidir_part;
+  int ret;
   efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk);
   efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1;
 
@@ -151,23 +153,26 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
   grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
 #endif
   /* Delete old entries from the same distributor.  */
-  grub_install_remove_efi_entries_by_distributor (efi_distributor);
+  ret = grub_install_remove_efi_entries_by_distributor (efi_distributor);
+  if (ret)
+    return ret;
 
   char *efidir_part_str = xasprintf ("%d", efidir_part);
 
   if (!verbosity)
-    grub_util_exec ((const char * []){ "efibootmgr", "-q",
+    ret = grub_util_exec ((const char * []){ "efibootmgr", "-q",
 	  "-c", "-d", efidir_disk,
 	  "-p", efidir_part_str, "-w",
 	  "-L", efi_distributor, "-l", 
 	  efifile_path, NULL });
   else
-    grub_util_exec ((const char * []){ "efibootmgr",
+    ret = grub_util_exec ((const char * []){ "efibootmgr",
 	  "-c", "-d", efidir_disk,
 	  "-p", efidir_part_str, "-w",
 	  "-L", efi_distributor, "-l", 
 	  efifile_path, NULL });
   free (efidir_part_str);
+  return ret;
 }
 
 void
include/grub/util/install.h +1 -1
index 5910b0c09..0dba8b67f 100644
@@ -210,7 +210,7 @@ grub_install_create_envblk_file (const char *name);
 const char *
 grub_install_get_default_x86_platform (void);
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor);
util/grub-install.c +13 -5
index 5e4cdfd2b..690f180c5 100644
@@ -1848,9 +1848,13 @@ main (int argc, char *argv[])
 	  if (!removable && update_nvram)
 	    {
 	      /* Try to make this image bootable using the EFI Boot Manager, if available.  */
-	      grub_install_register_efi (efidir_grub_dev,
-					 "\\System\\Library\\CoreServices",
-					 efi_distributor);
+	      int ret;
+	      ret = grub_install_register_efi (efidir_grub_dev,
+					       "\\System\\Library\\CoreServices",
+					       efi_distributor);
+	      if (ret)
+	        grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
+				 strerror (ret));
 	    }
 
 	  grub_device_close (ins_dev);
@@ -1871,6 +1875,7 @@ main (int argc, char *argv[])
 	{
 	  char * efifile_path;
 	  char * part;
+	  int ret;
 
 	  /* Try to make this image bootable using the EFI Boot Manager, if available.  */
 	  if (!efi_distributor || efi_distributor[0] == '\0')
@@ -1887,8 +1892,11 @@ main (int argc, char *argv[])
 			  efidir_grub_dev->disk->name,
 			  (part ? ",": ""), (part ? : ""));
 	  grub_free (part);
-	  grub_install_register_efi (efidir_grub_dev,
-				     efifile_path, efi_distributor);
+	  ret = grub_install_register_efi (efidir_grub_dev,
+					   efifile_path, efi_distributor);
+	  if (ret)
+	    grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
+			     strerror (ret));
 	}
       break;
 
Signature · 1 line
2.11.0
#4 lore raw
Quoted 52 lines · Steve McIntyre

Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like:

Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform.
Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported.

and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it!

We've been using this patch in Debian now for some time, with no ill effects.

---
 grub-core/osdep/unix/platform.c | 25 +++++++++++++++----------
 include/grub/util/install.h     |  2 +-
 util/grub-install.c             | 18 +++++++++++++-----
 3 files changed, 29 insertions(+), 16 deletions(-)
grub-core/osdep/unix/platform.c +3 -2
index a3fcfcaca..b3a617e44 100644
@@ -78,19 +78,20 @@ get_ofpathname (const char *dev)
 		   dev);
 }
 
-static void
+static int
 grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
 {
   int fd;
   pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd);
   char *line = NULL;
   size_t len = 0;
+  int ret;
 
   if (!pid)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   FILE *fp = fdopen (fd, "r");
@@ -98,14 +99,13 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),

grub-core/osdep/unix/platform.c grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) · line 108

Quoted 10 lines
grub-core/osdep/unix/platform.c +1 -2
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   line = xmalloc (80);
   len = 80;
   while (1)
     {
-      int ret;

Oh, no, please do not do that here. If my first proposal conflicts with existing variables use second one. If second is bad please choose third. The rest of the patch LGTM.

Daniel

#5 lore raw
Quoted 37 lines · Daniel Kiper
Quoted 36 lines · Steve McIntyre
grub-core/osdep/unix/platform.c +4 -3
index a3fcfcaca..b3a617e44 100644
@@ -78,19 +78,20 @@ get_ofpathname (const char *dev)
 		   dev);
 }
 
-static void
+static int
 grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
 {
   int fd;
   pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd);
   char *line = NULL;
   size_t len = 0;
+  int ret;
 
   if (!pid)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   FILE *fp = fdopen (fd, "r");
@@ -98,14 +99,13 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
Quoted 9 lines

grub-core/osdep/unix/platform.c grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) · line 108

Quoted 5 lines
grub-core/osdep/unix/platform.c +0 -1
   line = xmalloc (80);
   len = 80;
   while (1)
     {
-      int ret;

Oh, no, please do not do that here. If my first proposal conflicts with existing variables use second one. If second is bad please choose third. The rest of the patch LGTM.

OK, no problem. New version on its way in a sec.

Signature · 2 lines
Steve McIntyre, Cambridge, UK.                                [email protected]
You raise the blade, you make the change... You re-arrange me 'til I'm sane...
#6 lore raw

PATCH 1/1 Make grub-install check for errors from efibootmgr

In reply to Daniel Kiper

Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like:

Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform.
Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported.

and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it!

We've been using this patch in Debian now for some time, with no ill effects.

---
 grub-core/osdep/unix/platform.c | 24 +++++++++++++++---------
 include/grub/util/install.h     |  2 +-
 util/grub-install.c             | 18 +++++++++++++-----
 3 files changed, 29 insertions(+), 15 deletions(-)
grub-core/osdep/unix/platform.c +15 -9
index a3fcfcaca..ca448bc11 100644
@@ -78,19 +78,20 @@ get_ofpathname (const char *dev)
 		   dev);
 }
 
-static void
+static int
 grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
 {
   int fd;
   pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd);
   char *line = NULL;
   size_t len = 0;
+  int rc;
 
   if (!pid)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   FILE *fp = fdopen (fd, "r");
@@ -98,7 +99,7 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
     {
       grub_util_warn (_("Unable to open stream from %s: %s"),
 		      "efibootmgr", strerror (errno));
-      return;
+      return errno;
     }
 
   line = xmalloc (80);
@@ -119,23 +120,25 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
       bootnum = line + sizeof ("Boot") - 1;
       bootnum[4] = '\0';
       if (!verbosity)
-	grub_util_exec ((const char * []){ "efibootmgr", "-q",
+	rc = grub_util_exec ((const char * []){ "efibootmgr", "-q",
 	      "-b", bootnum,  "-B", NULL });
       else
-	grub_util_exec ((const char * []){ "efibootmgr",
+	rc = grub_util_exec ((const char * []){ "efibootmgr",
 	      "-b", bootnum, "-B", NULL });
     }
 
   free (line);
+  return rc;
 }
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor)
 {
   const char * efidir_disk;
   int efidir_part;
+  int ret;
   efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk);
   efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1;
 
@@ -151,23 +154,26 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
   grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
 #endif
   /* Delete old entries from the same distributor.  */
-  grub_install_remove_efi_entries_by_distributor (efi_distributor);
+  ret = grub_install_remove_efi_entries_by_distributor (efi_distributor);
+  if (ret)
+    return ret;
 
   char *efidir_part_str = xasprintf ("%d", efidir_part);
 
   if (!verbosity)
-    grub_util_exec ((const char * []){ "efibootmgr", "-q",
+    ret = grub_util_exec ((const char * []){ "efibootmgr", "-q",
 	  "-c", "-d", efidir_disk,
 	  "-p", efidir_part_str, "-w",
 	  "-L", efi_distributor, "-l", 
 	  efifile_path, NULL });
   else
-    grub_util_exec ((const char * []){ "efibootmgr",
+    ret = grub_util_exec ((const char * []){ "efibootmgr",
 	  "-c", "-d", efidir_disk,
 	  "-p", efidir_part_str, "-w",
 	  "-L", efi_distributor, "-l", 
 	  efifile_path, NULL });
   free (efidir_part_str);
+  return ret;
 }
 
 void
include/grub/util/install.h +1 -1
index 5910b0c09..0dba8b67f 100644
@@ -210,7 +210,7 @@ grub_install_create_envblk_file (const char *name);
 const char *
 grub_install_get_default_x86_platform (void);
 
-void
+int
 grub_install_register_efi (grub_device_t efidir_grub_dev,
 			   const char *efifile_path,
 			   const char *efi_distributor);
util/grub-install.c +13 -5
index 5e4cdfd2b..690f180c5 100644
@@ -1848,9 +1848,13 @@ main (int argc, char *argv[])
 	  if (!removable && update_nvram)
 	    {
 	      /* Try to make this image bootable using the EFI Boot Manager, if available.  */
-	      grub_install_register_efi (efidir_grub_dev,
-					 "\\System\\Library\\CoreServices",
-					 efi_distributor);
+	      int ret;
+	      ret = grub_install_register_efi (efidir_grub_dev,
+					       "\\System\\Library\\CoreServices",
+					       efi_distributor);
+	      if (ret)
+	        grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
+				 strerror (ret));
 	    }
 
 	  grub_device_close (ins_dev);
@@ -1871,6 +1875,7 @@ main (int argc, char *argv[])
 	{
 	  char * efifile_path;
 	  char * part;
+	  int ret;
 
 	  /* Try to make this image bootable using the EFI Boot Manager, if available.  */
 	  if (!efi_distributor || efi_distributor[0] == '\0')
@@ -1887,8 +1892,11 @@ main (int argc, char *argv[])
 			  efidir_grub_dev->disk->name,
 			  (part ? ",": ""), (part ? : ""));
 	  grub_free (part);
-	  grub_install_register_efi (efidir_grub_dev,
-				     efifile_path, efi_distributor);
+	  ret = grub_install_register_efi (efidir_grub_dev,
+					   efifile_path, efi_distributor);
+	  if (ret)
+	    grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
+			     strerror (ret));
 	}
       break;
 
Signature · 1 line
2.11.0
#7 lore raw
Quoted 9 lines · Steve McIntyre

Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like:

Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform.
Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported.

Quoted 4 lines

and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it!

We've been using this patch in Debian now for some time, with no ill

s/this/similar/? If you are OK I will change that during commit.

Quoted 3 lines

effects.

If there are no objections I will commit this in a week or so.

Daniel

#8 lore raw

Apologies for the delayed response - just found this in the archives but for some reason I never got it in my inbox. Weird... :-/

Quoted 10 lines · Daniel Kiper
Quoted 9 lines · Steve McIntyre

Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like:

Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform.
Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported.

Quoted 6 lines
Quoted 4 lines

and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it!

We've been using this patch in Debian now for some time, with no ill

s/this/similar/? If you are OK I will change that during commit.

Yup, perfect. :-)

Quoted 1 line

If there are no objections I will commit this in a week or so.

Please...

Signature · 3 lines
Steve McIntyre, Cambridge, UK.                                [email protected]
We don't need no education.
We don't need no thought control.
Applied
#9 lore raw
Quoted 19 lines · Steve McIntyre

Apologies for the delayed response - just found this in the archives but for some reason I never got it in my inbox. Weird... :-/

Quoted 15 lines · Daniel Kiper
Quoted 13 lines · Steve McIntyre

Code is currently ignoring errors from efibootmgr, giving users clearly bogus output like:

Setting up grub-efi-amd64 (2.02~beta3-4) ... Installing for x86_64-efi platform.
Could not delete variable: No space left on device Could not prepare Boot variable: No space left on device Installation finished. No error reported.

and then potentially unbootable systems. If efibootmgr fails, grub-install should know that and report it!

We've been using this patch in Debian now for some time, with no ill

Quoted 7 lines
Quoted 1 line

s/this/similar/? If you are OK I will change that during commit.

Yup, perfect. :-)

Quoted 1 line

If there are no objections I will commit this in a week or so.

Please...

Applied!

Quoted 4 lines

--
Steve McIntyre, Cambridge, UK. [email protected]
We don't need no education.
We don't need no thought control.

Ha! :-)))

Daniel