LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 02-25-2023, 09:51 PM   #1
Yetoo
Member
 
Registered: Dec 2015
Distribution: Fedora, Debian, Ubuntu, couldn't install gentoo
Posts: 44

Rep: Reputation: 5
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.

Last edited by Yetoo; 02-25-2023 at 09:54 PM.
 
Old 02-25-2023, 10:32 PM   #2
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,852
Blog Entries: 1

Rep: Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074
See if this helps:
Code:
# grep -B4 tty /etc/systemd/journald.conf
#ForwardToSyslog=no
#ForwardToKMsg=no
ForwardToConsole=yes
#ForwardToWall=yes
TTYPath=/dev/tty10
 
1 members found this post helpful.
Old 02-25-2023, 10:48 PM   #3
Yetoo
Member
 
Registered: Dec 2015
Distribution: Fedora, Debian, Ubuntu, couldn't install gentoo
Posts: 44

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by mrmazda View Post
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?
 
Old 02-25-2023, 11:06 PM   #4
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,852
Blog Entries: 1

Rep: Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074
Quote:
Originally Posted by Yetoo View Post
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.
 
Old 02-26-2023, 05:16 AM   #5
Yetoo
Member
 
Registered: Dec 2015
Distribution: Fedora, Debian, Ubuntu, couldn't install gentoo
Posts: 44

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by mrmazda View Post
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
 
Old 02-26-2023, 06:54 PM   #6
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,852
Blog Entries: 1

Rep: Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074
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.
 
1 members found this post helpful.
Old 02-27-2023, 02:13 PM   #7
Yetoo
Member
 
Registered: Dec 2015
Distribution: Fedora, Debian, Ubuntu, couldn't install gentoo
Posts: 44

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by mrmazda View Post
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.

Last edited by Yetoo; 02-27-2023 at 02:15 PM.
 
  


Reply

Tags
console, ioctl, kernel, systemd, tty



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kernel: printk: 3 messages suppressed. dubnik Linux - Server 1 08-14-2010 08:46 AM
printk does not output in the /var/log/messages for kernel compiled with debugging shoily Linux - Kernel 2 06-01-2008 05:08 PM
printk(KERN_DEBUG ...) vs printk(...) Sergei Lavrov Linux - Kernel 2 03-25-2007 04:41 PM
linux kernel: printk: 39476 messages suppressed. seanfitz Mandriva 4 04-19-2005 04:36 PM
change tty => system crashes (ati driver/tty resolution) mosca Debian 6 08-05-2004 07:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration