diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-04-14 14:24:09 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-14 14:24:09 +0000 |
| commit | 96573c5c3fa4a619819e808c4f8e7a8996cf7fe6 (patch) | |
| tree | bfb63f8c4d25632a90cb3b58b69c137511656eea /src/activation-scripts | |
| parent | 73f743d176f96affceab004c92d19b561f71a24e (diff) | |
| parent | 35db941bcf30f3fac5b1358aa1124f34f9808950 (diff) | |
| download | vyos-1x-96573c5c3fa4a619819e808c4f8e7a8996cf7fe6.tar.gz vyos-1x-96573c5c3fa4a619819e808c4f8e7a8996cf7fe6.zip | |
Merge pull request #5092 from c-po/kernel-serial-activation
serial: T8375: use boot activation script to define a serial console on the CLI
Diffstat (limited to 'src/activation-scripts')
| -rwxr-xr-x | src/activation-scripts/05-serial_console.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/activation-scripts/05-serial_console.py b/src/activation-scripts/05-serial_console.py new file mode 100755 index 000000000..ccda2ac4e --- /dev/null +++ b/src/activation-scripts/05-serial_console.py @@ -0,0 +1,43 @@ +# Copyright (C) VyOS Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# 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/>. + +from vyos.configtree import ConfigTree +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 activate(config: ConfigTree): + # 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 + + # 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) |
