Console to Serial
Have you ever needed to connect a dumb terminal (like a Wyse 50) to a Linux host? Do you need to login to a Linux server from a laptop to perform administrative functions, because there is no monitor or keyboard attached to the server? If you are accustomed to administering routers, switches, or firewalls in this manner, then you may be interested in doing the same with some of your GNU/Linux hosts. This HOWTO will explain, step-by-step, how to setup a serial console for Debain, although most of it should apply to other distributions as well.
This is installed on the 2.6 kernel (sarge 2.6.8-2-386 to be exact)
You may need to install additional packages
apt-get install setserial
 Step 1:
Check your system's serial support First, let's make sure that your operating system recognizes serial ports in your hardware. You should make a visual inspection and make sure that you have one or more serial ports on your motherboard or add-in PCI card. Most motherboards have two built-in ports, which are called COM1: and COM2: in the DOS/Windows world. You may need to enable them in BIOS before the OS can recognize them. After your system boots, you can check for serial ports with the following commands:
dmesg | grep tty ttyS0 at 0x03f8 (irq = 4) is a 16550A ttyS1 at 0x02f8 (irq = 3) is a 16550A
setserial -g /dev/ttyS /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4 /dev/ttyS1, UART: 16550A, Port: 0x02f8, IRQ: 3 As you can see, the two built-in serial ports are /dev/ttyS0 and /dev/ttyS1
 Step 2:
Configure your inittab to support serial console logins The /etc/inittab file must be reconfigured to allow serial console logins. You will note that the mingetty daemon is used to listen for virtual consoles (like the 6 that run by default with your keyboard and monitor). You will need to configure agetty or mgetty to listen on the serial ports, because they are capable of responding to input on physical serial ports. In the past, I have used both full-featured gettys. In this document, I will only discuss agetty, since it is already included in the default installation. It handles console/dumb terminal connections as well as dial-in modem connections.
- What is a getty?
- A getty is is a program that opens a tty port, prompts for a login name, and runs the /bin/login command. It is normally invoked by init.
Before you edit /etc/inittab, which is a very important config file, you should make a backup copy:
cp /etc/inittab /etc/inittab.org
The required /etc/inittab changes are highlighted in bold: (you may have to add the lines or uncomment them) id:3:initdefault:
vi /etc/inittab # System initialization. si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1 l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6 # Trap CTRL-ALT-DELETE ca::ctrlaltdel:/sbin/shutdown -t3 -r now pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down" # If power was restored before the shutdown kicked in, cancel it. pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled" # Run gettys in standard runlevels 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 # Run agetty on COM1/ttyS0 and COM2/ttyS1 s0:2345:respawn:/sbin/agetty -L 19200 ttyS0 vt100 s1:2345:respawn:/sbin/agetty -L 19200 ttyS1 vt100 #s1:2345:respawn:/sbin/agetty -L -i 38400 ttyS1 vt100 # Run xdm in runlevel 5 x:5:respawn:/etc/X11/prefdm -nodaemon
agetty options explained:
-L force line to be local line with no need for carrier detect (when you have no modem). -f alternative /etc/issue file. This is what a user sees at the login prompt. -i do not display any messages at the login prompt. 9600 serial line rate in bps. Set this to your dumb terminal or terminal emulator line rate. ttyS0 this is the serial port identifier. vt100 is the terminal emulation. You can use others, but VT100 is the most common or "standard". Another widely used termial type is VT102. Possible serial line rates (sometimes called baud rates) for the 16550A UART: 110 bps 300 bps 1200 bps 2400 bps 4800 bps 9600 bps 19,200 bps 38,400 bps 57,600 bps 115,200 bps I have tried all of these line rates. 9600 bps is generally O.K., and is a very common setting for networking hardware. 38,400 bps is the speed of the standard Linux console, so it is my second choice. If your dumb terminal or terminal emulator cannot handle 38,400 bps, then try 19,200 bps: it is reasonably speedy and you will not be annoyed.
Now, you must activate the changes that you made in /etc/inittab. This is done with the following command, which forces the init process to re-read the configuration file:
Now, let's make sure that the agetty process is listening on the serial ports:
ps -ef | grep getty root 958 1 0 Dec13 ttyS0 00:00:00 /sbin/agetty -L 19200 ttyS0 vt100 root 1427 1 0 Dec13 ttyS1 00:00:00 /sbin/agetty -L 38400 ttyS1 vt100
 Step 3:
Test serial port login Terminal settings:
19200, N, 8, 1. Terminal emulation should be set to VT100 or VT102. Turn flow control off.
Cable: To connect a laptop to the serial port on the Linux host, you need to have a null-modem cable. The purpose of a null-modem cable is to permit two RS-232 DTE devices to communicate with each other without modems between them. While you can construct this yourself, a good, sturdy manufactured null-modem cable is inexpensive and will last longer.
Note: If you want to be able to login via serial console as the root user, you may need to edit the /etc/securetty config file. The entries to add are highlighted in bold: Beow is just a sample this file can be huge, simply add ttyS0 and ttyS1 below the "console".
console ttyS0 ttyS1 tty1
 Additional Notes
 Change baud rate:
If you want to change the baud rate or some other agetty setting, you will need to perform these 3 steps:
1. Modify the /etc/inittab configuration file 2. Activate the config change by forcing init to re-read the config file (ie: killall getty) 3. Restart the agetty daemons (ie: init q)
 Configure serial port as THE system console:
You can use options in /boot/grub/menu.lst to redirect console output to one of your serial ports. This can be handy if you do not have a keyboard or monitor available for the Linux host in question. You can also see all of the bootup and shutdown messages from your terminal.
In this example, we will make the /dev/ttyS0 port be the console. The text to add to the config file is highlighted in bold:
title Debian GNU/Linux, kernel 2.6.8-2-386 root (hd0,0) kernel /vmlinuz-2.6.8-2-386 root=/dev/hda2 ro console=ttyS0,19200 initrd /initrd.img-2.6.8-2-386 savedefault boot
Now, if you drop your system into single user mode with the "init 1" command, you will still be able to administer the system from your serial-connected terminal. No monitor or keyboard is required!
 RedHat distro Warning!:
The kudzu hardware detection program may "choke" on boot when the serial port becomes the console, instead of the video adapter. To remedy this situation, you should disable kudzu (assuming that your hardware is configured properly and won't be changing). This is how you would do that:
You should also know how to break into the Grub bootloader during system startup and edit the kernel line. By deleting the console argument from the kernel line, you can boot the system with the standard console, which uses the video card and attached keyboard. You have been warned!
 Finale Notes
Now, you should be able to login from the serial ports on your GNU/Linux host. This could be useful for maintenance or for serving a whole room full of dumb terminals. In the future, I will investigate a PCI multiport serial card in the latter role.
Special thanks to Van Emery (http://www.vanemery.com/Linux/Serial/serial-console.html) for his great write-up of RedHat 9 systems
Other noteable sites: