2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 17:43:14 +00:00

Reinstate linuxefi/initrdefi for older GRUB

Technically, Grub never had 'linuxefi/initrdefi' commands
officially, so this is a bit weird.

However, if we see signs of GRUB older than 2.03, we will assume
that is requires the linuxefi/initrdefi commands from
the out of tree patch to support EFI the old way.

This corresponds with EL7.  Other variants seem ok with
the more proper linux/initrd command names.
This commit is contained in:
Jarrod Johnson 2024-07-15 11:26:58 -04:00
parent 5d08919769
commit abf12f2b96

View File

@ -165,9 +165,27 @@ def find_glob(loc, fileglob):
def update_boot_linux(profiledir, profile, label):
profname = os.path.basename(profiledir)
kernelargs = profile.get('kernelargs', '')
needefi = False
for grubexe in glob.glob(profiledir + '/boot/efi/boot/grubx64.efi'):
with open(grubexe, 'rb') as grubin:
grubcontent = grubin.read()
uaidx = grubcontent.find(b'User-Agent: GRUB 2.0')
if uaidx > 0:
grubcontent = grubcontent[uaidx:]
cridx = grubcontent.find(b'\r')
if cridx > 1:
grubcontent = grubcontent[:cridx]
grubver = grubcontent.split(b'~', 1)[0]
grubver = grubver.rsplit(b' ', 1)[-1]
grubver = grubver.split(b'.')
if len(grubver) > 1:
if int(grubver[0]) < 3 and int(grubver[1]) < 3:
needefi = True
lincmd = 'linuxefi' if needefi else 'linux'
initrdcmd = 'initrdefi' if needefi else 'initrd'
grubcfg = "set timeout=5\nmenuentry '"
grubcfg += label
grubcfg += "' {\n linux /kernel " + kernelargs + "\n"
grubcfg += "' {\n " + lincmd + " /kernel " + kernelargs + "\n"
initrds = []
for initramfs in glob.glob(profiledir + '/boot/initramfs/*.cpio'):
initramfs = os.path.basename(initramfs)
@ -175,7 +193,7 @@ def update_boot_linux(profiledir, profile, label):
for initramfs in os.listdir(profiledir + '/boot/initramfs'):
if initramfs not in initrds:
initrds.append(initramfs)
grubcfg += " initrd "
grubcfg += " " + initrdcmd + " "
for initramfs in initrds:
grubcfg += " /initramfs/{0}".format(initramfs)
grubcfg += "\n}\n"