@@ -922,6 +922,30 @@ def update_grub_rpm(remote, newversion):
922922 grub2_kernel_select_generic (remote , newversion , 'rpm' )
923923
924924
925+ def _update_uefi_grub_config (remote , grubconfig ):
926+ """
927+ Update UEFI GRUB config if UEFI is being used.
928+ UEFI boots from /boot/efi/EFI/<vendor>/grub.cfg
929+
930+ We copy the generated grub.cfg to all EFI vendor directories to ensure
931+ the correct one is updated, as different systems may use different
932+ vendor directories (e.g., /boot/efi/EFI/BOOT, /boot/efi/EFI/centos).
933+ """
934+ try :
935+ # Update all EFI vendor directories to ensure the correct one is updated
936+ efi_vendors = remote .sh ('find /boot/efi/EFI/ -mindepth 1 -maxdepth 1 -type d' ).strip ()
937+ if efi_vendors :
938+ for efi_vendor in efi_vendors .split ('\n ' ):
939+ efi_vendor = efi_vendor .strip ()
940+ if efi_vendor :
941+ remote .run (args = ['sudo' , 'cp' , grubconfig , '{}/grub.cfg' .format (efi_vendor )])
942+ log .info ("Updated UEFI GRUB config at {}/grub.cfg" .format (efi_vendor ))
943+ else :
944+ log .warning ("Could not find EFI vendor directory in /boot/efi/EFI/, skipping UEFI GRUB config update" )
945+ except Exception as e :
946+ log .warning ("Failed to update UEFI GRUB config: {error}" .format (error = e ))
947+
948+
925949def grub2_kernel_select_generic (remote , newversion , ostype ):
926950 """
927951 Can be used on DEB and RPM. Sets which entry should be boted by entrynum.
@@ -936,7 +960,32 @@ def grub2_kernel_select_generic(remote, newversion, ostype):
936960 grubset = 'grub-set-default'
937961 grubconfig = '/boot/grub/grub.cfg'
938962 mkconfig = 'grub-mkconfig'
963+
964+ # check if BLS system - check if GRUB_ENABLE_BLSCFG is enabled
965+ # The /boot/loader/entries directory may exist even when BLS is disabled
966+ has_bls = False
967+ try :
968+ grub_default_file = '/etc/default/grub'
969+ result = remote .run (args = ['test' , '-f' , grub_default_file ], check_status = False )
970+ if result .exitstatus == 0 :
971+ content = remote .sh ('sudo cat {file}' .format (file = grub_default_file )).strip ()
972+ if 'GRUB_ENABLE_BLSCFG=true' in content :
973+ has_bls = True
974+ except Exception as e :
975+ log .warning ("Failed to check /etc/default/grub: {error}" .format (error = e ))
976+
939977 remote .run (args = ['sudo' , mkconfig , '-o' , grubconfig , ])
978+ # only update UEFI GRUB config if system is UEFI and not using BLS
979+ result = remote .run (args = ['test' , '-d' , '/sys/firmware/efi' ], check_status = False )
980+ is_uefi = (result .exitstatus == 0 )
981+ if is_uefi :
982+ if not has_bls :
983+ _update_uefi_grub_config (remote , grubconfig )
984+ else :
985+ log .debug ("BLS system detected, skipping UEFI GRUB config update" )
986+ else :
987+ log .debug ("Not a UEFI system, skipping UEFI GRUB config update" )
988+
940989 grub2conf = teuthology .get_file (remote , grubconfig , sudo = True ).decode ()
941990 entry_num = 0
942991 if '\n menuentry ' not in grub2conf :
0 commit comments