summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-04-02 07:53:02 +0200
committerChristian Breunig <christian@breunig.cc>2026-04-09 20:54:06 +0200
commit35db941bcf30f3fac5b1358aa1124f34f9808950 (patch)
tree09db740466acd3d42037698ac4bf6d33100a50e4 /python
parent51922535b79529d603c3b7d52cde9da54c069d42 (diff)
downloadvyos-1x-35db941bcf30f3fac5b1358aa1124f34f9808950.tar.gz
vyos-1x-35db941bcf30f3fac5b1358aa1124f34f9808950.zip
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 <name> kernel When set, the selected serial console is used as the kernel boot console. When removed, the kernel boot console falls back to tty0.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/flavor.py3
-rw-r--r--python/vyos/system/grub.py2
-rw-r--r--python/vyos/utils/kernel.py26
3 files changed, 27 insertions, 4 deletions
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 <http://www.gnu.org/licenses/>.
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=(?P<console_type>tty(?:S|AMA))(?P<console_num>\d+),(?P<console_speed>\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)