Serial Communication in Linux

Today I set up serial communication with a linux server and thought I'd document the procedure here.  The following instructions assume your linux distro uses GRUB.  This was tested on CentOS 5.6 (ish) and Windows 7.

We'll refer to the Linux computer that we are trying to connect to as the "server".  The computer we are using to make the serial connection will be the "client".

Procedure

Step 1)  On the server, open /boot/grub/grub.conf in a text editor and find the entry for your current kernel.  It will look something like this:
default=0
timeout=5
hiddenmenu
title CentOS (2.6.18-194.17.4.el5.centos.plus)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.17.4.el5.centos.plus ro root=/dev/VolGroup00/LogVol00 rhgb quiet
        initrd /initrd-2.6.18-194.17.4.el5.centos.plus.img

You may see multiple title sections.  Each of these is another possible boot option in GRUB.  Every time a new kernel is installed, a new boot entry is added to this list.  The old boot entry and kernel are left behind so that you can boot with them if you end up having any issues with your system.

In order to have terminal output displayed over serial during bootup, we need to append some serial settings to the appropriate boot entry.  Each title section is implicitly numbered starting with 0.  Take a look at your default=# line to determine which entry is booting up by default and add your changes to that entry.  Or you could just add the serial settings to every entry.
default=0
timeout=5
hiddenmenu
serial --unit=0 --speed=38400 --word=8 --parity=no --stop=1
terminal --timeout=30 serial console
title CentOS (2.6.18-194.17.4.el5.centos.plus)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.17.4.el5.centos.plus ro root=/dev/VolGroup00/LogVol00 rhgb quiet console=tty0 console=ttyS0,38400n8
        initrd /initrd-2.6.18-194.17.4.el5.centos.plus.img

Step 2)  Open /etc/inittab in a text editor.  Add the following two lines at the bottom of the file:
T0:23:respawn:/sbin/getty -L ttyS0 38400 vt100
T1:23:respawn:/sbin/getty -L ttyS1 38400 vt100

Step 3)  Connect the server and client computers together with a serial cable.

Step 4)  Open up a serial communication program on the client computer.  I prefer to use Hyper Terminal.  This program was included free in Windows XP, but is not part of Windows Vista or later.  If you can copy the program from a Windows XP computer, it will still run in newer versions of Windows.

Step 5)  Configure Hyper Terminal for to use the proper serial settings.  For us, that will be:

Port:  COM3
Bits per second:  38400
Data bits:  8
Parity:  No
Stop Bits:  1
Flow Control:  Hardware

If you are using an actual serial port on the client, you will most likely be using COM1 or COM2.  If, like me, you are using a Serial-to-USB converter, it will probably be COM3.  If the above settings still don't work, try changing Flow Control to None.

Final

At this point, you will be able to see the normal terminal output during server bootup on the client's serial display.  Once the Linux server is booted up, you will be presented with a login prompt giving you shell access to the server.


No comments:

Post a Comment