@@ -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 )
0 commit comments