Archive

Serial Console


How to setup a serial console to manage and boot your Linux box

This document will explain how to setup your Linux box to give you a console via a serial connection. As long as you have a serial port you will be able to log in to a Linux box over serial and also manipulate LILO/grub. If you have a server BIOS that can do serial console redirection then you may also be able to manipulate BIOS settings and watch the entire boot process.

BIOS serial console redirection

If you have a fancy BIOS/motherboard that can do serial console redirection then you will be able to get the entire bootup process from POST to login prompt on your serial console. Make sure that:

  • your BIOS is set to redirect the console always
  • it is using the same speed and settings as your bootloader and your getty (use 9600 8n1 for everything for best compatability)
  • the BIOS agent is set to die as soon as it sees an operating system loaded – otherwise you will get nothing after your bootloader loads a kernel

If you don’t have this then you can still get access to the bootloader and to the machine once a getty is started, but probably nothing before or in between.

Starting a console on the serial port

Edit /etc/inittab

Uncomment or add a line that looks like the following:

{{{  T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100

}}}

Save your inittab and run the following:

{{{  # telinit q

}}}

This reloads your inittab.

Connecting

Connect a serial line to the Linux box and another computer (or a dumb terminal, like a DEC VT420). Open a connection and hit enter. You should see a login prompt.

If you’re connecting from another Linux box, I recommand installing “cu” (apt-get install cu for all Debian users) and then run:

{{{  $ cu -l /dev/ttyS0 -s 9600

}}}

Note: You’ll probably need to add yourself to the dialout group with something like adduser $USER dialout and then logout and back in again (run id after to make sure). Although this really depends on which group owns the ttySx device in question. If you do have to add yourself to that group, ensure that you logout and login again so that the permissions are picked up.

Setting up the bootloader to use a serial line

LILO

If you want to be able to see LILO to boot your Linux box from a serial line, add the following as a global option to /etc/lilo.conf:

{{{  serial=0,9600n8

}}}

The 0 means ttyS0 (or COM1), the 9600 is the speed – these values should be fine.

Then to each kernel image block:

{{{  append="console=tty0 console=ttyS0,9600n8"

}}}

Now run either the following:

{{{  # lilo -v

}}}

Make sure there are no errors, reboot and connect to the serial line – You should be able to see a LILO prompt.

grub

To get into grub over the serial try something like this in your menu.lst:

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

}}}

The first line configures the serial port to use, the second line tells grub where to put its output. It says to send it to both the serial port and to the console (the monitor attached to the machine in this case). grub will print “press any key to continue” repeatedly on both monitor and serial and whichever one sees a keypress first will get the rest of the grub output. The other display will get nothing; don’t panic!

That covers telling grub to allow control of itself via serial console, but you also have to configure the kernel lines of each stanza in your grub config to tell the kernel to display to serial too:

{{{  kernel /vmlinuz-2.6.11.4 root=/dev/sda2 ro console=tty0 console=ttyS0,9600n8

}}}

This tells the kernel to display to both monitor (tty0) and serial (ttyS0).

Note: Whichever way you boot your kernel, unless you have BIOS serial console redirection you won’t see anything on the serial line until the login prompt is displayed. This is normal. Do not panic! Time the boot process if necessary so you know when to expect a login prompt to appear.

References

  • ttyS0: /dev/ttyS0 – This is COM1

  • Linux Remote Serial Console HOWTO – goes into far more detail than this wiki page, and includes lots of (possibly overkill) security advice, also a lot more information about attaching a modem rather than a terminal.

Leave a Reply