@@ -1325,6 +1325,7 @@ def _add_grub_bootloader(
13251325 boot_partition : PartitionModification ,
13261326 root : PartitionModification | LvmVolume ,
13271327 efi_partition : PartitionModification | None ,
1328+ uki_enabled : bool = False ,
13281329 bootloader_removable : bool = False ,
13291330 ) -> None :
13301331 debug ('Installing grub bootloader' )
@@ -1396,6 +1397,37 @@ def _add_grub_bootloader(
13961397 except SysCallError as err :
13971398 raise DiskError (f'Failed to install GRUB boot on { boot_partition .dev_path } : { err } ' )
13981399
1400+ # Add custom UKI entries if enabled
1401+ if uki_enabled and SysInfo .has_uefi () and efi_partition :
1402+ custom_entries = self .target / 'etc/grub.d/09_custom'
1403+ entries_content = (
1404+ '#!/bin/sh\n '
1405+ 'exec tail -n +3 $0\n '
1406+ '# This file provides UKI (Unified Kernel Image) boot entries.\n '
1407+ '# Generated by archinstall. Do not modify the exec tail line above.\n '
1408+ '# Custom entries can be added below.\n \n '
1409+ )
1410+
1411+ uki_entries = []
1412+ for kernel in self .kernels :
1413+ entry = textwrap .dedent (
1414+ f"""
1415+ menuentry "Arch Linux ({ kernel } ) UKI" {{
1416+ uki /EFI/Linux/arch-{ kernel } .efi
1417+ }}
1418+ """
1419+ )
1420+ uki_entries .append (entry )
1421+
1422+ entries_content += '\n ' .join (uki_entries )
1423+ custom_entries .write_text (entries_content )
1424+ custom_entries .chmod (0o755 )
1425+
1426+ # Disable 10_linux to prevent broken entries on kernel updates
1427+ linux_script = self .target / 'etc/grub.d/10_linux'
1428+ if linux_script .exists ():
1429+ linux_script .chmod (0o644 )
1430+
13991431 try :
14001432 self .arch_chroot (
14011433 f'grub-mkconfig -o { boot_dir } /grub/grub.cfg' ,
@@ -1669,29 +1701,28 @@ def _add_refind_bootloader(
16691701 kernel_params = ' ' .join (self ._get_kernel_params (root ))
16701702
16711703 for kernel in self .kernels :
1672- for variant in ('' , '-fallback' ):
1673- if uki_enabled :
1674- entry = f'"Arch Linux ({ kernel } { variant } ) UKI" "{ kernel_params } "'
1675- else :
1676- if boot_on_root :
1677- # Kernels are in /boot subdirectory of root filesystem
1678- if hasattr (root , 'btrfs_subvols' ) and root .btrfs_subvols :
1679- # Root is btrfs with subvolume, find the root subvolume
1680- root_subvol = next ((sv for sv in root .btrfs_subvols if sv .is_root ()), None )
1681- if root_subvol :
1682- subvol_name = root_subvol .name
1683- initrd_path = f'initrd={ subvol_name } \\ boot\\ initramfs-{ kernel } { variant } .img'
1684- else :
1685- initrd_path = f'initrd=\\ boot\\ initramfs-{ kernel } { variant } .img'
1704+ if uki_enabled :
1705+ entry = f'"Arch Linux ({ kernel } ) UKI" "{ kernel_params } "'
1706+ else :
1707+ if boot_on_root :
1708+ # Kernels are in /boot subdirectory of root filesystem
1709+ if hasattr (root , 'btrfs_subvols' ) and root .btrfs_subvols :
1710+ # Root is btrfs with subvolume, find the root subvolume
1711+ root_subvol = next ((sv for sv in root .btrfs_subvols if sv .is_root ()), None )
1712+ if root_subvol :
1713+ subvol_name = root_subvol .name
1714+ initrd_path = f'initrd={ subvol_name } \\ boot\\ initramfs-{ kernel } .img'
16861715 else :
1687- # Root without btrfs subvolume
1688- initrd_path = f'initrd=\\ boot\\ initramfs-{ kernel } { variant } .img'
1716+ initrd_path = f'initrd=\\ boot\\ initramfs-{ kernel } .img'
16891717 else :
1690- # Kernels are at root of their partition (ESP or separate boot partition)
1691- initrd_path = f'initrd=\\ initramfs-{ kernel } { variant } .img'
1692- entry = f'"Arch Linux ({ kernel } { variant } )" "{ kernel_params } { initrd_path } "'
1718+ # Root without btrfs subvolume
1719+ initrd_path = f'initrd=\\ boot\\ initramfs-{ kernel } .img'
1720+ else :
1721+ # Kernels are at root of their partition (ESP or separate boot partition)
1722+ initrd_path = f'initrd=\\ initramfs-{ kernel } .img'
1723+ entry = f'"Arch Linux ({ kernel } )" "{ kernel_params } { initrd_path } "'
16931724
1694- config_contents .append (entry )
1725+ config_contents .append (entry )
16951726
16961727 config_path .write_text ('\n ' .join (config_contents ) + '\n ' )
16971728
@@ -1823,7 +1854,7 @@ def add_bootloader(self, bootloader: Bootloader, uki_enabled: bool = False, boot
18231854 case Bootloader .Systemd :
18241855 self ._add_systemd_bootloader (boot_partition , root , efi_partition , uki_enabled )
18251856 case Bootloader .Grub :
1826- self ._add_grub_bootloader (boot_partition , root , efi_partition , bootloader_removable )
1857+ self ._add_grub_bootloader (boot_partition , root , efi_partition , uki_enabled , bootloader_removable )
18271858 case Bootloader .Efistub :
18281859 self ._add_efistub_bootloader (boot_partition , root , uki_enabled )
18291860 case Bootloader .Limine :
0 commit comments