Enabling Linux Serial Console with a Script
There are a number of steps needed to properly enable a serial console on Linux. You have to make sure that the kernel uses it for logging, make sure a getty runs on it, make sure that kudzu doesn’t mess with your terminal, and finally make sure that root logins are allowed on it. To make these steps simpler, I have written a script to perform all the steps automatically. This script was written and tested on Red Hat Enterprise Linux 4 (RHEL4) but it could easily be modified for other Linux distributions.
Activate Serial Console script
(download script here: ActivateSerialConsole.tar)
#!/bin/bash # # ActivateSerialConsole - a script for Red Hat Enterprise Linux # # See if ttyS0 is already present in grub, if it is not there, # then add it to the kernel command line. fgrep -q ttyS0 /boot/grub/grub.conf if [ $? != 0 ] ; then echo Modifying grub.conf... sed -i-ORIGINAL 's/^.*vmlinuz.*$/& console=tty0 console=ttyS0,115200/g' /boot/grub/grub.conf fi # Check kudzu for the SAFE entry, add it if its not there already. fgrep -q SAFE=yes /etc/sysconfig/kudzu if [ $? != 0 ] ; then echo Modifying kudzu... echo SAFE=yes >> /etc/sysconfig/kudzu fi # Make sure we start a getty on ttyS0 fgrep -q ttyS0 /etc/inittab if [ $? != 0 ] ; then echo Modifying inittab... cat >> /etc/inittab << END_OF_TEXT # Serial Console S0:12345:respawn:/sbin/agetty ttyS0 115200 vt100 END_OF_TEXT kill -HUP 1 fi # Make sure that ttyS0 is added to securetty so we can login as root fgrep -q ttyS0 /etc/securetty if [ $? != 0 ] ; then echo Modifying securetty... echo ttyS0 >> /etc/securetty fi


January 29th, 2010 at 11:29 am
Take a look at grubby(8) for safer editing of grub.conf
January 29th, 2010 at 11:52 am
Thanks for the tip. Grubby looks pretty cool — I never knew it existed!