Skip to content

Commit

Permalink
Merge pull request #2347 from OSInside/fix_grub_double_entries
Browse files Browse the repository at this point in the history
Fix double grub entries in hybrid ISO images
  • Loading branch information
Conan-Kudo authored Aug 9, 2023
2 parents 493a11e + 1e4687f commit 8ada037
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
18 changes: 12 additions & 6 deletions kiwi/bootloader/config/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def post_init(self, custom_args):
else:
self.boot_directory_name = 'grub'

if self.custom_args and 'grub_load_command' in self.custom_args:
self.grub_load = self.custom_args['grub_load_command']
else:
self.grub_load = 'source'

if self.custom_args and 'config_options' in self.custom_args:
self.config_options = self.custom_args['config_options']

Expand Down Expand Up @@ -321,7 +326,7 @@ def setup_install_image_config(
'theme': self.theme,
'boot_timeout': self.timeout,
'boot_timeout_style': self.timeout_style or 'menu',
'serial_line_setup': self.serial_line_setup or 'serial',
'serial_line_setup': self.serial_line_setup or '',
'title': self.get_menu_entry_install_title(),
'bootpath': self.get_boot_path('iso'),
'boot_directory_name': self.boot_directory_name,
Expand Down Expand Up @@ -386,7 +391,7 @@ def setup_live_image_config(
'theme': self.theme,
'boot_timeout': self.timeout,
'boot_timeout_style': self.timeout_style or 'menu',
'serial_line_setup': self.serial_line_setup or 'serial',
'serial_line_setup': self.serial_line_setup or '',
'title': self.get_menu_entry_title(plain=True),
'bootpath': self.get_boot_path('iso'),
'boot_directory_name': self.boot_directory_name,
Expand Down Expand Up @@ -1093,8 +1098,9 @@ def _create_early_boot_script_for_uuid_search(self, filename, uuid):
)
)
early_boot.write(
'source ($root){0}/{1}/grub.cfg{2}'.format(
self.get_boot_path(), self.boot_directory_name, os.linesep
'{0} ($root){1}/{2}/grub.cfg{3}'.format(
self.grub_load, self.get_boot_path(),
self.boot_directory_name, os.linesep
)
)

Expand All @@ -1114,8 +1120,8 @@ def _create_early_boot_script_for_mbrid_search(self, filename, mbrid):
)
)
early_boot.write(
'source ($root)/boot/{0}/grub.cfg{1}'.format(
self.boot_directory_name, os.linesep
'{0} ($root)/boot/{1}/grub.cfg{2}'.format(
self.grub_load, self.boot_directory_name, os.linesep
)
)

Expand Down
4 changes: 3 additions & 1 deletion kiwi/builder/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def create_install_iso(self) -> None:
'grub2', self.xml_state, root_dir=self.root_dir,
boot_dir=self.media_dir.name, custom_args={
'grub_directory_name':
Defaults.get_grub_boot_directory_name(self.root_dir)
Defaults.get_grub_boot_directory_name(self.root_dir),
'grub_load_command':
'configfile'
}
)
bootloader_config.setup_install_boot_images(
Expand Down
4 changes: 3 additions & 1 deletion kiwi/builder/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def create(self) -> Result:
'grub2', self.xml_state, root_dir=self.root_dir,
boot_dir=self.media_dir.name, custom_args={
'grub_directory_name':
Defaults.get_grub_boot_directory_name(self.root_dir)
Defaults.get_grub_boot_directory_name(self.root_dir),
'grub_load_command':
'configfile'
}
)
bootloader_config.setup_live_boot_images(
Expand Down
12 changes: 12 additions & 0 deletions test/unit/bootloader/config/grub2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def setup(self, mock_theme, mock_firmware):
self.bootloader = BootLoaderConfigGrub2(
self.state, 'root_dir', None, {
'grub_directory_name': 'grub2',
'grub_load_command': 'source',
'boot_is_crypto': True,
'crypto_disk': True,
'targetbase': 'rootdev',
Expand Down Expand Up @@ -139,6 +140,17 @@ def test_post_init_grub2_boot_directory(self, mock_which):
bootloader = BootLoaderConfigGrub2(xml_state, 'root_dir')
assert bootloader.boot_directory_name == 'grub'

@patch('kiwi.bootloader.config.grub2.Path.which')
def test_post_init_grub2_load_command(self, mock_which):
Defaults.set_platform_name('i686')
xml_state = MagicMock()
xml_state.build_type.get_firmware = Mock(
return_value=None
)
mock_which.return_value = None
bootloader = BootLoaderConfigGrub2(xml_state, 'root_dir')
assert bootloader.grub_load == 'source'

def test_post_init_invalid_platform(self):
Defaults.set_platform_name('unsupported-arch')
with raises(KiwiBootLoaderGrubPlatformError):
Expand Down
3 changes: 2 additions & 1 deletion test/unit/builder/install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ def side_effect(prefix, path):
mock_BootLoaderConfig.assert_called_once_with(
'grub2', self.xml_state, root_dir='root_dir',
boot_dir='temp_media_dir', custom_args={
'grub_directory_name': mock_grub_dir.return_value
'grub_directory_name': mock_grub_dir.return_value,
'grub_load_command': 'configfile'
}
)
bootloader_config.setup_install_boot_images.assert_called_once_with(
Expand Down
3 changes: 2 additions & 1 deletion test/unit/builder/live_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def side_effect():
kiwi.builder.live.BootLoaderConfig.new.assert_called_once_with(
'grub2', self.xml_state, root_dir='root_dir',
boot_dir='temp_media_dir', custom_args={
'grub_directory_name': 'grub2'
'grub_directory_name': 'grub2',
'grub_load_command': 'configfile'
}
)
self.bootloader.setup_live_boot_images.assert_called_once_with(
Expand Down

0 comments on commit 8ada037

Please sign in to comment.