From 35db941bcf30f3fac5b1358aa1124f34f9808950 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 2 Apr 2026 07:53:02 +0200 Subject: serial: T8375: add CLI option to explicitly set kernel console Previously, VyOS hardcoded the kernel boot log console to either ttyS0 or tty0, with no post-install CLI method to change it (manual GRUB edits were required). This commit adds a new CLI node: system console device kernel When set, the selected serial console is used as the kernel boot console. When removed, the kernel boot console falls back to tty0. --- python/vyos/flavor.py | 3 ++- python/vyos/system/grub.py | 2 +- python/vyos/utils/kernel.py | 26 ++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/vyos/flavor.py b/python/vyos/flavor.py index 46c1775f5..a9dccf448 100644 --- a/python/vyos/flavor.py +++ b/python/vyos/flavor.py @@ -21,7 +21,8 @@ convenient interface to reading it. Example of the version data dict:: { - 'console_type': 'ttyS0', + 'console_type': 'ttyS', + 'console_num': '0', 'console_speed': '115200' } """ diff --git a/python/vyos/system/grub.py b/python/vyos/system/grub.py index 1bae0d5fb..9435d18d2 100644 --- a/python/vyos/system/grub.py +++ b/python/vyos/system/grub.py @@ -390,7 +390,7 @@ def set_console_type(console_type: str, root_dir: str = '') -> None: """Write default console type to GRUB configuration Args: - console_type (str): a default console type + console_type (str): GRUB default console type, e.g. tty, ttyS or ttyAMA root_dir (str, optional): an optional path to the root directory. Defaults to empty. """ diff --git a/python/vyos/utils/kernel.py b/python/vyos/utils/kernel.py index 48a7e88ea..726025605 100644 --- a/python/vyos/utils/kernel.py +++ b/python/vyos/utils/kernel.py @@ -14,12 +14,13 @@ # License along with this library. If not, see . import os +from typing import Tuple +from typing import Optional # A list of used Kernel constants # https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/net/wireguard/messages.h?h=linux-6.6.y#n45 WIREGUARD_REKEY_AFTER_TIME = 120 - def load_module(name: str, quiet: bool = True, dry_run: bool = False) -> int: """Load a kernel module via modprobe. @@ -39,7 +40,6 @@ def load_module(name: str, quiet: bool = True, dry_run: bool = False) -> int: cmd.append(name) return run(cmd) - def unload_module(name: str) -> int: """Unload a kernel module via rmmod. @@ -150,3 +150,25 @@ def lsmod(): for m in list_loaded_modules(): mods_data.append(get_module_data(m)) return mods_data + +def get_kernel_serial_console() -> Tuple[Optional[str], Optional[str], Optional[str]]: + """ + Extract the serial console type, number, and speed setting from the kernel + command line which was used during system boot. + """ + import re + from vyos.utils.file import read_file + + cmdline_console_re = re.compile( + r'(?:^|\s)console=(?Ptty(?:S|AMA))(?P\d+),(?P\d+)(?=\s|$)' + ) + + kernel_cmdline = read_file('/proc/cmdline') + if m := cmdline_console_re.search(kernel_cmdline): + return ( + m.group('console_type'), + m.group('console_num'), + m.group('console_speed'), + ) + + return (None, None, None) -- cgit v1.2.3