Skip to content

Commit

Permalink
Fix mbrid setup for read-only systems
Browse files Browse the repository at this point in the history
On filesystems without a UUID (e.g squashfs) the fallback boot id
setup should apply if neither UUID nor MBR ID is present. This
is a followup fix for Issue #2391
  • Loading branch information
schaefi committed Nov 10, 2023
1 parent 7447203 commit 7f64e7a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 11 additions & 5 deletions kiwi/bootloader/config/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ def _setup_efi_image(
uuid, mbrid, lookup_path
)

def _setup_bios_image(self, mbrid=None, lookup_path=None):
def _setup_bios_image(self, mbrid, lookup_path=None):
"""
Provide bios grub image
"""
Expand Down Expand Up @@ -1020,7 +1020,7 @@ def _create_efi_config_search(self, uuid=None, mbrid=None):
efi_boot_config, mbrid
)

def _create_bios_image(self, mbrid=None, lookup_path=None):
def _create_bios_image(self, mbrid, lookup_path=None):
early_boot_script = os.path.normpath(
os.sep.join([self._get_grub2_boot_path(), 'earlyboot.cfg'])
)
Expand Down Expand Up @@ -1116,9 +1116,15 @@ def _create_early_boot_script_for_mbrid_search(self, filename, mbrid):
early_boot.write(
'set btrfs_relative_path="yes"{0}'.format(os.linesep)
)
early_boot.write(
f'search --file --set=root /boot/{mbrid.get_id()}{os.linesep}'
)
if mbrid:
early_boot.write(
f'search --file --set=root /boot/{mbrid.get_id()}{os.linesep}'
)
else:
# Fallback search for /boot/mbrid
early_boot.write(
f'search --file --set=root /boot/mbrid{os.linesep}'
)
early_boot.write(
'set prefix=($root)/boot/{0}{1}'.format(
self.boot_directory_name, os.linesep
Expand Down
13 changes: 13 additions & 0 deletions test/unit/bootloader/config/grub2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,19 @@ def side_effect(arg):
)
]

with patch('builtins.open', create=True) as mock_open:
# Test fallback search for earlyboot if UUID and MBR ID are missing
mock_open.return_value = MagicMock(spec=io.IOBase)
file_handle = mock_open.return_value.__enter__.return_value
self.bootloader._setup_efi_image(uuid=None, mbrid=None)

assert file_handle.write.call_args_list == [
call('set btrfs_relative_path="yes"\n'),
call('search --file --set=root /boot/mbrid\n'),
call('set prefix=($root)/boot/grub2\n'),
call('source ($root)/boot/grub2/grub.cfg\n'),
]

@patch.object(BootLoaderConfigGrub2, '_supports_bios_modules')
@patch('kiwi.bootloader.config.grub2.Command.run')
@patch('os.path.exists')
Expand Down

0 comments on commit 7f64e7a

Please sign in to comment.