Problem solve Get help with specific problems with your technologies, process and projects.

System panic: Get a serial console log

How to create a serial console log of a system panic.

You'll need a null modem cable. Sometimes it's called a serial laplink cable. It should have 9-pin female connectors on both ends of the cable. The pinout will need to be:

You'll need another server to act as the logging machine. Any machine will do as long as it has a serial port and won't be rebooted more often than the server you're monitoring. If it runs Linux, you will need the application minicom. If it runs Windows, you'll need HyperTerm.

On the machine that has the problem, add "console=tty0 console=ttyS0,115200n8" to the kernel command line in /boot/grub/menu.lst or /etc/lilo.conf depending on your boot loader. (If you're using lilo, don't forget to run "lilo" to copy the config changes to the boot manager.) You may also want to remove "rhgb" which turns on "Red Hat Graphical Boot" and "quiet" which reduces the kernel messages during startup. Leave any other options on the line.

For example, in /boot/grub/menu.lst this:

title Fedora Core (2.6.5-1.358)
        root (hd0,0)
        kernel /vmlinuz-2.6.5-1.358 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.5-1.358.img


title Fedora Core w/Serial Console (2.6.5-1.358)
        root (hd0,0)
        kernel /vmlinuz-2.6.5-1.358 ro root=LABEL=/ console=tty0 console=ttyS0,115200n8
        initrd /initrd-2.6.5-1.358.img

Specifying "console=" multiple times causes kernel output (printk) to be mirrored to all devices listed. The last device mentioned will be used as /dev/console which is where syslog and the /etc/init.d startup scripts send their output. The typical keyboard and monitor are tty0. The first serial port is ttyS0 (COM1), the second serial port is ttyS1 (COM2). You can use either one. 115200 is the baud rate for the serial port. You can set it slower if you need to. Other popular baud rates are 9600, 19200, 38400 and 57600.

If you boot with the above kernel command line, Red Hat will generally detect this and prompt you to configure serial console for login. If not, do the following to enable login on the serial port.

Add the following lines to /etc/inittab:

# Serial console login
S0:2345:respawn:/sbin/agetty -L ttyS0 115200

Change "S0" to "S1" in two places on the line if you're using ttyS1 as your console. Change "115200" to match your baud rate if you changed it on the kernel command line.

Allow root login on this new port by adding "ttyS0" and "ttyS1" to /etc/securettys.

The system process named "init" manages logins and needs to be told to reread the /etc/inittab file. There are many ways to do this -- "telinit q" is one.

That completes the setup of the machine to be monitored.

Verify the setup

To verify your setup, you'll need the program "minicom" on the monitoring machine. If you have a Windows machine available, you can also use HyperTerm to record the kernel output.

1. Start by running "minicom -s -o" and then select "Serial Port Setup." Configure the "A - Serial device," "E - Bps/Par/Bits" and set both hardware (F) and software (G) flow control to off. Press return to get back to the main config menu. Select "Modem and Dialing" and delete the "A - Init string," "B - Reset string" and "K - Hang up string" since there is no modem in this situation. Return to the main menu and "Save setup as..." You should name the config to match the name of the serial port (eg. ttyS0). Exit minicom.

2. Next, start minicom using the config you saved. Run "minicom ttyS0" and after it starts, press "return" a couple of times. If everything is working, you should get a "login:" prompt from your monitored system.

3. Tell minicom to start logging everything by pressing "CTRL-A" and then "L" Select a filename for the log. Leave minicom running.

4. Try rebooting the target system. You should see the kernel messages and init.d scripts as the system boots.

5. Now duplicate the problem, or wait for the kernel panic. The kernel messages will be captured to the log file.

6. To close the log file, press "CTRL-A" and "L" again. Choose "Close" to end the existing log file.

You can start another log file by doing "CTRL-A" and "L" again. Be sure to use a different name.

Dig Deeper on Linux servers