Serial console
Hardware
Settings and detection
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
Configuration
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
Software
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 BootLoader
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
Kernel boot
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"
System login
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>
Reference