Saturday, September 6, 2008

Running CentOS Headless

CentOS on a Dell server will behave just fine if you simply unplug the keyboard and monitor but there are times when you really want to see those messages normally sent to the console. Note, some “desktop” machines will completely refuse to boot without a keyboard while others have a BIOS setting that determines the outcome when no keyboard is found. For a server it is unnecessary to have a keyboard and monitor but during times of troubleshooting it can be useful to see the boot messages. These messages can be directed to the serial port and read (via a null modem cable) in a terminal emulator program (minicom on Linux, TeraTerm Pro on Windows). In fact you can even see the grub menu and run a login shell over the serial port.

The setup in CentOS is as follows

  1. Add
    S0:12345:respawn:/sbin/agetty ttyS0 9600 linux

    to /etc/initab. This tells the kernel to a run login shell with the program agetty on ttyS0 (COM1 in Windows language) at a baud rate of 9600 in run levels 1-5.
  2. To allow root to directly login on the serial port add ttyS0 to /etc/securetty (echo "ttyS0" >> /etc/securetty)
  3. Edit /etc/grub/grub.conf - tell grub to use serial port at a certain baud rate and to direct the menu to the serial port instead of the console and also tell the kernel to direct messages to the serial port as well as the console. Also comment out the splashimage line since these graphics will not work over a serial port. Here is a sample grub.conf

    default=0
    timeout=10
    #splashimage=(hd0,0)/grub/splash.xpm.gz
    serial --unit=0 --speed=9600
    terminal --timeout=2 serial console
    hiddenmenu
    title CentOS (2.6.18-8.1.6.el5)
    root (hd0,0)
    kernel /vmlinuz-2.6.18-8.1.6.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet console=tty1 console=ttyS0,9600
    initrd /initrd-2.6.18-8.1.6.el5.img

To use higher baud rates simply change the 3 instances of “9600″ to your desired speed (two instances in grub.conf and one in /etc/inittab).

Setup the terminal emulator with these parameters (shown here with a baud rate of 57600)

No comments: