[SOLVED] How to change console vt/tty for kernel messages/printk messages.
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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.
I enabled ForwardToConsole and set TTYPath=/dev/tty1 and it works. Thank you. I know I said it wasn't the question here, but would you happen to know why the services clear the boot log on tty1?
would you happen to know why the services clear the boot log on tty1?
See if this helps:
Code:
# grep -A4 cleared /etc/systemd/system/getty.target.wants/getty@tty1.service
# the VT is cleared by TTYVTDisallocate
# The '-o' option value tells agetty to replace 'login' arguments with an
# option to preserve environment (-p), followed by '--' for safety, and then
# the entered username.
ExecStart=-/sbin/agetty -o '-p -- \\u' --noclear %I $TERM
# grep -A4 cleared /etc/systemd/system/getty.target.wants/getty@tty1.service
# the VT is cleared by TTYVTDisallocate
# The '-o' option value tells agetty to replace 'login' arguments with an
# option to preserve environment (-p), followed by '--' for safety, and then
# the entered username.
ExecStart=-/sbin/agetty -o '-p -- \\u' --noclear %I $TERM
My /etc/systemd/system/getty.target.wants/getty@tty1.service already has that so it looks like the bug may be affecting me and I just need to wait for the patch to trickle down in several years, though my /etc/issue isn't symbolic linked anywhere and my /etc/issue has no network/network interface lines. This is the content of /etc/issue:
I copied and pasted badly in comment #4. What's needed is TTYVTDisallocate=no to replace TTYVTDisallocate=yes in getty@tty1.service.
Debian GNU/Linux 11 \n \l is the default for Bullseye.
The bug I referred to explains in its comment #1 that the openSUSE network change notification, which AFAIK doesn't exist in Debian (yet? - I haven't seen it in Bookworm), is preceded by a screen clear. It means network change notifications need to be disabled to keep tty1 boot messages intact.
I copied and pasted badly in comment #4. What's needed is TTYVTDisallocate=no to replace TTYVTDisallocate=yes in getty@tty1.service.
Debian GNU/Linux 11 \n \l is the default for Bullseye.
The bug I referred to explains in its comment #1 that the openSUSE network change notification, which AFAIK doesn't exist in Debian (yet? - I haven't seen it in Bookworm), is preceded by a screen clear. It means network change notifications need to be disabled to keep tty1 boot messages intact.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.