Skip to content

Commit

Permalink
Merge pull request #2420 from OSInside/fix_grub_terminal_setup
Browse files Browse the repository at this point in the history
Fixed grub terminal setup
  • Loading branch information
Conan-Kudo authored Jan 8, 2024
2 parents 5146ec8 + c6d8235 commit e8fe186
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<oemconfig>
<oem-resize>false</oem-resize>
</oemconfig>
<bootloader name="grub2" timeout="10" console="serial gfxterm"/>
<bootloader name="grub2" timeout="10" console="serial"/>
<size unit="M">10240</size>
</type>
<version>0.3.10</version>
Expand Down
21 changes: 18 additions & 3 deletions doc/source/image_description/elements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,24 @@ attributes are supported:

console="none|console|gfxterm|serial":
Specifies the bootloader console. The attribute is available for the
grub and isolinux bootloader types. Specifying none here will
translate to setting console to an empty string. By default, the
gfxterm (graphical terminal) option is used.
`grub` and `isolinux` bootloader types. The behavior for setting up
the console is different per bootloader:

For `isolinux` the console setting is taken as provided, whereas
only the values `serial` and `console` are taken into account.

For `grub` the console setting is split into the setting for the
output and the input console:

* A single console value is provided. In this case the same value
is used for the output and input console and applied if possible.
Providing the `none` value will skip the console setup for both.

* Two values separated by a space are provided. In this case the
first value configures the output console and the second value
configures the input console. The `none` value can be used to skip
one or the other console setup. More than two space separated
values will be ignored.

grub_template="filename":
Specifies a custom grub bootloader template file which will be used
Expand Down
75 changes: 58 additions & 17 deletions kiwi/bootloader/config/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,28 @@ def post_init(self, custom_args):
if self.custom_args and 'config_options' in self.custom_args:
self.config_options = self.custom_args['config_options']

self.terminal = self.xml_state.get_build_type_bootloader_console()
if self.terminal is None:
self.terminal = 'gfxterm'
else:
self.terminal = self.terminal.replace('none', '').lstrip()
terminal_output = self.xml_state.get_build_type_bootloader_console()[0]
terminal_input = self.xml_state.get_build_type_bootloader_console()[1]
terminal_input_grub = [
'console',
'serial',
'at_keyboard',
'usb_keyboard'
]
terminal_output_grub = [
'console',
'serial',
'gfxterm',
'vga_text',
'mda_text',
'morse',
'spkmodem'
]

self.terminal_output = \
terminal_output if terminal_output in terminal_output_grub else ''
self.terminal_input = \
terminal_input if terminal_input in terminal_input_grub else ''

self.gfxmode = self.get_gfxmode('grub2')
self.theme = self.get_boot_theme()
Expand Down Expand Up @@ -318,6 +335,12 @@ def setup_install_image_config(
"""
log.info('Creating grub2 install config file from template')
self.iso_boot = True
has_graphics = False
has_serial = False
if 'gfxterm' in self.terminal_output:
has_graphics = True
if 'serial' in self.terminal_output or 'serial' in self.terminal_input:
has_serial = True
parameters = {
'search_params': '--file --set=root /boot/' + mbrid.get_id(),
'default_boot': self.get_install_image_boot_default(),
Expand All @@ -338,7 +361,8 @@ def setup_install_image_config(
'bootpath': self.get_boot_path('iso'),
'boot_directory_name': self.boot_directory_name,
'efi_image_name': Defaults.get_efi_image_name(self.arch),
'terminal_setup': self.terminal
'terminal_input': self.terminal_input,
'terminal_output': self.terminal_output
}
custom_template_path = self._get_custom_template()
if custom_template_path:
Expand All @@ -349,14 +373,14 @@ def setup_install_image_config(
log.info('--> Using multiboot install template')
parameters['hypervisor'] = hypervisor
template = self.grub2.get_multiboot_install_template(
self.failsafe_boot, self.terminal,
self.failsafe_boot, has_graphics, has_serial,
self.continue_on_timeout
)
else:
log.info('--> Using standard boot install template')
hybrid_boot = True
template = self.grub2.get_install_template(
self.failsafe_boot, hybrid_boot, self.terminal,
self.failsafe_boot, hybrid_boot, has_graphics, has_serial,
self.continue_on_timeout
)
try:
Expand All @@ -383,6 +407,12 @@ def setup_live_image_config(
"""
log.info('Creating grub2 live ISO config file from template')
self.iso_boot = True
has_graphics = False
has_serial = False
if 'gfxterm' in self.terminal_output:
has_graphics = True
if 'serial' in self.terminal_output or 'serial' in self.terminal_input:
has_serial = True
parameters = {
'search_params': '--file --set=root /boot/' + mbrid.get_id(),
'default_boot': '0',
Expand All @@ -403,7 +433,8 @@ def setup_live_image_config(
'bootpath': self.get_boot_path('iso'),
'boot_directory_name': self.boot_directory_name,
'efi_image_name': Defaults.get_efi_image_name(self.arch),
'terminal_setup': self.terminal
'terminal_input': self.terminal_input,
'terminal_output': self.terminal_output
}
custom_template_path = self._get_custom_template()
if custom_template_path:
Expand All @@ -414,14 +445,15 @@ def setup_live_image_config(
log.info('--> Using multiboot template')
parameters['hypervisor'] = hypervisor
template = self.grub2.get_multiboot_iso_template(
self.failsafe_boot, self.terminal, self.mediacheck_boot
self.failsafe_boot, has_graphics, has_serial,
self.mediacheck_boot
)
else:
log.info('--> Using standard boot template')
hybrid_boot = True
template = self.grub2.get_iso_template(
self.failsafe_boot, hybrid_boot,
self.terminal, self.mediacheck_boot
has_graphics, has_serial, self.mediacheck_boot
)
try:
self.config = template.substitute(parameters)
Expand Down Expand Up @@ -687,7 +719,8 @@ def _setup_default_grub(self):
* GRUB_CMDLINE_LINUX
* GRUB_CMDLINE_LINUX_DEFAULT
* GRUB_GFXMODE
* GRUB_TERMINAL
* GRUB_TERMINAL_INPUT
* GRUB_TERMINAL_OUTPUT
* GRUB_DISTRIBUTOR
* GRUB_DISABLE_LINUX_UUID
* GRUB_DISABLE_LINUX_PARTUUID
Expand All @@ -700,9 +733,16 @@ def _setup_default_grub(self):
# elements to set in any case
grub_default_entries = {
'GRUB_TIMEOUT': self.timeout,
'GRUB_GFXMODE': self.gfxmode,
'GRUB_TERMINAL': '"{0}"'.format(self.terminal)
'GRUB_GFXMODE': self.gfxmode
}
if self.terminal_input:
grub_default_entries['GRUB_TERMINAL_INPUT'] = '"{0}"'.format(
self.terminal_input
)
if self.terminal_output:
grub_default_entries['GRUB_TERMINAL_OUTPUT'] = '"{0}"'.format(
self.terminal_output
)
grub_final_cmdline = re.sub(
r'(^root=[^\s]+)|( root=[^\s]+)', '', self.cmdline
).strip()
Expand Down Expand Up @@ -730,8 +770,8 @@ def _setup_default_grub(self):
grub_default_entries['GRUB_CMDLINE_LINUX_DEFAULT'] = '"{0}"'.format(
grub_final_cmdline
)
if self.terminal and 'serial' in self.terminal and \
self.serial_line_setup:
if self.serial_line_setup and \
'serial' in self.terminal_input or 'serial' in self.terminal_output:
grub_default_entries['GRUB_SERIAL_COMMAND'] = '"{0}"'.format(
self.serial_line_setup
)
Expand Down Expand Up @@ -1301,7 +1341,8 @@ def _check_boot_theme_exists(self):
if not os.path.exists(theme_dir):
log.warning('Theme %s not found', theme_dir)
log.warning('Set bootloader terminal to console mode')
self.terminal = 'console'
self.terminal_input = 'console'
self.terminal_output = 'console'

def _setup_EFI_path(self, lookup_path):
"""
Expand Down
2 changes: 1 addition & 1 deletion kiwi/bootloader/config/isolinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def post_init(self, custom_args):
self.xml_state.build_type.get_hybridpersistent_filesystem()
)

self.terminal = self.xml_state.get_build_type_bootloader_console()
self.terminal = self.xml_state.get_build_type_bootloader_console()[0]
self.gfxmode = self.get_gfxmode('isolinux')
# isolinux counts the timeout in units of 1/10 sec
self.timeout = self.get_boot_timeout_seconds() * 10
Expand Down
62 changes: 35 additions & 27 deletions kiwi/bootloader/template/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self):
export linux initrd
''').strip() + os.linesep

self.header_gfxterm = dedent('''
self.header_gfxmode = dedent('''
if [ "$${grub_platform}" = "efi" ]; then
echo "Please press 't' to show the boot menu on this console"
fi
Expand All @@ -73,8 +73,8 @@ def __init__(self):
''').strip() + os.linesep

self.header_terminal_setup = dedent('''
terminal_input ${terminal_setup}
terminal_output ${terminal_setup}
terminal_input ${terminal_input}
terminal_output ${terminal_output}
''').strip() + os.linesep

self.fonts = dedent('''
Expand Down Expand Up @@ -310,14 +310,16 @@ def __init__(self):
''').strip() + os.linesep

def get_iso_template(
self, failsafe=True, hybrid=True, terminal='gfxterm', checkiso=False
self, failsafe=True, hybrid=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 string terminal: output terminal name
:param bool has_graphics: supports graphics terminal
:param bool has_serial: supports serial terminal
:return: instance of :class:`Template`
Expand All @@ -328,10 +330,10 @@ def get_iso_template(
template_data += self.timeout_style
if hybrid:
template_data += self.header_hybrid
if 'gfxterm' in terminal:
template_data += self.header_gfxterm
if has_graphics:
template_data += self.header_gfxmode
template_data += self.header_theme_iso
if 'serial' in terminal:
if has_serial:
template_data += self.header_serial
template_data += self.header_terminal_setup
if hybrid:
Expand All @@ -348,19 +350,21 @@ def get_iso_template(
template_data += self.menu_mediacheck_entry
template_data += self.menu_iso_harddisk_entry
template_data += self.menu_entry_boot_snapshots
if 'gfxterm' in terminal:
if has_graphics:
template_data += self.menu_entry_console_switch
return Template(template_data)

def get_multiboot_iso_template(
self, failsafe=True, terminal='gfxterm', checkiso=False
self, failsafe=True,
has_graphics=True, has_serial=False, checkiso=False
):
"""
Bootloader configuration template for live ISO media with
hypervisor, e.g Xen dom0
:param bool failsafe: with failsafe true|false
:param string terminal: output terminal name
:param bool has_graphics: supports graphics terminal
:param bool has_serial: supports serial terminal
:return: instance of :class:`Template`
Expand All @@ -369,10 +373,10 @@ def get_multiboot_iso_template(
template_data = self.header
template_data += self.timeout
template_data += self.timeout_style
if 'gfxterm' in terminal:
template_data += self.header_gfxterm
if has_graphics:
template_data += self.header_gfxmode
template_data += self.header_theme_iso
if 'serial' in terminal:
if has_serial:
template_data += self.header_serial
template_data += self.header_terminal_setup
template_data += self.menu_entry_multiboot
Expand All @@ -382,19 +386,21 @@ def get_multiboot_iso_template(
template_data += self.menu_mediacheck_entry_multiboot
template_data += self.menu_iso_harddisk_entry
template_data += self.menu_entry_boot_snapshots
if 'gfxterm' in terminal:
if has_graphics:
template_data += self.menu_entry_console_switch
return Template(template_data)

def get_install_template(
self, failsafe=True, hybrid=True, terminal='gfxterm', with_timeout=True
self, failsafe=True, hybrid=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 string terminal: output terminal name
:param bool has_graphics: supports graphics terminal
:param bool has_serial: supports serial terminal
:return: instance of :class:`Template`
Expand All @@ -406,10 +412,10 @@ def get_install_template(
template_data += self.timeout_style
if hybrid:
template_data += self.header_hybrid
if 'gfxterm' in terminal:
template_data += self.header_gfxterm
if has_graphics:
template_data += self.header_gfxmode
template_data += self.header_theme_iso
if 'serial' in terminal:
if has_serial:
template_data += self.header_serial
template_data += self.header_terminal_setup
template_data += self.menu_iso_harddisk_entry
Expand All @@ -422,19 +428,21 @@ def get_install_template(
if failsafe:
template_data += self.menu_install_entry_failsafe
template_data += self.menu_entry_boot_snapshots
if 'gfxterm' in terminal:
if has_graphics:
template_data += self.menu_entry_console_switch
return Template(template_data)

def get_multiboot_install_template(
self, failsafe=True, terminal='gfxterm', with_timeout=True
self, failsafe=True,
has_graphics=True, has_serial=False, with_timeout=True
):
"""
Bootloader configuration template for install media with
hypervisor, e.g Xen dom0
:param bool failsafe: with failsafe true|false
:param string terminal: output terminal name
:param bool has_graphics: supports graphics terminal
:param bool has_serial: supports serial terminal
:return: instance of :class:`Template`
Expand All @@ -444,17 +452,17 @@ def get_multiboot_install_template(
if with_timeout:
template_data += self.timeout
template_data += self.timeout_style
if 'gfxterm' in terminal:
template_data += self.header_gfxterm
if has_graphics:
template_data += self.header_gfxmode
template_data += self.header_theme_iso
if 'serial' in terminal:
if has_serial:
template_data += self.header_serial
template_data += self.header_terminal_setup
template_data += self.menu_iso_harddisk_entry
template_data += self.menu_install_entry_multiboot
if failsafe:
template_data += self.menu_install_entry_failsafe_multiboot
template_data += self.menu_entry_boot_snapshots
if 'gfxterm' in terminal:
if has_graphics:
template_data += self.menu_entry_console_switch
return Template(template_data)
Loading

0 comments on commit e8fe186

Please sign in to comment.