stages/grub2: opt-out option for /etc/default/grub

The file `/etc/defaults/grub` sets the defaults that are used by
grub2-mkconfig to (re-)generate the grub config (grub.cfg). This
command is not run by any scripts but by the user directly. On
modern installations (without the grubby-deprecated package)
the kernel is configured via Bootloader Specification snippets
and thus the grub config should not need to be touched at all
under normal circumstances. In the new future the grub2-mkconfig
will be updated to not require GRUB_ENABLE_BLSCFG which should
make the existence `/etc/defaults/grub` even more superfluous.
Additionally, in the future, some images might not contain
the grub2 packages at all.
This commit is contained in:
Christian Kellner 2020-04-14 17:56:02 +02:00 committed by David Rheinsberg
parent c15b3e6cf4
commit 4d0e18eb24

View file

@ -89,6 +89,11 @@ STAGE_OPTS = """
"default": false
}
}
},
"write_defaults": {
"description": "Whether to write /etc/defaults/grub",
"type": "boolean",
"default": true
}
}
"""
@ -152,6 +157,7 @@ def main(tree, options):
kernel_opts = options.get("kernel_opts", "")
legacy = options.get("legacy", None)
uefi = options.get("uefi", None)
write_defaults = options.get("write_defaults", True)
# legacy boolean means the
if isinstance(legacy, bool) and legacy:
@ -169,10 +175,11 @@ def main(tree, options):
separate_boot = boot_fs_uuid is not None
# Create the configuration file that determines how grub.cfg is generated.
os.makedirs(f"{tree}/etc/default", exist_ok=True)
with open(f"{tree}/etc/default/grub", "w") as default:
default.write("GRUB_TIMEOUT=0\n"
"GRUB_ENABLE_BLSCFG=true\n")
if write_defaults:
os.makedirs(f"{tree}/etc/default", exist_ok=True)
with open(f"{tree}/etc/default/grub", "w") as default:
default.write("GRUB_TIMEOUT=0\n"
"GRUB_ENABLE_BLSCFG=true\n")
os.makedirs(f"{tree}/boot/grub2", exist_ok=True)
grubenv = f"{tree}/boot/grub2/grubenv"