Skip to contentSkip to conversation

serial console _after_ boot ? - was: Redirect kernel console

DISCUSSION [email protected] 3 participants 3 messages Jan 3, 2008

lore
Share & tools
lore
#0 lore raw

hi !

i was wondering how to make kernel messages appear on /dev/ttyS0 without a reboot, i.e. kernelparam "console=ttyS0"

after playing for a while with setconsole, setterm and klogconsole i didn`t find a way to make that happen.

i can do "setconsole /dev/tty1 </dev/console" and then "echo test >/dev/console" and see "test" on tty1

"setterm -msg on -msglevel 8 >/dev/console" (or >/dev/tty1), modprobe loop;rmmod loop - and i see the kernel message there

i can do "setconsole /dev/ttyS0 </dev/console" and then "echo test >/dev/console" and see "test" on ttyS0

BUT :

"setterm -msg on -msglevel 8 >/dev/console" (or >/dev/ttyS0), modprobe loop;rmmod loop ...... nothing!

since i came across jans posting from 2005, which didnt get a reply i think it`s not that stupid to ask again...

any clue how to do that at runtime or what`s the issue here ? (see excerpts below)

i can set
regards
roland

List:       linux-kernel
Subject:    Redirect kernel console
From:       Jan Engelhardt <jengelh () linux01 ! gwdg ! de>
Date:       2005-08-13 12:48:22
Message-ID: Pine.LNX.4.61.0508131447220.4457 () yvahk01 ! tjqt ! qr

[Download message RAW]

Hi,

there is a klogconsole utiltity that allows to change the console to which kernel messages are printed. However, is it possible to redirect to ttyS0 without a reboot?

Jan Engelhardt
-------

Quoted 28 lines
Quoted 10 lines

Subject: Re: serial console _after_ boot ?

Quoted 5 lines

Setterm outputs the correct escape sequences to stdout. You can configure another tty using 'setterm -msglevel 8 -msg on > /dev/ttyS0'. I tested this on the standard kernel consoles (/dev/tty1-9), and it worked. You obviously need root access to write the escape sequences to the tty's.

oh - yes, this works! but with tty1-9 only.
not with ttyS0 :(

.....as the docs tell.....

Some options however (marked "virtual consoles only" below) do not correspond to a terminfo(5) capability.

-msg [on|off] (virtual consoles only)
Enables or disables the sending of kernel printk() messages to the console.

-msglevel 1-8 (virtual consoles only)
Sets the console logging level for kernel printk() messages. All messages strictly more important than this will be printed, so a logging level of 0 has the same effect as -msg on and a logging level of 8 will print all kernel messages. klogd(8) may be a more convenient interface to the logging of kernel messages.

Quoted 4 lines
Quoted 4 lines

but i don`t have change_console.
searched the net and found that this eventually should be part of sysvinit package. but mine doesn`t provide that tool.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

found "setconsole" which looks like something similar, but "setconsole /dev/ttyS0 < /dev/console" doesn`t have any effect

What distribution do you use? I have change_console on gentoo, yet I cannot find the tool on a debian etch. But that's a vserver, so it's probably not a reference.

i have opensuse 10.3

_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066

#1 lore raw
Quoted 4 lines · On Jan 3 2008 13:43, [email protected] wrote:

hi !

i was wondering how to make kernel messages appear on /dev/ttyS0 without a reboot, i.e. kernelparam "console=ttyS0"

The solution is simple... the following piece of code is inside opensuse-10.3/src/sysvinit-2.86-115.src.rpm#showconsole-1.08.tar.bz2#showconsole-1.08/blogd.c

(void)ioctl(0, TIOCCONS, NULL); /* Undo any current map if any */ if (ioctl(pts, TIOCCONS, NULL) < 0)
error("can not set console device to %s: %s\n", ptsname, strerror(errno));

so I suppose that's it. Write up a new program that calls the ioctl on a tty, and you should be done. IOW:

#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

int main(void)

{
	int fd = open("/dev/ttyS0", O_RDWR);
	ioctl(0, TIOCCONS, NULL);
	ioctl(fd, TIOCCONS, NULL);
}
#2 lore raw

In article <[email protected]>,

Quoted 11 lines · Jan Engelhardt
Quoted 4 lines · On Jan 3 2008 13:43, [email protected] wrote:

hi !

i was wondering how to make kernel messages appear on /dev/ttyS0

without a reboot, i.e. kernelparam "console=ttyS0"

The solution is simple... the following piece of code is inside opensuse-10.3/src/sysvinit-2.86-115.src.rpm#showconsole-1.08.tar.bz2#showconsole-1.08/blogd.c

Quoted 7 lines

(void)ioctl(0, TIOCCONS, NULL); /* Undo any current map if any */ if (ioctl(pts, TIOCCONS, NULL) < 0)
error("can not set console device to %s: %s\n", ptsname,
strerror(errno));

so I suppose that's it. Write up a new program that calls the ioctl on a tty, and you should be done. IOW:

TIOCCONS only works for pseudo terminals.

Besides, it only redirects stuff you send to /dev/console. It doesn't change what devices printk() prints to. Currently there is no way to change that on a running kernel.

Mike.