From b9d962bec2466d096b38c5c4e519e79c0162a0eb Mon Sep 17 00:00:00 2001 From: codefiles <11915375+codefiles@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:14:47 -0400 Subject: Refactor `_add_grub_bootloader()` installation (#1968) * Refactor `_add_grub_bootloader()` installation * Remove whitespace --- archinstall/lib/installer.py | 52 +++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'archinstall/lib/installer.py') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index d010e8a1..c32069c3 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -876,45 +876,43 @@ class Installer: info(f"GRUB boot partition: {boot_partition.dev_path}") + command = [ + '/usr/bin/arch-chroot', + str(self.target), + 'grub-install', + '--debug' + ] + if SysInfo.has_uefi(): self.pacman.strap('efibootmgr') # TODO: Do we need? Yes, but remove from minimal_installation() instead? + add_options = [ + '--target=x86_64-efi', + f'--efi-directory={boot_partition.mountpoint}', + '--bootloader-id=GRUB', + '--removable' + ] + + command.extend(add_options) + try: - SysCommand( - f'/usr/bin/arch-chroot {self.target} grub-install ' - f'--debug ' - f'--target=x86_64-efi ' - f'--efi-directory={boot_partition.mountpoint} ' - f'--bootloader-id=GRUB ' - f'--removable', - peek_output=True - ) + SysCommand(command, peek_output=True) except SysCallError: try: - SysCommand( - f'/usr/bin/arch-chroot {self.target} ' - f'grub-install ' - f'--debug ' - f'--target=x86_64-efi ' - f'--efi-directory={boot_partition.mountpoint} ' - f'--bootloader-id=GRUB ' - f'--removable', - peek_output=True - ) + SysCommand(command, peek_output=True) except SysCallError as err: raise DiskError(f"Could not install GRUB to {self.target}{boot_partition.mountpoint}: {err}") else: parent_dev_path = disk.device_handler.get_parent_device_path(boot_partition.safe_dev_path) - try: - cmd = f'/usr/bin/arch-chroot' \ - f' {self.target}' \ - f' grub-install' \ - f' --debug' \ - f' --target=i386-pc' \ - f' --recheck {parent_dev_path}' + add_options = [ + '--target=i386-pc', + '--recheck', + str(parent_dev_path) + ] - SysCommand(cmd, peek_output=True) + try: + SysCommand(command + add_options, peek_output=True) except SysCallError as err: raise DiskError(f"Failed to install GRUB boot on {boot_partition.dev_path}: {err}") -- cgit v1.2.3-54-g00ecf