Debian/Ubuntu Tips and Tricks

Debuntu

Debian/Ubuntu Tips and Tricks

How-To set up a serial console on Ubuntu

Posted by chantra on May 3rd, 2008

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

Unlike most other distros, Ubuntu uses upstart instead of sysvinit and as such, there is a few differences between most of the tutorial that you might find on the internet regarding how to set up a serial console.

A 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, the machine we want an access to. Setting up a serial console client will be covered in another article.

1. Checking the serial devices

In order to find which devices are 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

From this output, we can guess that there is 1 serial interface (/dev/ttyS0). You might possibly have more than one interface on your machine, this tutorial considers that you are using device 1 (ttyS0), if you use the second device, you will need to change ttyS0 by ttyS1.

2. Setting up the serial console on the server

On the server, we are going to set up:

  • A serial console on ttyS0
  • Have kernel booting messages output to the serial console
  • Make Grub outputs to the serial console

2.1. The serial console

To set up a serial console, We need to create a new file called /etc/event.d/ttyS0 in order to spawn a getty on the serial device. getty will take care of prompting the user for a username and password.

Go and edit /etc/event.d/ttyS0 and add:

# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
respawn
exec /sbin/getty -L 115200 ttyS0 vt102

To authorize root (if you enabled root account on your machine) to log in through the serial console, you need to edit /etc/securetty and add:

ttyS0

2.2. Having grub outputting to ttyS0

grub can be configured 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 kernels. This will take care of having grub being displayed one the serial console so you can actually modify grub through the serial console or boot using another kernel.

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    /boot/vmlinuz-2.6.24-16-generic root=UUID=uuuuuu-iii3-dddd-uuuu-iiiiiddddd ro quiet splash console=ttyS0,115200n8 console=tty0

That's it, upon next reboot, you will be able to connect directly to your box using a serial console!.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>