Yetoo |
02-25-2023 09:51 PM |
How to change console vt/tty for kernel messages/printk messages.
I want to change where kernel messages are printed to such as (e.g. ...eth0: control flow is disabled...). I have a full screen text application that a systemd service starts and runs in console/vt that I want to run in tty2 but then keep boot log as well as kernel messages in tty1. I was able to change the default tty by having systemd service that executes chvt 2 on startup and, while the vt switches to tty2 where the full screen text application runs, kernel messages now appear on tty2 rather than tty1 and the boot log doesn't show up, but question isn't about latter. The full screen text application and chvt 2 are started and run in separate systemd service scripts on start up, but despite different Description and ExecStart, they are essentially the same script:
Code:
[Unit]
Description=
After=getty.target
Conflicts=getty@tty2.service
[Service]
Type=oneshot
ExecStart=<scriptpath>
TTYPath=/dev/tty2
StandardInput=tty
StandardOutput=inherit
StandardError=inherit
[Install]
WantedBy=multi-user.target
I include the script(s) here because I don't know if I need to wait for something after getty or something else. For the script that changes the vt, if I set After= to the service that starts the full screen application it boots to tty1 and doesn't switch to tty2. If I change After= to Before= it boots to tty2 then shows the kernel messages and then switches to tty1. If I add After= and put getty.target it boots to tty2 but also shows kernel messages so same behavior as posted service script. Setting Requires= for the other service on each one at a time doesn't seem to change anything. This doesn't seem like an ordering issue and more internal to the kernel.
https://unix.stackexchange.com/quest...ut-to-the-curr indicates that passing "TIOCL_SETKMSGREDIRECT subcommand to the TIOCLINUX ioctl() against a KVT device" with the number of console/vt and /dev/console supplied needs to be set via ioctl. Is there a way to do this with proc? Is this the wrong approach? Busybox on Debian says setlogcons: applet not found. I don't trust the Allan Cruse C code has been vetted. I'm not fluent in C, but it uses atoi to convert user supplied char to integer and I know atoi isn't safe compared to strtol, but I don't know what else could be wrong with it.
Setting console=tty1 in GRUB_CMDLINE_LINUX_DEFAULT or GRUB_CMDLINE_LINUX doesn't appear to do anything.
Insight on what I need to do would be helpful. I am attempting to do this on Debian 11.
|