Move FreeBSD kernel messages (white) to second console

vermaden

Son of Beastie

Reaction score: 1,226
Messages: 2,798

By default FreeBSD puts kernel messages (white color) on the first console.

I know I can disable them with boot_mute in the /boot/loader.conf file, but is there a way to move them to second console instead of disabling them? ... or to redirect them to some file instead of disabling them?

Thanks,
vermaden
 

getopt

Aspiring Daemon

Reaction score: 411
Messages: 609

The "redirect" to logfile solution is:
In /boot/loader.conf
Code:
boot_mute="YES"
Then in /etc/syslog.conf I have
Code:
console.*;kern.none       /var/log/console.log   # no kernel messages in console.log
kern.*                    /var/log/kern.log      # kernel messages go here
This should do it, where kern.none in the console line is optional, but prevents duplicate logging.
 
OP
OP
vermaden

vermaden

Son of Beastie

Reaction score: 1,226
Messages: 2,798

I have also seen that utility, but I assumed that only mute is possible.

However I can not change to ttyv1 (second console?) with that utility:

Code:
# conscontrol list
Configured: ttyv0
 Available: ttyv0
    Muting: off
# conscontrol add ttyv1
conscontrol: could not add ttyv1 as a console: Device not configured
# conscontrol add /dev/ttyv1
conscontrol: could not add ttyv1 as a console: Device not configured
 

mrclksr

Active Member

Reaction score: 123
Messages: 153

# conscontrol add ttyv1 conscontrol: could not add ttyv1 as a console: Device not configured # conscontrol add /dev/ttyv1 conscontrol: could not add ttyv1 as a console: Device not configured
Use [FONT=Courier New]set[/FONT] instead of [FONT=Courier New]add[/FONT]:

conscontrol set ttyv1
 

mrclksr

Active Member

Reaction score: 123
Messages: 153

Unfortunately, messages sent to another tty don't contain a [FONT=Courier New]<CR>[/FONT], as it seems, so the output is quite messy. But you can fix that using stty(1):

stty -f /dev/ttyv1 `stty -f /dev/ttyv0 -g`
 
OP
OP
vermaden

vermaden

Son of Beastie

Reaction score: 1,226
Messages: 2,798

Use [FONT=Courier New]set[/FONT] instead of [FONT=Courier New]add[/FONT]:

conscontrol set ttyv1
Thanks,

how to setup it upon boot in /boot/loader.conf?

The 'documentation' from loader(8)() for currdev is quite useless:
Code:
     currdev   Selects the default device.  Syntax for devices is odd.
Also this from loader(8)() does not help a lot.
Code:
  console   Defines the current console or consoles.  Multiple consoles may
               be specified.  In that case, the first listed console will
               become the default console for userland output (e.g. from
               init(8)).
 
OP
OP
vermaden

vermaden

Son of Beastie

Reaction score: 1,226
Messages: 2,798

Unfortunately, messages sent to another tty don't contain a [FONT=Courier New]<CR>[/FONT], as it seems, so the output is quite messy. But you can fix that using stty(1):

stty -f /dev/ttyv1 `stty -f /dev/ttyv0 -g`
Isnt that a bug and should be submitted for fixing?
 

mrclksr

Active Member

Reaction score: 123
Messages: 153

From /boot/default/loader.conf:
Code:
#currdev="disk1s1a"             # Set the current device
This is probably the device the system boots from, or so.

From a more recent manual page of loader.conf(5):
Code:
          console   (“vidconsole”) “comconsole” selects serial console,
                     “vidconsole” selects the video console, “nullconsole”
                     selects a mute console (useful for systems with neither a
                     video console nor a serial port), and “spinconsole”
                     selects the video console which prevents any input and
                     hides all output replacing it with “spinning” character
                     (useful for embedded products and such).
So this variable is useless for your intention. I'm afraid, I have no idea how to solve your problem, but I keep thinking about it.
Isnt that a bug and should be submitted for fixing?
I would say no. The system console is configured to map <CR> to <NL>, while the other terminals are not.
 

Maxnix

Well-Known Member

Reaction score: 207
Messages: 329

Thanks,

how to setup it upon boot in /boot/loader.conf?

The 'documentation' from loader(8)() for currdev is quite useless:
Code:
     currdev   Selects the default device.  Syntax for devices is odd.
Also this from loader(8)() does not help a lot.
Code:
  console   Defines the current console or consoles.  Multiple consoles may
               be specified.  In that case, the first listed console will
               become the default console for userland output (e.g. from
               init(8)).
I did some researches, and discovered that:
currdev is used to select the default filesystem from which the system had to boot (ref.: Thread 50391 /boot/defaults/loader.conf).
console sets the console type rather than the desired tty (i.e. vidconsole, dcons, gdb).
Unfortunately, nothing that can help setting the tty at boot... :(

Edit: Thank you for your reference about the updated man page mrclksr. :) I didn't see your reply before. :oops:
 

Maxnix

Well-Known Member

Reaction score: 207
Messages: 329

A dirty hack (that probably won't work) came in mind: using a shell script loaded at boot time in /etc/ttys?
This is the script:
Code:
#!/bin/sh
/sbin/conscontrol set ttyv1
/usr/libexec/getty Pc
and could be put here (?) in /etc/ttys:
Code:
ttyv0   "/usr/local/lib/ttyscript.sh"   xterm   on   secure
 

mrclksr

Active Member

Reaction score: 123
Messages: 153

I didn't see your reply before.
No problem :)
A dirty hack (that probably won't work) came in mind: using a shell script loaded at boot time in /etc/ttys?
I tried the following, which works, but is, as you said, a dirty hack:

Code:
#!/bin/sh -

# PROVIDE: switchsyscons
# REQUIRE: LOGIN

# switchsyscons_tty (string)   # Name of new system console

. /etc/rc.subr

ttyopts="gfmt1:cflag=4b00:iflag=2b42:lflag=c3:oflag=3:discard=f"
ttyopts="$ttyopts:dsusp=ff:eof=ff:eol=ff:eol2=ff:erase=7f:erase2=8"
ttyopts="$ttyopts:intr=3:kill=15:lnext=ff:min=1:quit=1c:reprint=ff"
ttyopts="$ttyopts:start=11:status=ff:stop=13:susp=ff:time=0:werase=ff"
ttyopts="$ttyopts:ispeed=9600:ospeed=9600"

name="switchsyscons"
start_cmd="switchsyscons_start"
stop_cmd=":"

do_switch()
{
 
   if [ -z $switchsyscons_tty ]; then
       echo "switchsyscons_tty not defined"
   else
       while [ true ]; do
           # Wait for getty
           sleep 1
           pgrep getty && break
       done
       /bin/stty -f $switchsyscons_tty $ttyopts
       /sbin/conscontrol set $switchsyscons_tty
   fi
}

switchsyscons_start()
{
   do_switch&
}

load_rc_config $name
run_rc_command $*
in /etc/rc.conf:
Code:
switchsyscons_enable="YES"
switchsyscons_tty="/dev/ttyv1"
 

mrclksr

Active Member

Reaction score: 123
Messages: 153

m)

It's just a slight modification to the solution getopt posted:

Code:
echo boot_mute="YES" >> /boot/loader.conf
(BTW: there is also [FONT=Courier New]kern.consmute[/FONT])

Then extend getopt 's /etc/syslog.conf snippet:
Code:
console.*;kern.none       /var/log/console.log   # no kernel messages in console.log
kern.*                    /var/log/kern.log      # kernel messages go here
kern.*                    /dev/ttyv1             # Redirect kernel messages to /dev/ttyv1
 
Top