Skip to content

Commit

Permalink
Replace the regex-based loader entry fix with string parsing (#2388)
Browse files Browse the repository at this point in the history
A user building RHEL images ran into issues with the initrd. 
It turns out that RHEL uses some patches that mean the
initrd/linux files in RHEL are not installed to /boot, which trips
up the original regex. The new fix doesn't rely on matching the
path in boot, instead just finding the initrd/linux files and rewriting
them in place.

This change also adds the pre-and-post fix loader entries to the debug logs.

Reference: https://bugzilla.suse.com/1208701

Fixes suse bsc#1208701
  • Loading branch information
KaliumPuceon authored Nov 10, 2023
1 parent 7447203 commit 24fe960
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions kiwi/bootloader/config/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,19 +1460,24 @@ def _fix_grub_loader_entries_linux_and_initrd_paths(self):
)
for menu_entry_file in glob.iglob(loader_entries_pattern):
with open(menu_entry_file) as grub_menu_entry_file:
menu_entry = grub_menu_entry_file.read()
if self.bootpartition:
menu_entry = re.sub(
r'(linux|initrd) .*/boot(.*)',
r'\1 \2',
menu_entry
)
else:
menu_entry = re.sub(
r'(linux|initrd) .*(/boot.*)',
r'\1 \2',
menu_entry
)
menu_entry = grub_menu_entry_file.read().split(os.linesep)

for line_number, menu_entry_line in enumerate(menu_entry):
if bool(re.match(r'^(linux|initrd) .*', menu_entry_line)):

log.debug(f'Existing loader entry: {menu_entry_line}')
config_path = menu_entry_line.split(' ', 1)[0]

basename = os.path.basename(menu_entry_line)
if self.bootpartition:
config_path = (f'{config_path} /{basename}')
else:
config_path = (f'{config_path} /boot/{basename}')

menu_entry[line_number] = config_path
log.debug(f'Updated loader entry: {config_path}')

menu_entry = os.linesep.join(menu_entry)
with open(menu_entry_file, 'w') as grub_menu_entry_file:
grub_menu_entry_file.write(menu_entry)

Expand Down

0 comments on commit 24fe960

Please sign in to comment.