summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-11-03 16:36:31 +0100
committerChristian Breunig <christian@breunig.cc>2026-11-03 17:12:15 +0100
commit44d929a1b973d3f4131d25d7f9cd7b69c3cf3514 (patch)
treeb2036529618aa82066ed9256e480feeaee15e16d /python
parent6fe3f483aafe9ac27cd45791dde574f1b4a8b0b7 (diff)
downloadvyos-1x-44d929a1b973d3f4131d25d7f9cd7b69c3cf3514.tar.gz
vyos-1x-44d929a1b973d3f4131d25d7f9cd7b69c3cf3514.zip
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.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/kernel.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/python/vyos/utils/kernel.py b/python/vyos/utils/kernel.py
index 69574cefc..283dd8a9c 100644
--- a/python/vyos/utils/kernel.py
+++ b/python/vyos/utils/kernel.py
@@ -182,6 +182,40 @@ def get_kernel_serial_console() -> Tuple[Optional[str], Optional[str], Optional[
return (None, None, None)
+def get_kernel_primary_console(cmdline: str | None = None) -> Tuple[Optional[str], Optional[str], Optional[str]]:
+ """
+ Extract type, number and speed of the console the kernel uses as
+ /dev/console. With multiple console= arguments this is the last one, e.g.
+ "console=tty0 console=ttyS0,115200" boots on ttyS0 while
+ "console=ttyS0,115200 console=tty0" boots on tty0.
+
+ Args:
+ cmdline: kernel command line to parse, defaults to /proc/cmdline
+
+ Returns:
+ tuple: (console_type, console_num, console_speed), speed is None if
+ not specified. (None, None, None) if no console= is present.
+ """
+ import re
+
+ if cmdline is None:
+ cmdline = read_file(CMDLINE_PATH)
+
+ # speed may carry parity/bits/flow suffixes, e.g. 115200n8
+ console_re = re.compile(
+ r'console=(?P<console_type>[a-zA-Z]+)(?P<console_num>\d+)(?:,(?P<console_speed>\d+)\S*)?'
+ )
+ for part in reversed(cmdline.split()):
+ if m := console_re.fullmatch(part):
+ return (
+ m.group('console_type'),
+ m.group('console_num'),
+ m.group('console_speed'),
+ )
+
+ return (None, None, None)
+
+
def get_kernel_boot_arg(argument=None) -> str | None:
"""Read and parse kernel boot arguments from the kernel command line.