diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-04-02 07:53:02 +0200 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2026-04-09 20:54:06 +0200 |
| commit | 35db941bcf30f3fac5b1358aa1124f34f9808950 (patch) | |
| tree | 09db740466acd3d42037698ac4bf6d33100a50e4 /src/activation-scripts | |
| parent | 51922535b79529d603c3b7d52cde9da54c069d42 (diff) | |
| download | vyos-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 'src/activation-scripts')
| -rwxr-xr-x | src/activation-scripts/05-serial_console.py | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/src/activation-scripts/05-serial_console.py b/src/activation-scripts/05-serial_console.py index 93e381d17..ccda2ac4e 100755 --- a/src/activation-scripts/05-serial_console.py +++ b/src/activation-scripts/05-serial_console.py @@ -13,45 +13,31 @@ # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see <http://www.gnu.org/licenses/>. -import re - -from typing import Optional -from typing import Tuple - from vyos.configtree import ConfigTree -from vyos.utils.file import read_file from vyos.system.image import is_live_boot +from vyos.utils.kernel import get_kernel_serial_console +from vyos.utils.serial import is_tty base = ['system', 'console', 'device'] -def get_kernel_serial_console() -> Tuple[Optional[str], Optional[str]]: - """ - Extract the serial console device and speed setting from the kernel - command line. - """ - device = speed = None - CMDLINE_CONSOLE_RE = re.compile( - r'(?:^|\s)console=(?P<device>tty(?:S|AMA)\d+),(?P<speed>\d+)(?=\s|$)' - ) - kernel_cmdline = read_file('/proc/cmdline') - if m := CMDLINE_CONSOLE_RE.search(kernel_cmdline): - device = m.group("device") # "ttyS0" - speed = m.group("speed") # Baud rate/speed, e.g. "115200" - - return (device, speed) - def activate(config: ConfigTree): - # Configure the kernel serial console only once during live boot. - # During installation, the user can define the console. If this is not - # limited to live boot, the serial interface will always be re-added during - # system boot, even if it was removed from config.boot. + # Configure the kernel serial console only once during live boot. During + # installation, the user can define the console type (VT TTY or serial + # TTY). If this is not limited to live boot, the serial interface will + # always be re-added during system boot, even if it was removed from + # config.boot. if not is_live_boot(): return - (device, speed) = get_kernel_serial_console() - if device and speed: - # The kernel was booted with a configured serial console, but no - # console is configured in the CLI; align/fix the CLI configuration. - if not config.exists(base + [device]): - config.set(base + [device, 'speed'], value=speed) - config.set_tag(base) + # Parse current kernel cmdline and continue only for valid serial console + # data. Prevent writing incomplete/invalid console settings to config.boot. + console_type, console_num, console_speed = get_kernel_serial_console() + device = f'{console_type}{console_num}' + if not is_tty(device) or not console_speed: + return + + # The kernel was booted with a configured serial console, but no console + # is configured via CLI; align/fix the CLI configuration. + if not config.exists(base + [device]): + config.set(base + [device, 'speed'], value=console_speed) + config.set_tag(base) |
