Serial console settings are used by three independent subsystems:
- By GRUB for displaying the boot menu and allowing the user to interact with it.
- By Linux kernel, for displaying boot messages.
- By getty, for allowing users to log in.
When we build images that should be usable via a serial console right on the first boot, the system console subtree in the config is not enough because the GRUB config with correct console settings for the boot menu and kernel command line needs to exist before the config is loaded on first boot.
Therefore currently a flavor file for a platform that needs a serial console has to look like this:
default_config = '''
...
system {
...
console {
device ttyACM0 {
speed "115200"
}
}
...
'''
[boot_settings]
console_type = "ttyACM"
console_num = '0'
console_speed = "115200"The same information about the console device and speed has to be specified twice: in the config for login and in [boot_settings] for generating a correct GRUB config.
This is especially annoying when two platforms or architectures only differ in their console settings. For example, the default device is typically /dev/ttyS0 on x86 devices but /dev/ttyAMA0 on Aarch64 ones, which means the generic flavor for Aarch64 has to use a different default config — just for the console settings and nothing else.
Console data in [boot_settings] has to stay because we need to generate GRUB configs, and we almost certainly don't want to make the image build process require the config parsing library to extract it from default_config (although we technically could, getting it from TOML is much simpler).
We can, however, eliminate the need to store explicit console settings in the VyOS config.
We can use the data from [boot_settings] to produce the "platform default console" data file. We can store it in /usr/share/vyos/default_console.toml (for example) and it may look like this:
toml device = 'ttyACM' number = 0 speed = 115200
Then we can apply settings from the file to the system config. How exactly?
Some options we discussed among the maintainers are:
- Launch getty on the platform default console if /usr/share/vyos/default_console.toml file exists and system console is empty (or doesn't include the console that is the default).
- Introduce a special device name default — when a user configures set system console default speed 9600, get the device name from /usr/share/vyos/default_console.toml.
- Use the config activation mechanism to inject settings from /usr/share/vyos/default_console.toml into the config on first boot.
Option 1 seems simple but has an unfortunate side effect: it becomes impossible to disable the default console from inside the normal VyOS configuration.
Option 2 is better but raises a question what to do when a user configures both default and ttyS0 on a system where ttyS0 is also the default — we can make the explicit version win or throw an error, but neither option is truly intuitive.
So far option 3 seems the most attractive. The config activation mechanism is already used to inject various system-default settings such as Ethernet offload and hw-id.
We can also use the same mechanism to populate system console from /usr/share/vyos/default_console.toml on first boot. That will remove the need to store that data in multiple places without changing the syntax or behavior of the normal VyOS config.