Serial Terminal as Console
A frequently asked, but never completely answered, question in the comp.os.linux.* newsgroups and other Linux mailing lists, is the one about cheap, headless Linux boxes. It seems that many people need to install Linux boxes without a video card, a monitor or a keyboard.
A cheap response to this problem is to use a serial terminal (Wyse or Ampex, for example) as the main Linux console. This cuts the cost of a keyboard, a video card and a monitor. I've done this very thing on my second computer, an old 486 VLB, by using a Wyse 60 terminal.
Linking a terminal to your computer's serial port is not at all difficult. You can easily follow the instructions in the Serial-HOWTO and in the inittab(5) and agetty(8) man pages. Here's a short summary.
First, you must use a null modem cable.
Second, insert the following line in your /etc/inittab file, if you're using agetty. Other getty programs, like getty_ps, use a different syntax.
ID:RUNLEVELS:respawn:/sbin/agetty -L SPEED TTY TERM
ID = a two character identifier, e.g., s1 or s2
RUNLEVELS = Runlevels in which the terminal must be active
SPEED = serial port speed
TTY = tty port name relative to the /dev directory
TERM = value to be used for the TERM environment variable
My machine's /etc/inittab has the following line:
s2:12345:respawn:/sbin/agetty -L 9600 ttyS1 vt100
for a serial terminal on the /dev/ttyS1 port (COM2 for DOS users), with a port speed of 9600 BPS and vt100 terminal emulation (which seems to run better than native Wyse 60 mode).
Finally, restart init with the command init q.
If you correctly followed these three simple steps, you should see the login prompt on your terminal screen. You can log in and work on your machine in the same way you can when you're actually on the console or telneting from a remote host.
The messages the kernel shows at boot time are always directed to your main console (tty1). If you turn on your headless box, you can only wait for the login on the terminal, which means losing those precious messages. You can see them by using the dmesg command, but usually you need them before the login shell comes up.
There are other messages on your console: those generated by the scripts in the /etc/rc.d directory, and from scripts run at boot and shutdown time. How can you really know that “the system is halted” if you can't read it on a monitor?
You must patch the /usr/src/linux/drivers/char/console.c program in your kernel source tree. It's not a complex kernel hack. You can follow these three simple steps.
First, define the CONFIG_SERIAL_ECHO symbol at program start:
Second, modify the address of the terminal serial port (only if you're using a port different from that defined by default) looking for the following line:
#define SERIAL_ECHO_PORT 0x3f8 /* COM1 */In my machine I've changed that line to:
#define SERIAL_ECHO_PORT 0x2f8 /* COM2 */Third, rebuild your kernel and reboot: you should see on your terminal screen the kernel messages during your system's hardware devices probe.
Please note that these steps work for a 2.0.0 kernel, not on 1.2.13. I haven't yet had time to try other kernels. The console.c patch is necessary for all Linux ports except the one for Alpha, which contains it in the make config with the following option:
Echo console messages on /dev/ttyS1
To show these messages on your terminal, you can append > TTY to every line of these files that contains the command echo. TTY is the terminal serial port (the same one used in /etc/inittab serial terminal line).
If you want to choose among more than two kernel images, you have to modif the LILO configuration file, /etc/lilo.conf.
Complete instructions for seeing the LILO prompt on serial terminals can be found in the /usr/doc/lilo/README file (look for the SERIAL option). Here are two steps to do that correctly.
First, edit the /etc/lilo.conf file and insert a SERIAL option line after the BOOT option line:
serial=SERIAL_LINE,SPEED PARITY BITS
SERIAL_LINE = 0 (com1) 1 (com2) 2 (com3) 3 (com4) SPEED = serial port speed PARITY = n (= none) o (= odd) e (= even) BITS = bits in a character (8 or 7)Please note that there are no spaces between the SPEED, PARITY and BITS parameters. These must be equal to the ones defined in your terminal setup. Here's the line used by my machine's LILO:
serial=1,9600n8This line means COM2 at 9600 BPS, no parity, 8 bits per character.
Second, execute the lilo command to update your system's configuration.
Using the SERIAL option, LILO sets a two second delay (the same as when you put a delay = 20 line in the lilo.conf file) before booting the default kernel image. During this pause, you can interrupt the boot process and get the LILO prompt by sending a break to the terminal as you press the SHIFT key on your main console.
At last, your serial terminal can be used as a real system console. I think that the only thing you can't do is the CTRL-ALT-DEL reset—except, perhaps, with certain terminal emulations. If you're lucky, you can find one of these terminals cheaply, maybe even free, from a company upgrading its hardware.
Franceso Conti can be reached by e-mail at firstname.lastname@example.org.