Working with the serial console

An Arch Linux machine can be configured for connections via the serial console port, which enables administration of a machine even if it has no keyboard, mouse, monitor, or network attached to it.

Installation of Arch Linux is possible via the serial console as well.

A basic environment for this scenario is two machines connected using a serial cable (9-pin connector cable). The administering machine can be any Unix/Linux or Windows machine with a terminal emulator program (PuTTY or Minicom, for example).

The configuration instructions below will enable boot loader menu selection, boot messages, and terminal forwarding to the serial console.

Configure console access on the target machine

GRUB

When using GRUB with a generated grub.cfg, edit /etc/default/grub and enable serial input and output support:

/etc/default/grub
...
GRUB_TERMINAL_INPUT="console serial"
...
GRUB_TERMINAL_OUTPUT="gfxterm serial"
...

Next add the GRUB_SERIAL_COMMAND variable and set the options for the serial connection. For COM1 (/dev/ttyS0) with baud rate of 115200 bit/s:

/etc/default/grub
...
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200"

Read GRUB's manual on Using GRUB via a serial line and the serial command for detailed explanation of the available options.

GRUB Legacy

Edit the GRUB Legacy configuration file /boot/grub/menu.lst and add these lines to the general area of the configuration:

serial --unit=0 --speed=9600
terminal --timeout=5 serial console
Note: When the terminal --timeout=5 serial console line is added to your menu.lst, your boot sequence will now show a series of Press any key to continue messages. If no key is pressed, the boot menu will appear on whichever (serial or console) appears first in the terminal configuration line.

rEFInd

rEFInd supports serial console only in text mode. Edit refind.conf and uncomment textonly.

Syslinux

To enable serial console in Syslinux, edit and add as the first directive in the configuration file.

For COM1 (/dev/ttyS0) with baud rate of 115200 bit/s:

SERIAL 0 115200

The serial parameters are hardcoded to 8 bits, no parity and 1 stop bit.. Read Syslinux Wiki:Config#SERIAL for the directive's options.

Kernel

Kernel's output can be sent to serial console by setting the kernel parameter. The last specified will be set as .

console=tty0 console=ttyS0,115200

See https://docs.kernel.org/admin-guide/serial-console.html.

getty

At boot, will start a getty instance for each console specified in the kernel command line.

If you have not configured in kernel command line start serial-getty@device.service. For /dev/ttyS0 (COM1) that would be . Enable the service to start it at boot.

Unless specified otherwise in the kernel command line, getty will be expecting 38400 bit/s baud rate, 8 data bits, no parity and one stop bit-times.

Making Connections

Connect using a terminal emulator program

Perform these steps on the machine used to connect the remote console.

dterm

dtermAUR is a tiny serial communication program. If you invoke it without parameters, it will connect to /dev/ttyS0 at 9600 baud by default. The following example connect to /dev/ttyS0 at 115200 baud, with 8 data bits, no parity bit and 1 stop bit-times:

$ dterm 115200 8 n 1

See its homepage for more examples.

Minicom

can be obtained from the official repositories. Start Minicom in setup mode:
$ minicom -s

Using the textual navigation menu, change the serial port settings to the following:

Serial Device: /dev/ttyS0
Bps/Par/Bits: 9600 8N1

Press Enter to exit the menus (pressing Esc will not save changes). Remove the modem Init and Reset strings, as we are not connecting to a modem. To do this, under the menu, delete the Init and Reset strings. Optionally save the configuration by choosing from the main menu. Restart minicom with the serial cable connected to the target machine. To end the session, press followed by .

picocom

is a tiny dumb-terminal emulation program that is very like minicom, but instead of mini, it is pico. The following example connect to ttyS0 at 9600 bps:
$ picocom -b 9600 /dev/ttyS0

See its manual for detailed usage.

Screen

GNU Screen is able to connect to a serial port. It will connect at 9600 baud by default:

$ screen /dev/ttyS0

A different baud rate (e.g. 115200) may be specified on the command line.

$ screen /dev/ttyS0 115200

To end the session, press followed by . Alternatively, press , type and confirm it by pressing .

Serialclient

Serialclient is a CLI client for serial connection written in ruby. Install ruby package, then install it with the following:

# gem install serialclient

Then, you can use like this:

$ serialclient -p /dev/ttyS0

tinyserial

is a  replacement for accessing serial ports on Linux inspired by FreeBSD 'tip'.
$ com /dev/ttyS0 9600

Graphical front-ends

  • PuTTY A terminal integrated SSH/Telnet client.
https://www.chiark.greenend.org.uk/~sgtatham/putty/ || putty

    Windows clients

    On Windows machines, connect to the serial port using programs like PuTTY or Terminalbpp.

    Installing Arch Linux using the serial console

    1. Connect to the target machine using the method described above.
    2. Boot the target machine using the Arch Linux installation medium.
    3. When the bootloader appears, select Boot Arch Linux (<arch>) and press to edit
    4. Append and press .
    5. Now systemd should detect ttyS0 and spawn a serial getty on it. Login as and start the installation as usual.

    Debugging an unresponsive machine using a serial console

    Even though has only raw and terse instructions, it presents the full scene. It is important to note that here, the machine under test got unresponsive in a reproducible manner. And that it happened during normal operation. So it could be accessed normally before it needed debugging. However, in general, the serial console is also useful for debugging boot issues. Perhaps by configuring the boot loader by hand at machine startup time. Also note the mentioned netconsole within the P.S paragraph of the external link from this section.

    Troubleshooting

    Ctrl+c and Minicom

    If you are having trouble sending a command through minicom you need to switch off hardware flow control in the device settings (), which then enables the break.

    Resizing a terminal

    Unlike ssh, serial connections do not have a mechanism to transfer something like when a terminal is resized. This can cause weird problems with some full-screen programs (e.g. less) when you resize your terminal emulator's window.

    Resizing the terminal via stty is a workaround:

    $ stty rows lines cols columns

    However, this requires you to manually input the proper geometry. The following methods should be simpler.

    1. There is a lesser-known utility called , shipped with , that can solve this problem. Invoke it without parameters after you resize the terminal emulator's window:

    $ resize

    2. If you do not want to install xterm, it is possible to do the same work via a shell function. Put the following function into your bash/zshrc and invoke it without parameters after resizing the terminal emulator's window:

    Missing ports on multi-port expansion cards

    The number of serial ports using the generic 8250 driver on the default kernel configuration is set to 4 at runtime with a maximum of 32. This will prevent the creation of and above. Counting the typical built in serial port on the motherboard this prevents the use of the 4th serial port on a 4 port expansion card.

    This can be overridden with the kernel parameter 8250.nr_uarts. E.g.:

    8250.nr_uarts=5
    gollark: Can someone send me rule 7?
    gollark: I mean, maybe try and require that players sign a contract beforehand?
    gollark: You can't really.
    gollark: r/somewhathorriblejokes
    gollark: No, that was caused by potatOS bricking itself one time due to a bug.
    This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.