Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GRUB with non-/boot ESP #2015

Merged
merged 5 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions archinstall/lib/disk/device_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,20 +788,25 @@ def add_partition(self, partition: PartitionModification):
def get_efi_partition(self) -> Optional[PartitionModification]:
"""
Similar to get_boot_partition() but excludes XBOOTLDR partitions from it's candidates.
Also works with ESP flag.
"""
filtered = filter(lambda x: x.is_boot() and x.fs_type == FilesystemType.Fat32 and PartitionFlag.XBOOTLDR not in x.flags, self.partitions)
filtered = filter(lambda x: (x.is_boot() or PartitionFlag.ESP in x.flags) and x.fs_type == FilesystemType.Fat32 and PartitionFlag.XBOOTLDR not in x.flags, self.partitions)
return next(filtered, None)

def get_boot_partition(self) -> Optional[PartitionModification]:
"""
Returns the first partition marked as XBOOTLDR (PARTTYPE id of bc13c2ff-...) or Boot and has a mountpoint.
Only returns XBOOTLDR if separate EFI is detected using self.get_efi_partition()
Will return None if no suitable partition is found.
"""
if efi_partition := self.get_efi_partition():
filtered = filter(lambda x: x.is_boot() and x != efi_partition and x.mountpoint, self.partitions)
if boot_partition := next(filtered, None):
return boot_partition
return efi_partition
if efi_partition.is_boot():
return efi_partition
else:
return None
else:
filtered = filter(lambda x: x.is_boot() and x.mountpoint, self.partitions)
return next(filtered, None)
Expand Down
24 changes: 15 additions & 9 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,9 @@ def _add_systemd_bootloader(

def _add_grub_bootloader(
self,
boot_partition: disk.PartitionModification,
root_partition: disk.PartitionModification
boot_partition: Optional[disk.PartitionModification],
root_partition: disk.PartitionModification,
efi_partition: Optional[disk.PartitionModification]
):
self.pacman.strap('grub') # no need?

Expand All @@ -874,19 +875,21 @@ def _add_grub_bootloader(
config = re.sub(r'(GRUB_CMDLINE_LINUX=")("\n)', rf'\1{" ".join(cmdline_linux)}\2', config, 1)
grub_default.write_text(config)

info(f"GRUB boot partition: {boot_partition.dev_path}")

if SysInfo.has_uefi():
info(f"GRUB EFI partition: {efi_partition.dev_path}")

self.pacman.strap('efibootmgr') # TODO: Do we need? Yes, but remove from minimal_installation() instead?

try:
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory={boot_partition.mountpoint} --bootloader-id=GRUB --removable', peek_output=True)
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory={efi_partition.mountpoint} {f'--boot-directory={boot_partition.mountpoint}' if boot_partition} --bootloader-id=GRUB --removable', peek_output=True)
except SysCallError:
try:
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory={boot_partition.mountpoint} --bootloader-id=GRUB --removable', peek_output=True)
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --debug --target=x86_64-efi --efi-directory={efi_partition.mountpoint} {f'--boot-directory={boot_partition.mountpoint}' if boot_partition} --bootloader-id=GRUB --removable', peek_output=True)
except SysCallError as err:
raise DiskError(f"Could not install GRUB to {self.target}{boot_partition.mountpoint}: {err}")
raise DiskError(f"Could not install GRUB to {self.target}{efi_partition.mountpoint}: {err}")
else:
info(f"GRUB boot partition: {boot_partition.dev_path}")

device = disk.device_handler.get_device_by_partition_path(boot_partition.safe_dev_path)

if not device:
Expand All @@ -905,7 +908,10 @@ def _add_grub_bootloader(
raise DiskError(f"Failed to install GRUB boot on {boot_partition.dev_path}: {err}")

try:
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-mkconfig -o {boot_partition.mountpoint}/grub/grub.cfg')
if boot_partition != None:
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-mkconfig -o {boot_partition.mountpoint}/grub/grub.cfg')
else:
SysCommand(f'/usr/bin/arch-chroot {self.target} grub-mkconfig -o /boot/grub/grub.cfg')
except SysCallError as err:
raise DiskError(f"Could not configure GRUB: {err}")

Expand Down Expand Up @@ -1115,7 +1121,7 @@ def add_bootloader(self, bootloader: Bootloader):
case Bootloader.Systemd:
self._add_systemd_bootloader(boot_partition, root_partition, efi_partition)
case Bootloader.Grub:
self._add_grub_bootloader(boot_partition, root_partition)
self._add_grub_bootloader(boot_partition, root_partition, efi_partition)
case Bootloader.Efistub:
self._add_efistub_bootloader(boot_partition, root_partition)
case Bootloader.Limine:
Expand Down
Loading