Skip to content

Commit

Permalink
Merge pull request #2424 from OSInside/drop-grub2-linuxefi
Browse files Browse the repository at this point in the history
Drop hybrid boot snippets from the GRUB 2 configuration template
  • Loading branch information
Conan-Kudo authored Jan 16, 2024
2 parents 31e6f2d + a638884 commit 5ee55ae
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 333 deletions.
46 changes: 0 additions & 46 deletions kiwi/bootloader/config/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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
Expand Down
100 changes: 10 additions & 90 deletions kiwi/bootloader/template/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -410,23 +337,16 @@ 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
if has_serial:
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
Expand Down
Loading

0 comments on commit 5ee55ae

Please sign in to comment.