From 44d929a1b973d3f4131d25d7f9cd7b69c3cf3514 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Tue, 3 Nov 2026 16:36:31 +0100 Subject: serial: T9567: honor booted serial console during 31 -> 32 migration An installation that still carries a legacy 1.3.x image keeps GRUB in compat mode. The GRUB structure update then rewrites the GRUB vars on every boot, before the config migration runs. The migration relied on these vars to detect a serial boot console and silently skipped setting "system console device ttyS0 kernel" after an upgrade from 1.4. The console code then fell back to tty0, so the next boot lost all serial output. On compat GRUB installs, the migration now uses the console the kernel booted with (the last console= argument). Installs using the current GRUB layout keep reading the GRUB vars, so a one-off console choice from the GRUB boot options menu is not persisted into the config. --- src/migration-scripts/system/31-to-32 | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/migration-scripts') diff --git a/src/migration-scripts/system/31-to-32 b/src/migration-scripts/system/31-to-32 index 89b604a7f..4f537cd41 100644 --- a/src/migration-scripts/system/31-to-32 +++ b/src/migration-scripts/system/31-to-32 @@ -17,9 +17,12 @@ from vyos.configtree import ConfigTree from vyos.flavor import get_image_serial_console +from vyos.system import compat from vyos.system import disk +from vyos.system import image from vyos.system.grub import CFG_VYOS_VARS from vyos.system.grub import vars_read +from vyos.utils.kernel import get_kernel_primary_console base = ['system', 'console'] @@ -35,6 +38,25 @@ def migrate(config: ConfigTree) -> None: console_type, console_num = 'ttyS', '0' serial_console = f'{console_type}{console_num}' + if not config.exists(base + ['device', serial_console]): + return + + # A container shares the kernel command line of its host, which says + # nothing about the console of VyOS itself + if image.is_running_as_container(): + return + + # An installed legacy image keeps GRUB in compat mode. The GRUB structure + # update then rewrites the GRUB vars on every boot before migration runs, + # so they may not reflect the boot console - use the console the kernel + # booted with instead + if compat.mode(): + kernel_type, kernel_num, _ = get_kernel_primary_console() + if kernel_type is not None: + if f'{kernel_type}{kernel_num}' == serial_console: + config.set(base + ['device', serial_console, 'kernel']) + return + root_dir = disk.find_persistence() vars_file: str = f'{root_dir}/{CFG_VYOS_VARS}' vars_current: dict[str, str] = vars_read(vars_file) @@ -46,5 +68,4 @@ def migrate(config: ConfigTree) -> None: # Check if VyOS installation uses serial boot console if vars_current['console_type'] == console_type: - if config.exists(base + ['device', serial_console]): - config.set(base + ['device', serial_console, 'kernel']) + config.set(base + ['device', serial_console, 'kernel']) -- cgit v1.2.3