Skip to content

Commit 4e82862

Browse files
committed
Add support for rEFInd boot manager
1 parent 2f05481 commit 4e82862

3 files changed

Lines changed: 79 additions & 2 deletions

File tree

archinstall/lib/global_menu.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ def _validate_bootloader(self) -> str | None:
456456
if boot_partition.fs_type not in [FilesystemType.Fat12, FilesystemType.Fat16, FilesystemType.Fat32]:
457457
return 'Limine does not support booting with a non-FAT boot partition'
458458

459+
elif bootloader == Bootloader.Refind:
460+
if not SysInfo.has_uefi():
461+
return 'rEFInd can only be used on UEFI systems'
462+
459463
return None
460464

461465
def _prev_install_invalid_config(self, item: MenuItem) -> str | None:

archinstall/lib/installer.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,75 @@ def _add_efistub_bootloader(
15301530

15311531
self._helper_flags['bootloader'] = 'efistub'
15321532

1533+
def _add_refind_bootloader(
1534+
self,
1535+
boot_partition: PartitionModification,
1536+
efi_partition: PartitionModification | None,
1537+
root: PartitionModification | LvmVolume,
1538+
uki_enabled: bool = False,
1539+
) -> None:
1540+
debug('Installing rEFInd bootloader')
1541+
1542+
self.pacman.strap('refind')
1543+
1544+
if not SysInfo.has_uefi():
1545+
raise HardwareIncompatibilityError
1546+
1547+
if not efi_partition:
1548+
raise ValueError('Could not detect EFI system partition')
1549+
elif not efi_partition.mountpoint:
1550+
raise ValueError('EFI system partition is not mounted')
1551+
1552+
info(f'rEFInd EFI partition: {efi_partition.dev_path}')
1553+
1554+
try:
1555+
SysCommand(f'arch-chroot {self.target} refind-install')
1556+
except SysCallError as err:
1557+
raise DiskError(f'Could not install rEFInd to {self.target}{efi_partition.mountpoint}: {err}')
1558+
1559+
if not boot_partition.mountpoint:
1560+
raise ValueError("Boot partition is not mounted, cannot write rEFInd config")
1561+
1562+
config_path = self.target / boot_partition.mountpoint.relative_to('/') / 'refind_linux.conf'
1563+
config_contents = []
1564+
1565+
kernel_params = ' '.join(self._get_kernel_params(root))
1566+
1567+
for kernel in self.kernels:
1568+
for variant in ('', '-fallback'):
1569+
if uki_enabled:
1570+
entry = f'"Arch Linux ({kernel}{variant}) UKI" "{kernel_params}"'
1571+
else:
1572+
initrd_path = f'initrd=\\initramfs-{kernel}{variant}.img'
1573+
entry = f'"Arch Linux ({kernel}{variant})" "{kernel_params} {initrd_path}"'
1574+
1575+
config_contents.append(entry)
1576+
1577+
config_path.write_text('\n'.join(config_contents) + '\n')
1578+
1579+
hook_contents = textwrap.dedent(
1580+
'''\
1581+
[Trigger]
1582+
Operation = Install
1583+
Operation = Upgrade
1584+
Type = Package
1585+
Target = refind
1586+
1587+
[Action]
1588+
Description = Updating rEFInd on ESP
1589+
When = PostTransaction
1590+
Exec = /usr/bin/refind-install
1591+
'''
1592+
)
1593+
1594+
hooks_dir = self.target / 'etc' / 'pacman.d' / 'hooks'
1595+
hooks_dir.mkdir(parents=True, exist_ok=True)
1596+
1597+
hook_path = hooks_dir / '99-refind.hook'
1598+
hook_path.write_text(hook_contents)
1599+
1600+
self._helper_flags['bootloader'] = 'refind'
1601+
15331602
def _config_uki(
15341603
self,
15351604
root: PartitionModification | LvmVolume,
@@ -1583,11 +1652,12 @@ def _config_uki(
15831652
def add_bootloader(self, bootloader: Bootloader, uki_enabled: bool = False) -> None:
15841653
"""
15851654
Adds a bootloader to the installation instance.
1586-
Archinstall supports one of three types:
1655+
Archinstall supports one of five types:
15871656
* systemd-bootctl
15881657
* grub
15891658
* limine (beta)
15901659
* efistub (beta)
1660+
* refnd (beta)
15911661
15921662
:param bootloader: Type of bootloader to be added
15931663
"""
@@ -1623,6 +1693,8 @@ def add_bootloader(self, bootloader: Bootloader, uki_enabled: bool = False) -> N
16231693
self._add_efistub_bootloader(boot_partition, root, uki_enabled)
16241694
case Bootloader.Limine:
16251695
self._add_limine_bootloader(boot_partition, efi_partition, root, uki_enabled)
1696+
case Bootloader.Refind:
1697+
self._add_refind_bootloader(boot_partition, efi_partition, root, uki_enabled)
16261698

16271699
def add_additional_packages(self, packages: str | list[str]) -> None:
16281700
return self.pacman.strap(packages)

archinstall/lib/models/bootloader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ class Bootloader(Enum):
1313
Grub = 'Grub'
1414
Efistub = 'Efistub'
1515
Limine = 'Limine'
16+
Refind = 'rEFInd'
1617

1718
def has_uki_support(self) -> bool:
1819
match self:
19-
case Bootloader.Efistub | Bootloader.Limine | Bootloader.Systemd:
20+
case Bootloader.Efistub | Bootloader.Limine | Bootloader.Systemd | Bootloader.Refind:
2021
return True
2122
case _:
2223
return False

0 commit comments

Comments
 (0)