How To Configure Linux Serial Consoles

Need a serial console on your Linux box, just in case something happens to the network? Yeah, me too. It’s fairly simple to get it running (at least on Red Hat Enterprise Linux 4), if you have the right steps.

This is not an in-depth tutorial on serial consoles, it’s just designed to get you moving faster. I assume you know how to install packages, edit files, etc., or are at least resourceful enough to figure it out. I also assume you’re s-m-r-t enough to try this on a machine you can get to easily, if you mess it up the first time.

On newer machines there are often BIOS serial redirection options, too, which might be useful. Conveniently, check your BIOS! :-)

1. Figure out what speed your terminal server wants to go, as well as the number of data, parity, and stop bits. 9600 is a common default, and the other parameters are often 8, N, and 1. Faster speeds generally mean it’s less annoying to work on them, but it has to be set the same on both sides, and you can go too fast for the cables you have.

You can verify the settings with “/usr/bin/screen /dev/ttyS0” (as suggested by Greg in the comments), or /usr/bin/minicom (installed as the “minicom” package from Red Hat). If you ever used Telix for DOS you’ll be right at home with minicom. Hit Ctrl-A, then O to get to the configuration menu. Once it is set up properly you should be able to type in Minicom and have it appear on the terminal server, and vice versa. Don’t go on until you can do that.

/dev/ttyS0 is COM1, /dev/ttyS1 is COM2, etc.

From here on out replace 9600, 8N1, and ttyS0 in my examples with the right parameters for your setup.

2. Add the following to /etc/inittab, remembering to substitute the right serial port, and the terminal type you want:

# Serial Console Access
S0:2345:respawn:/sbin/agetty ttyS0 9600 vt100

Have ‘init’ reread inittab by issuing the command “sudo /sbin/telinit q” and you should be able to see something via the terminal server. You might need to hit enter a couple of times to get its attention.

3. If you want to see stuff at boot, edit /etc/grub.conf. Add the following, substituting the proper serial port in “unit”:

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

(two lines, “serial” and “terminal,” if it wraps)

4. Comment out any line in /etc/grub.conf that starts with “splashimage.” The splash image doesn’t work so well with character-only interfaces.

5. Add “console=ttyS0,9600n8” to the proper kernel entry in /etc/grub.conf. So your original entry:

title Red Hat Enterprise Linux AS (2.6.9-67.EL)
  root (hd0,0)
  kernel /vmlinuz-2.6.9-67.EL ro root=/dev/sda1 rhgb quiet
  initrd /initrd-2.6.9-67.EL.img

becomes something like:

title Red Hat Enterprise Linux AS (2.6.9-67.EL)
  root (hd0,0)
  kernel /vmlinuz-2.6.9-67.EL ro root=/dev/sda1 rhgb quiet console=ttyS0,9600n8
  initrd /initrd-2.6.9-67.EL.img

(that’s four lines if it’s wrapping)

6. Reboot and check it out. Party like it’s 1989.

If it isn’t working you’ll have to comment out the inittab line and “telinit q” again to free up the serial port, before you try Minicom or screen.

If I have messed something up here let me know in the comments. Thanks!

Comments on this entry are closed.

  • Out of curiosity, why do you suggest installing mgetty rather than using agetty?

  • As an alternative to minicom, give GNU screen a shot. It works just as well and is more likely to be installed by default.

    “screen /dev/ttyS0” is usually enough; you can tack baud rates and other serial settings on the end, if required.

  • Good point, Scott. My notes were from a time when I needed FAX receive capability, and mgetty does that. Serial console access doesn’t need that, so I updated the doc (removed two whole steps!). Thanks!

Previous Post:

Next Post: