How-To set up a serial console

This tutorial will go over the step to go through in order to set up a serial console on Linux.

Serial Console becomes handy when running a headless server (i.e no keyboard and screen) or if you cannot connect a a server because of a network issue.

In this tutorial, we will set up a serial console on the server and we will connect to it using another machine, which will be the client.

1. Checking the serial devices

In order to find the devices available on a box, you can run:

$ dmesg | grep tty
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
00:0c: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A

As you can get from this output, there is 1 serial interface (/dev/ttyS0).

2. Setting up the serial console on the server

On the server, we are going to set up:

  • A serial console on ttyS0
  • Make Grub outputs to the serial console

2.1. The serial console

To set up a serial console, We need to modify /etc/inittab in order to spawn a agetty on the serial device. agetty will take care of prompting the user for a username and password.

Go and edit /etc/inittab and add:

s0:2345:respawn:/sbin/agetty -L ttyS0 115200 vt102

below:

# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

Finally, run:

# init q

To reload inittab.

To authorize root to log in through the serial console, you need to edit /etc/securetty and add:

ttyS0

2.2. Having grub outputting to ttyS0

We can also configure grub to output on the serial console.Edit grub and add:

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

In the section before the different kernel. This will take care of having grub being displayed one the serial console.

Change the unit number according to your setting. If using ttyS1, then change it to --unit=1

Also, in order to get the booting messages outputted to the serial console, you can append to your kernel line the following:

console=ttyS0,115200n8 console=tty0

So, finally, the kernel line will look like:

kernel /vmlinuz-2.6.9-67.0.7.EL ro root=/dev/VolGroup00/LogVol00 console=ttyS0,115200n8 console=tty0

Now, let's go on the client side...