You can use the command dmesg -n1
to prevent all messages, except panic messages, from appearing on the console.
To make this change permanent, modify your /etc/sysctl.conf
file to include the following setting (the first 3
is the important part).
kernel.printk = 3 4 1 3
See this post for information on the kernel.printk values.
The man page for tty_ioctl lists the ioctl
TIOCCONS. When applied to an open file descriptor of a tty it will redirect future output intended for /dev/console
to that tty.
You can use this in a simple perl script. Create and chmod +x
a file mysetconsole holding the following:
#!/usr/bin/perl
# https://unix.stackexchange.com/a/397790/119298
# see man tty_ioctl for TIOCCONS
# and perldoc IO::Tty::Constant
require "sys/ioctl.ph";
use IO::Tty::Constant qw(TIOCCONS);
ioctl(STDIN,TIOCCONS,0) or die $!;
Assuming you can open the wanted device, use it simply as
sudo ./mysetconsole </dev/ttys3
You will not be able to use it again until you set the console back to /dev/console
, with
sudo sh -c './mysetconsole </dev/console'
You may get perl warnings about _FORTIFY_SOURCE
which can be ignored.
You will need rpm package perl-IO-Tty
or debian package libio-pty-perl
. If you prefer you can just look for the definition of TIOCCONS in the system include files. I found mine in:
/usr/include/asm-generic/ioctls.h: #define TIOCCONS 0x541D
Your perl script can then just be
#!/usr/bin/perl
# https://unix.stackexchange.com/a/397790/119298
sub TIOCCONS{ return 0x541D; }
ioctl(STDIN,TIOCCONS(),0) or die $!;
Best Answer
I've found the answer. It's simple, you just have to add
chvt 4
to/etc/rc.local
file, and that's it.