# Move FreeBSD kernel messages (white) to second console



## vermaden (Nov 29, 2017)

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 (Nov 29, 2017)

The "redirect" to logfile solution is:
In /boot/loader.conf

```
boot_mute="YES"
```
Then in /etc/syslog.conf I have

```
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.


----------



## mrclksr (Nov 29, 2017)

vermaden said:


> but is there a way to move them to second console instead of disabling them?



conscontrol(8)


----------



## vermaden (Nov 29, 2017)

mrclksr said:


> conscontrol(8)


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:


```
# 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 (Nov 29, 2017)

vermaden said:


> # 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 (Nov 29, 2017)

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``


----------



## vermaden (Dec 5, 2017)

mrclksr said:


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

```
currdev   Selects the default device.  Syntax for devices is odd.
```

Also this from loader(8)() does not help a lot.

```
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)).
```


----------



## vermaden (Dec 5, 2017)

mrclksr said:


> 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 (Dec 5, 2017)

From /boot/default/loader.conf:

```
#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):

```
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.


vermaden said:


> 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 (Dec 5, 2017)

vermaden said:


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


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.


----------



## Maxnix (Dec 5, 2017)

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:

```
#!/bin/sh
/sbin/conscontrol set ttyv1
/usr/libexec/getty Pc
```
and could be put here (?) in /etc/ttys:

```
ttyv0   "/usr/local/lib/ttyscript.sh"   xterm   on   secure
```


----------



## mrclksr (Dec 5, 2017)

Maxnix said:


> I didn't see your reply before.


No problem 


Maxnix said:


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


```
#!/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:

```
switchsyscons_enable="YES"
switchsyscons_tty="/dev/ttyv1"
```


----------



## mrclksr (Dec 5, 2017)

Maxnix said:


> and could be put here (?) in /etc/ttys


The problem is that we need `getty` to set up the terminal first.


----------



## mrclksr (Dec 5, 2017)

m)

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


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

```
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
```


----------

