Skip to content

Commit

Permalink
bootloader: utilize grub2-common posttrans script for handling config…
Browse files Browse the repository at this point in the history
… file generation

Our backend now executes the grub2-common posttrans script to generate
grub config files. This is an ugly hack, but still better than having
this logic on our side.
I requested that this logic get's extracted to some sanely reusable
helper scripts: https://bugzilla.redhat.com/show_bug.cgi?id=2327644
  • Loading branch information
KKoukiou committed Nov 20, 2024
1 parent 1176b22 commit 8a6a14d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
2 changes: 2 additions & 0 deletions anaconda.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Requires: python3-pid
Requires: crypto-policies
Requires: crypto-policies-scripts

Requires: grub2-common

# required because of the rescue mode and RDP question
Requires: anaconda-tui = %{version}-%{release}

Expand Down
25 changes: 0 additions & 25 deletions pyanaconda/modules/storage/bootloader/efi.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,31 +177,6 @@ def efi_config_file(self):
""" Full path to EFI configuration file. """
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")

super().write_config()


class EFISystemdBoot(EFIBase, SystemdBoot):
"""EFI Systemd-boot"""
Expand Down
25 changes: 17 additions & 8 deletions pyanaconda/modules/storage/bootloader/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pyanaconda.core import util
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.core.i18n import _
from pyanaconda.core.path import open_with_perm
from pyanaconda.core.path import join_paths, open_with_perm
from pyanaconda.core.product import get_product_name

from pyanaconda.anaconda_loggers import get_module_logger
Expand Down Expand Up @@ -363,14 +363,23 @@ def write_config(self):
if rc:
log.error("failed to set menu_auto_hide=1")

# now tell grub2 to generate the main configuration file
rc = util.execWithRedirect(
"grub2-mkconfig",
["-o", self.config_file],
root=conf.target.system_root
)
# Executes the grub2-common posttrans script to generate grub config files
# This should be autohandled by grub2-common, but posttrans scriptlets
# in live image scenarios are not triggered.
# FIXME: https://bugzilla.redhat.com/show_bug.cgi?id=2327644

# Drop the first line as it's the posttrans scriptlet header
script = util.execWithCapture("rpm", ["-q", "--scripts", "grub2-common"], root=conf.target.system_root).splitlines()[1:]
script = "\n".join(script)

# Write the script to a temporary file in the chroot
with open(join_paths(conf.target.system_root, "/tmp/grub2-posttrans.sh"), "w") as f:
f.write(script)

# Run the script in the chroot
rc = util.execWithRedirect("/bin/sh", ["/tmp/grub2-posttrans.sh"], root=conf.target.system_root)
if rc:
raise BootLoaderError("failed to write boot loader configuration")
raise BootLoaderError("grub2-common posttrans script failed")

#
# installation
Expand Down

0 comments on commit 8a6a14d

Please sign in to comment.