Skip to content

Commit

Permalink
bootloader: use grub2-mkconfig for EFI boot entry generation
Browse files Browse the repository at this point in the history
This patch simplifies the EFI GRUB configuration generation by replacing the manual config
file writing with a `grub2-mkconfig` command. By doing so, we avoid direct file handling
and path resolution issues, leveraging `grub2-mkconfig` to set up the correct paths and UUIDs.

Additionally, this change enables OS Prober in `grub.cfg` generation by default, ensuring that
other operating systems are detected and added to the boot menu automatically. This is particularly
useful for multi-boot environments, as it allows the system to recognize existing OS installations
without additional configuration.
  • Loading branch information
KKoukiou committed Nov 14, 2024
1 parent 50e55fd commit 1a76933
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
25 changes: 4 additions & 21 deletions pyanaconda/modules/storage/bootloader/efi.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,10 @@ def efi_config_file(self):
return "%s/%s" % (self.efi_config_dir, self._config_file)

def write_config(self):
config_path = "%s%s" % (conf.target.system_root, self.efi_config_file)

with open(config_path, "w") as fd:
grub_dir = self.config_dir
if self.stage2_device.format.type != "btrfs":
fs_uuid = self.stage2_device.format.uuid
else:
fs_uuid = self.stage2_device.format.vol_uuid

if fs_uuid is None:
raise BootLoaderError("Could not get stage2 filesystem UUID")

grub_dir = util.execWithCapture("grub2-mkrelpath", [grub_dir],
root=conf.target.system_root)
if not grub_dir:
raise BootLoaderError("Could not get GRUB directory path")

fd.write("search --no-floppy --fs-uuid --set=dev %s\n" % fs_uuid)
fd.write("set prefix=($dev)%s\n" % grub_dir)
fd.write("export $prefix\n")
fd.write("configfile $prefix/grub.cfg\n")
""" Run grub2-mkconfig to generate the EFI grub.cfg file for the new system. """
ret = util.execWithRedirect("grub2-mkconfig", ["-o", self.efi_config_file], root=conf.target.system_root)
if ret != 0:
raise BootLoaderError("failed to generate EFI grub.cfg file.")

super().write_config()

Expand Down
1 change: 1 addition & 0 deletions pyanaconda/modules/storage/bootloader/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def write_device_map(self):
def write_defaults(self):
defaults_file = "%s%s" % (conf.target.system_root, self.defaults_file)
defaults = open(defaults_file, "w+")
defaults.write("GRUB_DISABLE_OS_PROBER=false\n")
defaults.write("GRUB_TIMEOUT=%d\n" % self.timeout)
defaults.write("GRUB_DISTRIBUTOR=\"$(sed 's, release .*$,,g' /etc/system-release)\"\n")
defaults.write("GRUB_DEFAULT=saved\n")
Expand Down

0 comments on commit 1a76933

Please sign in to comment.