diff --git a/kiwi/bootloader/config/grub2.py b/kiwi/bootloader/config/grub2.py index 92c32c1e75d..f490ac9d936 100644 --- a/kiwi/bootloader/config/grub2.py +++ b/kiwi/bootloader/config/grub2.py @@ -312,7 +312,6 @@ def setup_disk_image_config( # One fine day the following fix methods can hopefully # be deleted... if self.xml_state.build_type.get_overlayroot_write_partition() is not False: - self._fix_grub_to_support_dynamic_efi_and_bios_boot(config_file) self._fix_grub_root_device_reference(config_file, boot_options) self._fix_grub_loader_entries_boot_cmdline() self._fix_grub_loader_entries_linux_and_initrd_paths() @@ -713,8 +712,6 @@ def _setup_default_grub(self): * SUSE_REMOVE_LINUX_ROOT_PARAM * GRUB_BACKGROUND * GRUB_THEME - * GRUB_USE_LINUXEFI - * GRUB_USE_INITRDEFI * GRUB_SERIAL_COMMAND * GRUB_CMDLINE_LINUX * GRUB_CMDLINE_LINUX_DEFAULT @@ -787,18 +784,6 @@ def _setup_default_grub(self): ) if os.path.exists(os.sep.join([self.root_dir, theme_background])): grub_default_entries['GRUB_BACKGROUND'] = theme_background - if self.firmware.efi_mode(): - # linuxefi/initrdefi only exist on x86, others always use efi - if self.arch == 'ix86' or self.arch == 'x86_64': - use_linuxefi_implemented = Command.run( - [ - 'grep', '-q', 'GRUB_USE_LINUXEFI', - self._get_grub2_mkconfig_tool() - ], raise_on_error=False - ) - if use_linuxefi_implemented.returncode == 0: - grub_default_entries['GRUB_USE_LINUXEFI'] = 'true' - grub_default_entries['GRUB_USE_INITRDEFI'] = 'true' if self.xml_state.build_type.get_btrfs_root_is_snapshot(): grub_default_entries['SUSE_BTRFS_SNAPSHOT_BOOTING'] = 'true' if self.custom_args.get('crypto_disk'): @@ -1390,37 +1375,6 @@ def _get_shim_install(self): filename='shim-install', root_dir=self.boot_dir ) - def _fix_grub_to_support_dynamic_efi_and_bios_boot(self, config_file): - if self.firmware.efi_mode() and self.arch in ['x86_64', 'ix86']: - # On systems that are configured to use EFI with grub2 - # there is no support for dynamic EFI environment checking. - # In this condition we change the grub config to add this - # support as follows: - # - # * Apply on grub with EFI - # 1. Modify grub.cfg to set linux/initrd as variables - # 2. Prepend hybrid setup to select linux vs. linuxefi on demand - # - # Please note this is a one time modification done by kiwi - # Any subsequent call of the grub config tool will overwrite - # the setup and disables dynamic EFI environment checking - # at boot time - with open(config_file) as grub_config_file: - grub_config = grub_config_file.read() - grub_config = re.sub( - r'([ \t]+)linux(efi|16)*([ \t]+)', r'\1$linux\3', - grub_config - ) - grub_config = re.sub( - r'([ \t]+)initrd(efi|16)*([ \t]+)', r'\1$initrd\3', - grub_config - ) - with open(config_file, 'w') as grub_config_file: - grub_config_file.write( - Template(self.grub2.header_hybrid).substitute() - ) - grub_config_file.write(grub_config) - def _fix_grub_root_device_reference(self, config_file, boot_options): if self.root_reference: # grub2-mkconfig has no idea how the correct root= setup is diff --git a/kiwi/bootloader/template/grub2.py b/kiwi/bootloader/template/grub2.py index 52b1c407b71..2e9274c3c43 100644 --- a/kiwi/bootloader/template/grub2.py +++ b/kiwi/bootloader/template/grub2.py @@ -49,18 +49,6 @@ def __init__(self): set timeout_style=${boot_timeout_style} ''').strip() + os.linesep - self.header_hybrid = dedent(''' - set linux=linux - set initrd=initrd - if [ "$${grub_cpu}" = "x86_64" -o "$${grub_cpu}" = "i386" ]; then - if [ "$${grub_platform}" = "efi" ]; then - set linux=linuxefi - set initrd=initrdefi - fi - fi - export linux initrd - ''').strip() + os.linesep - self.header_gfxmode = dedent(''' if [ "$${grub_platform}" = "efi" ]; then echo "Please press 't' to show the boot menu on this console" @@ -143,16 +131,6 @@ def __init__(self): fi ''').strip() + os.linesep - self.menu_entry_hybrid = dedent(''' - menuentry "${title}" --class os --unrestricted { - set gfxpayload=keep - echo Loading kernel... - $$linux ($$root)${bootpath}/${kernel_file} $${extra_cmdline} $${isoboot} ${boot_options} - echo Loading initrd... - $$initrd ($$root)${bootpath}/${initrd_file} - } - ''').strip() + os.linesep - self.menu_entry_multiboot = dedent(''' menuentry "${title}" --class os --unrestricted { set gfxpayload=keep @@ -175,16 +153,6 @@ def __init__(self): } ''').strip() + os.linesep - self.menu_entry_failsafe_hybrid = dedent(''' - menuentry "Failsafe -- ${title}" --class os --unrestricted { - set gfxpayload=keep - echo Loading kernel... - $$linux ($$root)${bootpath}/${kernel_file} $${extra_cmdline} $${isoboot} ${failsafe_boot_options} - echo Loading initrd... - $$initrd ($$root)${bootpath}/${initrd_file} - } - ''').strip() + os.linesep - self.menu_entry_failsafe_multiboot = dedent(''' menuentry "Failsafe -- ${title}" --class os --unrestricted { set gfxpayload=keep @@ -207,16 +175,6 @@ def __init__(self): } ''').strip() + os.linesep - self.menu_install_entry_hybrid = dedent(''' - menuentry "Install ${title}" --class os --unrestricted { - set gfxpayload=keep - echo Loading kernel... - $$linux ($$root)${bootpath}/${kernel_file} cdinst=1 ${boot_options} - echo Loading initrd... - $$initrd ($$root)${bootpath}/${initrd_file} - } - ''').strip() + os.linesep - self.menu_install_entry_multiboot = dedent(''' menuentry "Install -- ${title}" --class os --unrestricted { set gfxpayload=keep @@ -239,16 +197,6 @@ def __init__(self): } ''').strip() + os.linesep - self.menu_mediacheck_entry_hybrid = dedent(''' - menuentry "Mediacheck" --class os --unrestricted { - set gfxpayload=keep - echo Loading kernel... - $$linux ($$root)${bootpath}/${kernel_file} mediacheck=1 plymouth.enable=0 $${isoboot} ${boot_options} - echo Loading initrd... - $$initrd ($$root)${bootpath}/${initrd_file} - } - ''').strip() + os.linesep - self.menu_mediacheck_entry_multiboot = dedent(''' menuentry "Mediacheck" --class os --unrestricted { set gfxpayload=keep @@ -271,16 +219,6 @@ def __init__(self): } ''').strip() + os.linesep - self.menu_install_entry_failsafe_hybrid = dedent(''' - menuentry "Failsafe -- Install ${title}" --class os --unrestricted { - set gfxpayload=keep - echo Loading kernel... - $$linux ($$root)${bootpath}/${kernel_file} cdinst=1 ${failsafe_boot_options} - echo Loading initrd... - $$initrd ($$root)${bootpath}/${initrd_file} - } - ''').strip() + os.linesep - self.menu_install_entry_failsafe_multiboot = dedent(''' menuentry "Failsafe -- Install ${title}" --class os --unrestricted { set gfxpayload=keep @@ -310,14 +248,13 @@ def __init__(self): ''').strip() + os.linesep def get_iso_template( - self, failsafe=True, hybrid=True, + self, failsafe=True, has_graphics=True, has_serial=False, checkiso=False ): """ Bootloader configuration template for live ISO media :param bool failsafe: with failsafe true|false - :param bool hybrid: with hybrid true|false :param bool has_graphics: supports graphics terminal :param bool has_serial: supports serial terminal @@ -328,26 +265,17 @@ def get_iso_template( template_data = self.header template_data += self.timeout template_data += self.timeout_style - if hybrid: - template_data += self.header_hybrid if has_graphics: template_data += self.header_gfxmode template_data += self.header_theme_iso if has_serial: template_data += self.header_serial template_data += self.header_terminal_setup - if hybrid: - template_data += self.menu_entry_hybrid - if failsafe: - template_data += self.menu_entry_failsafe_hybrid - if checkiso: - template_data += self.menu_mediacheck_entry_hybrid - else: - template_data += self.menu_entry - if failsafe: - template_data += self.menu_entry_failsafe - if checkiso: - template_data += self.menu_mediacheck_entry + template_data += self.menu_entry + if failsafe: + template_data += self.menu_entry_failsafe + if checkiso: + template_data += self.menu_mediacheck_entry template_data += self.menu_iso_harddisk_entry template_data += self.menu_entry_boot_snapshots if has_graphics: @@ -391,14 +319,13 @@ def get_multiboot_iso_template( return Template(template_data) def get_install_template( - self, failsafe=True, hybrid=True, + self, failsafe=True, has_graphics=True, has_serial=False, with_timeout=True ): """ Bootloader configuration template for install media :param bool failsafe: with failsafe true|false - :param bool hybrid: with hybrid true|false :param bool has_graphics: supports graphics terminal :param bool has_serial: supports serial terminal @@ -410,8 +337,6 @@ def get_install_template( if with_timeout: template_data += self.timeout template_data += self.timeout_style - if hybrid: - template_data += self.header_hybrid if has_graphics: template_data += self.header_gfxmode template_data += self.header_theme_iso @@ -419,14 +344,9 @@ def get_install_template( template_data += self.header_serial template_data += self.header_terminal_setup template_data += self.menu_iso_harddisk_entry - if hybrid: - template_data += self.menu_install_entry_hybrid - if failsafe: - template_data += self.menu_install_entry_failsafe_hybrid - else: - template_data += self.menu_install_entry - if failsafe: - template_data += self.menu_install_entry_failsafe + template_data += self.menu_install_entry + if failsafe: + template_data += self.menu_install_entry_failsafe template_data += self.menu_entry_boot_snapshots if has_graphics: template_data += self.menu_entry_console_switch diff --git a/test/unit/bootloader/config/grub2_test.py b/test/unit/bootloader/config/grub2_test.py index c047bd17514..b9a106d8a41 100644 --- a/test/unit/bootloader/config/grub2_test.py +++ b/test/unit/bootloader/config/grub2_test.py @@ -16,7 +16,6 @@ from kiwi.xml_state import XMLState from kiwi.xml_description import XMLDescription from kiwi.bootloader.config.grub2 import BootLoaderConfigGrub2 -from kiwi.bootloader.template.grub2 import BootLoaderTemplateGrub2 from kiwi.utils.sysconfig import SysConfig from kiwi.exceptions import ( @@ -87,9 +86,7 @@ def setup(self, mock_theme, mock_firmware): return_value='0xffffffff' ) - grub_template = BootLoaderTemplateGrub2() self.grub2 = Mock() - self.grub2.header_hybrid = grub_template.header_hybrid kiwi.bootloader.config.grub2.BootLoaderTemplateGrub2 = Mock( return_value=self.grub2 ) @@ -253,7 +250,6 @@ def test_post_init_dom0(self, mock_exists): mock_exists.return_value = True self.bootloader.post_init(None) assert self.bootloader.multiboot is True - assert self.bootloader.hybrid_boot is False assert self.bootloader.xen_guest is False @patch('os.path.exists') @@ -268,7 +264,6 @@ def test_post_init_domU(self, mock_exists): mock_exists.return_value = True self.bootloader.post_init(None) assert self.bootloader.multiboot is False - assert self.bootloader.hybrid_boot is False assert self.bootloader.xen_guest is True @patch.object(BootLoaderConfigGrub2, '_setup_default_grub') @@ -602,8 +597,6 @@ def test_setup_default_grub( 'GRUB_THEME': '/boot/grub2/themes/openSUSE/theme.txt', 'GRUB_TIMEOUT': 10, 'GRUB_TIMEOUT_STYLE': 'countdown', - 'GRUB_USE_INITRDEFI': 'true', - 'GRUB_USE_LINUXEFI': 'true', 'SUSE_BTRFS_SNAPSHOT_BOOTING': 'true', 'GRUB_DEFAULT': 'saved' } @@ -998,32 +991,11 @@ def open_file(filename, mode=None): mock_copy_grub_config_to_efi_path.assert_called_once_with( 'efi_mount_point', 'earlyboot.cfg' ) - assert file_handle_grub.write.call_args_list == [ - # first write of grub.cfg, adapting to linux/initrd as variables - call( - 'set linux=linux\n' - 'set initrd=initrd\n' - 'if [ "${grub_cpu}" = "x86_64" -o ' - '"${grub_cpu}" = "i386" ]; then\n' - ' if [ "${grub_platform}" = "efi" ]; then\n' - ' set linux=linuxefi\n' - ' set initrd=initrdefi\n' - ' fi\n' - 'fi\n' - 'export linux initrd\n' - ), - call( - 'root=rootdev nomodeset console=ttyS0 console=tty0' - '\n' - 'root=PARTUUID=xx' - ), - # second write of grub.cfg, setting overlay root - call( - 'root=overlay:UUID=ID nomodeset console=ttyS0 console=tty0' - '\n' - 'root=overlay:UUID=ID' - ) - ] + file_handle_grub.write.assert_called_once_with == ( + 'root=overlay:UUID=ID nomodeset console=ttyS0 console=tty0' + '\n' + 'root=overlay:UUID=ID' + ) file_handle_grubenv.write.assert_called_once_with( 'root=overlay:UUID=ID' ) @@ -1048,63 +1020,6 @@ def open_file(filename, mode=None): assert 'initrd /initrd' in \ file_handle_menu.write.call_args_list[1][0][0].split(os.linesep) - @patch.object(BootLoaderConfigGrub2, '_mount_system') - @patch.object(BootLoaderConfigGrub2, '_copy_grub_config_to_efi_path') - @patch('kiwi.bootloader.config.grub2.Command.run') - @patch('kiwi.bootloader.config.grub2.Path.which') - def test_setup_disk_image_config_validate_linuxefi( - self, mock_Path_which, mock_Command_run, - mock_copy_grub_config_to_efi_path, mock_mount_system - ): - mock_Path_which.return_value = '/path/to/grub2-mkconfig' - self.firmware.efi_mode = Mock( - return_value='uefi' - ) - self.bootloader.root_mount = Mock() - self.bootloader.root_mount.mountpoint = 'root_mount_point' - self.bootloader.efi_mount = Mock() - self.bootloader.efi_mount.mountpoint = 'efi_mount_point' - with patch('builtins.open', create=True) as mock_open: - mock_open.return_value = MagicMock(spec=io.IOBase) - file_handle = mock_open.return_value.__enter__.return_value - file_handle.read.return_value = os.linesep.join( - [ - '\tlinuxefi ${rel_dirname}/${basename} ...', - '\tlinux ${rel_dirname}/${basename} ...', - '\tlinux16 ${rel_dirname}/${basename} ...', - '\tinitrdefi ${rel_dirname}/${initrd}', - '\tinitrd ${rel_dirname}/${initrd}', - '\tinitrd16 ${rel_dirname}/${initrd}' - ] - ) - self.bootloader.setup_disk_image_config( - boot_options={ - 'root_device': 'rootdev', 'boot_device': 'bootdev' - } - ) - assert file_handle.write.call_args_list == [ - call( - 'set linux=linux\n' - 'set initrd=initrd\n' - 'if [ "${grub_cpu}" = "x86_64" -o ' - '"${grub_cpu}" = "i386" ]; then\n' - ' if [ "${grub_platform}" = "efi" ]; then\n' - ' set linux=linuxefi\n' - ' set initrd=initrdefi\n' - ' fi\n' - 'fi\n' - 'export linux initrd\n' - ), - call( - '\t$linux ${rel_dirname}/${basename} ...\n' - '\t$linux ${rel_dirname}/${basename} ...\n' - '\t$linux ${rel_dirname}/${basename} ...\n' - '\t$initrd ${rel_dirname}/${initrd}\n' - '\t$initrd ${rel_dirname}/${initrd}\n' - '\t$initrd ${rel_dirname}/${initrd}' - ) - ] - @patch.object(BootLoaderConfigGrub2, '_copy_grub_config_to_efi_path') def test_setup_install_image_config_standard( self, mock_copy_grub_config_to_efi_path diff --git a/test/unit/bootloader/template/grub2_test.py b/test/unit/bootloader/template/grub2_test.py index 6007b8e98fa..7fb819ff39f 100644 --- a/test/unit/bootloader/template/grub2_test.py +++ b/test/unit/bootloader/template/grub2_test.py @@ -95,115 +95,9 @@ def test_get_install_template(self): terminal_output='console' ) - def test_get_install_template_console_no_hybrid(self): - assert self.grub2.get_install_template( - has_graphics=False, - hybrid=False - ).substitute( - search_params='--file --set=root /boot/0xd305fb7d', - default_boot='0', - kernel_file='boot/linux.vmx', - initrd_file='boot/initrd.vmx', - boot_options='cdinst=1 splash', - failsafe_boot_options='cdinst=1 splash', - boot_timeout='10', - boot_timeout_style='menu', - serial_line_setup='', - title='LimeJeOS-SLE12-Community [ VMX ]', - bootpath='/boot', - efi_image_name='bootx64.efi', - terminal_input='console', - terminal_output='console' - ) - - def test_get_install_template_serial_no_hybrid(self): - assert self.grub2.get_install_template( - has_graphics=False, - hybrid=False - ).substitute( - search_params='--file --set=root /boot/0xd305fb7d', - default_boot='0', - kernel_file='boot/linux.vmx', - initrd_file='boot/initrd.vmx', - boot_options='cdinst=1 splash', - failsafe_boot_options='cdinst=1 splash', - boot_timeout='10', - boot_timeout_style='menu', - serial_line_setup='', - title='LimeJeOS-SLE12-Community [ VMX ]', - bootpath='/boot', - efi_image_name='bootx64.efi', - terminal_input='serial', - terminal_output='serial' - ) - def test_get_iso_template(self): - assert self.grub2.get_iso_template().substitute( - search_params='--file --set=root /boot/0xd305fb7d', - default_boot='0', - kernel_file='boot/linux.vmx', - initrd_file='boot/initrd.vmx', - boot_options='splash', - failsafe_boot_options='splash', - gfxmode='800x600', - theme='SLE', - boot_timeout='10', - boot_timeout_style='menu', - serial_line_setup='', - title='LimeJeOS-SLE12-Community', - bootpath='/boot', - boot_directory_name='grub2', - efi_image_name='bootx64.efi', - terminal_input='console', - terminal_output='console' - ) - - def test_get_iso_template_console_no_hybrid(self): - assert self.grub2.get_iso_template( - has_graphics=False, - hybrid=False - ).substitute( - search_params='--file --set=root /boot/0xd305fb7d', - default_boot='0', - kernel_file='boot/linux.vmx', - initrd_file='boot/initrd.vmx', - boot_options='splash', - failsafe_boot_options='splash', - boot_timeout='10', - boot_timeout_style='menu', - serial_line_setup='', - title='LimeJeOS-SLE12-Community', - bootpath='/boot', - efi_image_name='bootx64.efi', - terminal_input='console', - terminal_output='console' - ) - - def test_get_iso_template_serial_no_hybrid(self): - assert self.grub2.get_iso_template( - has_graphics=False, - has_serial=True, - hybrid=False - ).substitute( - search_params='--file --set=root /boot/0xd305fb7d', - default_boot='0', - kernel_file='boot/linux.vmx', - initrd_file='boot/initrd.vmx', - boot_options='splash', - failsafe_boot_options='splash', - boot_timeout='10', - boot_timeout_style='menu', - serial_line_setup='', - title='LimeJeOS-SLE12-Community', - bootpath='/boot', - efi_image_name='bootx64.efi', - terminal_input='serial', - terminal_output='serial' - ) - - def test_get_iso_template_checkiso_no_hybrid(self): assert self.grub2.get_iso_template( - hybrid=False, checkiso=True + has_serial=True ).substitute( search_params='--file --set=root /boot/0xd305fb7d', default_boot='0',