LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to change console vt/tty for kernel messages/printk messages. (https://www.linuxquestions.org/questions/linux-general-1/how-to-change-console-vt-tty-for-kernel-messages-printk-messages-4175722418/)

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.

mrmazda 02-25-2023 10:32 PM

See if this helps:
Code:

# grep -B4 tty /etc/systemd/journald.conf
#ForwardToSyslog=no
#ForwardToKMsg=no
ForwardToConsole=yes
#ForwardToWall=yes
TTYPath=/dev/tty10


Yetoo 02-25-2023 10:48 PM

Quote:

Originally Posted by mrmazda (Post 6413859)
See if this helps:
Code:

# grep -B4 tty /etc/systemd/journald.conf
#ForwardToSyslog=no
#ForwardToKMsg=no
ForwardToConsole=yes
#ForwardToWall=yes
TTYPath=/dev/tty10


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?

mrmazda 02-25-2023 11:06 PM

Quote:

Originally Posted by Yetoo (Post 6413865)
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

Other reasons can account for it, e.g. this.

Yetoo 02-26-2023 05:16 AM

Quote:

Originally Posted by mrmazda (Post 6413870)
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

Other reasons can account for it, e.g. this.

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:
Code:

Debian GNU/Linux 11 \n \l

mrmazda 02-26-2023 06:54 PM

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.

Yetoo 02-27-2023 02:13 PM

Quote:

Originally Posted by mrmazda (Post 6414009)
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.

Setting TTYVTDisallocate=no worked; thanks.


All times are GMT -5. The time now is 05:17 PM.