Serial Console

From Segfault
Jump to navigation Jump to search


To use GRUB on the serial console, we have to configure the serial line and the output device[1]

serial --unit=0 --speed=115200
terminal_input serial; terminal_output serial

Or, for GRUB Legacy:

serial --unit=0 --speed=115200
terminal --timeout=5 serial console

On most distributions, GRUB can be configured via /etc/default/grub:[2]

GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200"
GRUB_TERMINAL="serial console"
  • If the arrow keys do not work through your serial console, try CTRL+P resp. CTRL+N instead.[3]
  • Add --dumb to GRUB_SERIAL_COMMAND if your terminal is not VT100 compatible.


The FreeBSD boot process, in short:[4][5][6][7][8]

boot0 → boot2 → loader → kernel

To output to the serial console[9], we can configure each stage to do just that.

For the boot2 stage, use boot.config[10]:

$ cat /boot.config
-P                                                  # Or is it "-D"?[9]

For the loader stage, use loader.conf:

$ cat /boot/loader.conf
console="comconsole,vidconsole"                     # Output on serial & video console, in that order
boot_multicons="YES"                                # Output on both devices

Once booted, the userland needs a serial console too:

$ grep ttyu0 /etc/ttys
ttyu0   "/usr/libexec/getty std.9600"  vt100  onifconsole secure



To see the boot messages, add the following to the kernel command line:[11]

console=ttyS0,115200 console=tty0

This will display boot messages both to the first serial port and the VGA console. Both will be usable for login after the system has booted.


 $ grep ttyS0 /etc/inittab /etc/securetty 
 /etc/inittab:S:2345:respawn:/sbin/agetty 115200 ttyS0         # Or "../getty -L ttyS0 115200 vt100" for getty 
 $ init q


 # grep ^[a-z] /etc/init/ttyS0.conf
 start on stopped rc RUNLEVEL=[2345]
 stop on runlevel [!2345]
 exec /sbin/getty -L 115200 ttyS0 xterm
 # initctl start ttyS0


To enable[12] the serial console in an OpenSUSE or Debian system:

$ sudo systemctl enable serial-getty@ttyS0
ln -s '/usr/lib/systemd/system/serial-getty@.service' '/etc/systemd/system/'

$ sudo systemctl start serial-getty@ttyS0
$ ps auxw | grep tt[y]
root      8247  0.0  0.1   4444  1460 tty1     Ss+  00:23   0:00 /sbin/agetty --noclear tty1 linux
root      8608  0.0  0.1   4724  1708 ttyS0    Ss+  00:29   0:00 /sbin/agetty --keep-baud ttyS0 115200 38400 9600 vt102

Adjust the console name as needed, e.g. use hvc0 for Xen VMs.


The serial console has to be activated by adjusting the bootstap software:[13]

$ dumpfs wd0a | grep ^format
format       FFSv2
$ doas installboot -v -o console=auto,speed=0 /dev/wd0a /usr/mdec/bootxx_ffsv2 
File system:         /dev/rwd0a
Primary bootstrap:   /usr/mdec/bootxx_ffsv2
Boot options:        timeout 5, flags 0, speed 0, ioaddr 0, console auto

Go back to a VGA console with console=pc.


The serial console can be configured[14] via boot.conf:

$ cat /etc/boot.conf                                                                                                                                                                               
set timeout 10
set tty com0

Once in the boot prompt, the console output device can be changed to e.g. pc0 again.


$ eeprom ttya-mode='115200,8,n,1,-'

$ cat /rpool/boot/grub/menu.lst 
serial --unit=0 --speed=115200
terminal serial console
timeout 10
default 0

title Oracle Solaris 11 Express snv_151a
findroot (pool_rpool,0,a)
bootfs rpool/ROOT/solaris
kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS,console=ttya -v
module$ /platform/i86pc/$ISADIR/boot_archive

$ grep ^console: /etc/ttydefs 
console:115200 hupcl opost onlcr:115200::console

$ svcadm restart svc:/system/console-login:default

How to send a BREAK

Here's how to send a BREAK via telnet(1):

 # telnet
 Connected to terminalserver.
 Escape character is '^]'.
 ser2net port 2002 device /dev/ttyUSB0 [9600 N81]
 solaris console login: 

OK, now we're at the console prompt. Press ^] to get to the telnet prompt and do:

 telnet> send break
 Type  'go' to resume
 {3} ok printenv