doc:techref:serialconsole

Serial console

Obvisouly we need a serial port enabled in the BIOS, to avoid issues make sure is not sharing the IRQ with any other device. If you don't have any physical port you will need a USB-dongle.

The command setserial will allow you to review and configure the settings if required (not usually needed):

# setserial /dev/ttyS0
/dev/ttyS0, UART: 16550A, Port: 0x0000, IRQ: 60
# setserial /dev/ttyS1
/dev/ttyS1, UART: 16550A, Port: 0x0000, IRQ: 66
First MUST is to decide a serial configuration on speed, bits, stop bits and parity. As you will have to configure it in some distinct software and configruations is better to have been defined prior to start diving in the system. For some devices like network equipment which usually defaults to a serial configuration is highly recommended to keep that setting as its default (in case of any config reset)

As reference this are the usual available settings:

Speed transmission rate in bps 1200, 2400, 4800, 9600, 19200, 38400, 57600 or 115200 bps
Parity Parity bit checksum (None), (O)dd, (E)ven
Data bits how many bits to encode data 7 or 8
Stop bit Bits to mark stop 1 or 2
Other other flows settings like CTS/RTS

Usually many devices use the 9600N8 configuraiton (9600bps, No parity and 8bit data). If you have long cables and suffering issues is recommended to lower the speed.

We can safe this settings into /etc/setserial.conf to configure the port by default, although each software configures it by itself:

setserial -G /dev/ttyS0 >> /etc/setserial.conf

The whole boot process involves various software, and each one will need to be configured to use the serial port for its input/output console operation.

GRUB Legacy

serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console

GRUB2

For Debian based sytems, best way is to edit /etc/default/grub file:

GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1"

http://www.gnu.org/software/grub/manual/html_node/Serial-terminal.html#Serial-terminal

You must pass console configuration to kernel, this should be done ideally on the grub line which boots Linux. Note that 2 console params are passed in order to not lose the physical console. As before we put this configuration on the grub config file:

GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0,9600n8 console=tty0"

Once kernel has booted, the kernel will show no more messages on the console (except for new events). To be able to login on the system one a serial termianl you must configure init to start a login process on the serial console so you can log on the system once booted.

How to do so depends highly on the system services start architecutre which may be inittab based or upstart.

SystemV (Debian)

Edit /etc/inittab file

co:12345:respawn:/sbin/agetty -8 19200 ttyS0

UpStart (Ubuntu)

You need to create a file under /etc/init/ directory to represent the login service. Call it for example serial-console:

# serial-console 
#
# This service maintains a serial console
start on stopped rc RUNLEVEL=[12345] and (
            not-container or
            container CONTAINER=lxc or
            container CONTAINER=lxc-libvirt)
stop on runlevel [!12345]
respawn
exec /sbin/agetty -8 19200 ttyS0
  • <todo>Document SystemD serial console use</todo>
  • <todo>Document client quick usage</todo>
  • <todo>Conserver document and reference</todo>
  • doc/techref/serialconsole.txt
  • Last modified: 2021/06/10 21:45
  • by 127.0.0.1