Tech Tip: Setup Your Linux Server to Use a Serial Console

July 7th, 2009 by Josh Hiner in

Your rating: None Average: 4.4 (11 votes)

Do you have a linux server without a keyboard or monitor? Need to administer the server on-site but don't want to lug over a monitor and keyboard (or kvm)? Then setup the server to output the console to a serial port and use screen/minicom (Hyperterminal or putty in Windows) to console into the server over a serial cable.

To set this up, you need to edit /etc/inittab to tell it to start a terminal on the serial port for the console. If you want to see the kernel load and see all the services start then you also need to configure grub to use the serial port as well.

Edit /etc/inittab and add the line starting with "co" to the file (substitute the device name of your serial port for ttyS0 below):

co:2345:respawn:/sbin/agetty ttyS0 57600 vt100-nav  # ADD THIS LINE
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

To watch the kernel load (and all the services) you must configure grub to enable the console option in the kernel on boot. Edit /boot/grub.conf and add the "serial" and "terminal" lines below, and modify the "kernel" line to include the console specification:

serial --unit=0 --speed=57600
terminal --timeout=5 serial console
title CentOS (2.6.9-55.0.2.EL)
   root (hd1,0)
   kernel /vmlinuz-2.6.9-55.0.2.EL ro root=/dev/VolGroup00/LogVol00 console=ttyS0,57600n8
   initrd /initrd-2.6.9-55.0.2.EL.img

To connect to the server just hook a serial cable from your laptop to the server. Set the speed to 57600, no parity and 8bits. Boot up the server, you should see kernel output, services load, and finally a login prompt. After you disconnect you can easily re-connect and log in: just fire up your terminal emulator, connect your serial cable, hit enter a few times and you should get a prompt to log in.

__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous's picture

It'd be really slick if

On July 13th, 2009 Anonymous (not verified) says:

It'd be really slick if there exists a serial-to-USB cable. I'd love to be able to plug in when there's a problem that takes the system off the network, but most laptops these days don't have a serial port...

Paul B's picture

USB to Serial

On July 31st, 2009 Paul B (not verified) says:

"It'd be really slick if there exists a serial-to-USB cable. I'd love to be able to plug in when there's a problem that takes the system off the network, but most laptops these days don't have a serial port..."

There are many USB to serial connectors on the market.

Google is your friend.

Here is one of the better connectors:

http://www.datapro.net/products/usb-to-rs232-serial-convertor.html

- Paul

ran's picture

I recommend to set up line

On July 8th, 2009 ran (not verified) says:

I recommend to set up line speed not 57600, but 9600
This number is more typical in many situation of same using of serial port:
Cisco, Solaris ...

Anonymous's picture

Cable Length

On July 8th, 2009 Anonymous (not verified) says:

This article omits mentioning maximum serial cable lengths.

The length of serial cable will determine the max communication speed. ... Just in case someone was thinking of running a serial cable from one room to another. (Google serial cable lengths and speed for more info.)

And, for those curious how some can get a copy/past of those nasty kernel oops, well, this is how they did it.

(This is also commonly used for debugging LinuxBios/Coreboot project. ;-)

This is probably one of the coolest things I've seen that can be done with Linux vs Windows.

thogarty's picture

remembering sun serial console

On July 7th, 2009 thogarty says:

for those who have worked with sun hardware, serial console is enabled at a lower level allowing the OS to be installed or boot firmware settings (bios in pc speak) to be modified using a serial terminal.

does anyone know of pc hardware that supports a serial console before the OS is loaded like this? it's similar to the way network equipment can be configured (cisco, etc).

thanks for the tip, indeed another handy way to access systems in the data center or elsewhere where a gui console is not easily available.

Frederic Roussel's picture

Will depend on your BIOS.

On July 7th, 2009 Frederic Roussel (not verified) says:

Will depend on your BIOS. Some server BIOSes allow to be configured to have console to serial instead of VGA.

Now, if you really badly want it, there is some really cool, though not totally obvious to deploy, replacement for the VGA console in the form of a BIOS extension:
http://code.google.com/p/sgabios/

-frr

blak111's picture

Very Cool

On July 7th, 2009 blak111 (not verified) says:

I really like this tip. I have a lot of headless servers that I have to bring a monitor to when something goes bad (usually a mistake on my part). I didn't realize how easy it was to set this up.
Thanks!

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.







Read this issue