Skip to contentSkip to conversation

improve error messages in grub-setup

PATCH In review Robert Millan 2 participants 7 messages May 2, 2009 – May 4, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 improve error messages in grub-setup

This patch improves error messages in grub-setup, and adds a few warnings when requested to install in odd layouts.

Since there was no facility to emmit a warning that is always visible (regardless of verbosity), but doesn't abort execution, I added one (grub_util_warn ()). Is everyone fine with using this interface?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

2009-05-02 Robert Millan <[email protected]>

* util/misc.c (grub_util_warn): New function. Emmits a warning unconditionally.
* include/grub/util/misc.h (grub_util_warn): New declaration.

* util/i386/pc/grub-setup.c (setup): Improve error messages and add warnings when requested to install in odd layouts.

grub/util/misc.h +1 -0
Index: include/grub/util/misc.h
===================================================================
@@ -40,6 +40,7 @@ extern char *progname;
 extern int verbosity;
 extern jmp_buf main_env;
 
+void grub_util_warn (const char *fmt, ...);
 void grub_util_info (const char *fmt, ...);
 void grub_util_error (const char *fmt, ...) __attribute__ ((noreturn));
 
i386/pc/grub-setup.c +23 -8
Index: util/i386/pc/grub-setup.c
===================================================================
@@ -109,7 +109,7 @@ setup (const char *dir,
   FILE *fp;
   struct { grub_uint64_t start; grub_uint64_t end; } embed_region;
   embed_region.start = embed_region.end = ~0UL;
-  int able_to_embed = 1;
+  int embedding_area_exists = 0, able_to_embed = 0;
   
   auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
 			       unsigned length);
@@ -304,6 +304,12 @@ setup (const char *dir,
   
   grub_util_info ("dos partition is %d, bsd partition is %d",
 		  dos_part, bsd_part);
+
+  if (! dest_dev->disk->has_partitions)
+    grub_util_warn ("Attempting to install GRUB to a partitionless disk.  This is a BAD idea.");
+
+  if (dest_dev->disk->partition)
+    grub_util_warn ("Attempting to install GRUB to a partition instead of the MBR.  This is a BAD idea.");
   
   /* If the destination device can have partitions and it is the MBR,
      try to embed the core image into after the MBR.  */
@@ -311,11 +317,16 @@ setup (const char *dir,
     {
       grub_partition_iterate (dest_dev->disk, find_usable_region);
 
+      if (embed_region.end != 0)
+	embedding_area_exists = 1;
+
       /* If there is enough space...  */
       if ((unsigned long) core_sectors <= embed_region.end - embed_region.start)
 	{
 	  grub_util_info ("will embed the core image at sector 0x%llx", embed_region.start);
 
+	  able_to_embed = 1;
+
 	  *install_dos_part = grub_cpu_to_le32 (dos_part);
 	  *install_bsd_part = grub_cpu_to_le32 (bsd_part);
 
@@ -349,16 +360,20 @@ setup (const char *dir,
 
 	  goto finish;
 	}
+    }
+
+  if (! able_to_embed)
+    {
+      if (embedding_area_exists)
+	grub_util_warn ("Embedding area is too small for core.img.");
       else
-        able_to_embed = 0;
+	grub_util_warn ("Embedding area not present at all!");
+
+      if (must_embed)
+	grub_util_error ("Embedding is not possible, but this is required when "
+			 "the root device is on a RAID array or LVM volume.");
     }
-  else
-    able_to_embed = 0;
 
-  if (must_embed && ! able_to_embed)
-    grub_util_error ("Core image is too big for embedding, but this is required when\n"
-		     "the root device is on a RAID array or LVM volume.");
-  
   /* The core image must be put on a filesystem unfortunately.  */
   grub_util_info ("will leave the core image on the filesystem");
   
misc.c +13 -0
Index: util/misc.c
===================================================================
@@ -52,6 +52,19 @@ char *progname = 0;
 int verbosity = 0;
 
 void
+grub_util_warn (const char *fmt, ...)
+{
+  va_list ap;
+  
+  fprintf (stderr, "%s: warn: ", progname);
+  va_start (ap, fmt);
+  vfprintf (stderr, fmt, ap);
+  va_end (ap);
+  fputc ('\n', stderr);
+  fflush (stderr);
+}
+
+void
 grub_util_info (const char *fmt, ...)
 {
   if (verbosity > 0)
#1 lore raw
Quoted 7 lines · Robert Millan

This patch improves error messages in grub-setup, and adds a few warnings when requested to install in odd layouts.

Since there was no facility to emmit a warning that is always visible (regardless of verbosity), but doesn't abort execution, I added one (grub_util_warn ()). Is everyone fine with using this interface?

I'm fine with the code, but the warnings are quite serious. I think grub-install should not proceed if there are any warnings unless there is an option to ignore warnings (e.g. --ignore-warnings or --force).

Signature · 2 lines
Regards,
Pavel Roskin
#2 lore raw
Quoted 4 lines · Pavel Roskin
Quoted 3 lines · Robert Millan

This patch improves error messages in grub-setup, and adds a few warnings when requested to install in odd layouts.

Quoted 8 lines
Quoted 4 lines

Since there was no facility to emmit a warning that is always visible (regardless of verbosity), but doesn't abort execution, I added one (grub_util_warn ()). Is everyone fine with using this interface?

I'm fine with the code, but the warnings are quite serious. I think grub-install should not proceed if there are any warnings unless there is an option to ignore warnings (e.g. --ignore-warnings or --force).

Agreed. It's no harm to add --force for users who are stuck in such layouts.

Here's a new patch.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

2009-05-03 Robert Millan <[email protected]>

* util/misc.c (grub_util_warn): New function. Emmits a warning unconditionally.
* include/grub/util/misc.h (grub_util_warn): New declaration.

* util/i386/pc/grub-install.in: Understand --force and pass it down to grub-setup.

* util/i386/pc/grub-setup.c (main): Understand --force and pass it down to setup().
(setup): Improve error messages and add warnings when requested to install in odd layouts. Refuse to install using blocklists unless --force was set.

grub/util/misc.h +1 -0
Index: include/grub/util/misc.h
===================================================================
@@ -40,6 +40,7 @@ extern char *progname;
 extern int verbosity;
 extern jmp_buf main_env;
 
+void grub_util_warn (const char *fmt, ...);
 void grub_util_info (const char *fmt, ...);
 void grub_util_error (const char *fmt, ...) __attribute__ ((noreturn));
 
i386/pc/grub-install.in +4 -1
Index: util/i386/pc/grub-install.in
===================================================================
@@ -67,6 +67,7 @@ Install GRUB on your drive.
   --grub-probe=FILE       use FILE as grub-probe
   --no-floppy             do not probe any floppy drive
   --recheck               probe a device map even if it already exists
+  --force                 install even if problems are detected
 
 INSTALL_DEVICE can be a GRUB device name or a system device filename.
 
@@ -106,6 +107,8 @@ for option in "$@"; do
     # This is an undocumented feature...
     --debug)
 	debug=yes ;;
+    -f | --force)
+        setup_force="--force" ;;
     -*)
 	echo "Unrecognized option \`$option'" 1>&2
 	usage
@@ -295,7 +298,7 @@ if [ "${target_cpu}-${platform}" = "i386
     $grub_mkimage --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
 
     # Now perform the installation.
-    $grub_setup ${setup_verbose} --directory=${grubdir} --device-map=${device_map} \
+    $grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \
         ${install_device} || exit 1
 else
     $grub_mkimage -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
i386/pc/grub-setup.c +35 -14

125 lines not on this page · raw message

misc.c +13 -0
Index: util/misc.c
===================================================================
@@ -52,6 +52,19 @@ char *progname = 0;
 int verbosity = 0;
 
 void
+grub_util_warn (const char *fmt, ...)
+{
+  va_list ap;
+  
+  fprintf (stderr, "%s: warn: ", progname);
+  va_start (ap, fmt);
+  vfprintf (stderr, fmt, ap);
+  va_end (ap);
+  fputc ('\n', stderr);
+  fflush (stderr);
+}
+
+void
 grub_util_info (const char *fmt, ...)
 {
   if (verbosity > 0)
#3 lore raw
Quoted 3 lines · Robert Millan

Agreed. It's no harm to add --force for users who are stuck in such layouts.

Here's a new patch.

I don't see the "force" variable affecting anything in setup() other than output. grub_util_warn() doesn't set any flag that there have been warnings.

Signature · 2 lines
Regards,
Pavel Roskin
#4 lore raw
Quoted 8 lines · Pavel Roskin
Quoted 3 lines · Robert Millan

Agreed. It's no harm to add --force for users who are stuck in such layouts.

Here's a new patch.

I don't see the "force" variable affecting anything in setup() other than output.

There is, see:

+ grub_util_warn ("Embedding is not possible. GRUB can only be installed in this "
+ "setup by using blocklists. However, blocklists are UNRELIABLE and "
+ "its use is discouraged.");
+ if (! force)
+ grub_util_error ("If you really want blocklists, use --force.");

The first is always displayed, the latter only when we don't have --force

Quoted 2 lines

grub_util_warn() doesn't set any flag that there have been warnings.

That's an option, too. But it would preclude the possibility of issuing warnings for which we don't want to require --force (i.e. lesser evils). I wonder if that would be a problem?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#5 lore raw
Quoted 18 lines · Robert Millan
Quoted 8 lines · Pavel Roskin
Quoted 3 lines · Robert Millan

Agreed. It's no harm to add --force for users who are stuck in such layouts.

Here's a new patch.

I don't see the "force" variable affecting anything in setup() other than output.

There is, see:

i386/pc/grub-setup.c +5 -0
+  grub_util_warn ("Embedding is not possible.  GRUB can only be installed in this "
+                 "setup by using blocklists.  However, blocklists are UNRELIABLE and "
+                 "its use is discouraged.");
+  if (! force)
+    grub_util_error ("If you really want blocklists, use --force.");
Quoted 1 line

The first is always displayed, the latter only when we don't have --force

Sorry, I missed the side effect of grub_util_error(). Never mind.

Quoted 6 lines
Quoted 2 lines

grub_util_warn() doesn't set any flag that there have been warnings.

That's an option, too. But it would preclude the possibility of issuing warnings for which we don't want to require --force (i.e. lesser evils). I wonder if that would be a problem?

We can decide it when we know what the lesser evils are. I'm fine with your patch.

Signature · 2 lines
Regards,
Pavel Roskin
#6 lore raw
Quoted 9 lines · Pavel Roskin
Quoted 6 lines
Quoted 2 lines

grub_util_warn() doesn't set any flag that there have been warnings.

That's an option, too. But it would preclude the possibility of issuing warnings for which we don't want to require --force (i.e. lesser evils). I wonder if that would be a problem?

We can decide it when we know what the lesser evils are. I'm fine with your patch.

Alright then, I checked it in.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."