388b8a4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
388b8a4
From: Javier Martinez Canillas <javierm@redhat.com>
388b8a4
Date: Tue, 26 Feb 2019 20:11:27 +0100
388b8a4
Subject: [PATCH] blscfg: fallback to default_kernelopts if BLS option field
388b8a4
 isn't set
388b8a4
388b8a4
If the $kernelopts variable isn't found, then the entry will fail to boot
388b8a4
since there won't be a kernel command line params set. This makes the BLS
388b8a4
configuration more fragile than a non-BLS one, since in that case it will
388b8a4
boot even without a correct grubenv file.
388b8a4
388b8a4
So set a $default_kernelopts in the GRUB config file that will be used as
388b8a4
a fallback if the value in the BLS options field can't be resolved.
388b8a4
388b8a4
Related: rhbz#1625124
388b8a4
388b8a4
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
388b8a4
---
388b8a4
 grub-core/commands/blscfg.c | 7 +++++++
388b8a4
 util/grub.d/10_linux.in     | 2 ++
388b8a4
 2 files changed, 9 insertions(+)
388b8a4
388b8a4
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
388b8a4
index 1ef2ae06cff..5635066e3eb 100644
388b8a4
--- a/grub-core/commands/blscfg.c
388b8a4
+++ b/grub-core/commands/blscfg.c
388b8a4
@@ -629,6 +629,9 @@ static char *expand_val(char *value)
388b8a4
   char *end = value;
388b8a4
   bool is_var = false;
388b8a4
 
388b8a4
+  if (!value)
388b8a4
+    return NULL;
388b8a4
+
388b8a4
   while (*value) {
388b8a4
     if (*value == '$') {
388b8a4
       if (start != end) {
388b8a4
@@ -732,6 +735,10 @@ static void create_entry (struct bls_entry *entry)
388b8a4
 
388b8a4
   title = bls_get_val (entry, "title", NULL);
388b8a4
   options = expand_val (bls_get_val (entry, "options", NULL));
388b8a4
+
388b8a4
+  if (!options)
388b8a4
+    options = expand_val (grub_env_get("default_kernelopts"));
388b8a4
+
388b8a4
   initrds = bls_make_list (entry, "initrd", NULL);
388b8a4
 
388b8a4
   hotkey = bls_get_val (entry, "grub_hotkey", NULL);
388b8a4
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
388b8a4
index 22a85c69ea0..2547dd52115 100644
388b8a4
--- a/util/grub.d/10_linux.in
388b8a4
+++ b/util/grub.d/10_linux.in
388b8a4
@@ -158,6 +158,8 @@ linux_entry ()
388b8a4
     populate_header_warn
388b8a4
 
388b8a4
     cat << EOF
388b8a4
+set default_kernelopts="root=${linux_root_device_thisversion} ro ${args}"
388b8a4
+
388b8a4
 insmod blscfg
388b8a4
 blscfg
388b8a4
 if [ -s \$prefix/grubenv ]; then