From 4d0e18eb24bf0e8e554517e445245969943c9c93 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 14 Apr 2020 17:56:02 +0200 Subject: [PATCH] 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. --- stages/org.osbuild.grub2 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/stages/org.osbuild.grub2 b/stages/org.osbuild.grub2 index a716b3b1..f7027543 100755 --- a/stages/org.osbuild.grub2 +++ b/stages/org.osbuild.grub2 @@ -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"