From: Michael Tremer Date: Sun, 5 Feb 2023 17:59:42 +0000 (+0000) Subject: bootloaders: Write a proper GRUB configuration file X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=648deb2482af61fc72a25c8ade0c8219f0415f48;p=people%2Fms%2Fbricklayer.git bootloaders: Write a proper GRUB configuration file Signed-off-by: Michael Tremer --- diff --git a/src/python/__init__.py b/src/python/__init__.py index e92e8ac..03edb7e 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -217,6 +217,20 @@ class Bricklayer(object): with open("/etc/os-release") as f: return util.config_read(f) + def open(self, path, *args, **kwargs): + """ + Opens a file inside the environment + """ + # Make the path relative + while path.startswith("/"): + path = path[1:] + + # Make the path relative to the root directory + path = os.path.join(self.root, path) + + # Open the file and return the handle + return open(path, *args, **kwargs) + def command(self, command, error_ok=False, interactive=False, chroot=False, bind=None): """ Runs a command in a shell environment diff --git a/src/python/bootloaders.py b/src/python/bootloaders.py index d8cb906..665daeb 100644 --- a/src/python/bootloaders.py +++ b/src/python/bootloaders.py @@ -27,6 +27,8 @@ from .i18n import _, N_ # Setup logging log = logging.getLogger("bricklayer.bootloaders") +GRUB_TIMEOUT = 5 + class Bootloader(object): """ A generic class for bootloaders @@ -82,6 +84,9 @@ class Grub(Bootloader): requires_bootldr_partition = True def install(self): + # Write the configuration file + self.write_configuration() + # Install GRUB2 on all disks that have been selected for disk in self.bricklayer.disks.selected: self.install_on_disk(disk) @@ -107,6 +112,41 @@ class Grub(Bootloader): *self.grub_args, disk.path, ], chroot=True, bind=["/dev", "/proc", "/sys"]) + def write_configuration(self): + """ + This method writes /etc/default/grub + """ + log.debug("Writing GRUB Configuration:") + + conf = { + # Tell GRUB who we are + "GRUB_DISTRIBUTOR" : "\"$(sed 's, release .*$,,g' /etc/system-release)\"", + + # Give the user a moment to select an option + "GRUB_TIMEOUT" : GRUB_TIMEOUT, + + # Remember the selected option + "GRUB_DEFAULT" : "saved", + + # Do not show a submenu + "GRUB_DISABLE_SUBMENU" : "true", + + # Disable the recovery option + "GRUB_DISABLE_RECOVERY" : "true", + } + + # XXX Handle serial console + conf["GRUB_TERMINAL_OUTPUT"] = "\"console\"" + + # Write everything to file + with self.bricklayer.open("/etc/default/grub", "w") as f: + for key, val in conf.items(): + # Log the line + log.debug(" %s = %s" % (key, val)) + + # Write the line to file + f.write("%s=%s\n" % (key, val)) + def install_configuration(self): """ Generates a GRUB configuration file