Friday, October 4, 2013

Enable serial console

When running servers, it can be very useful to enable a serial console. Accomplishing this entails:
  1. Telling the kernel that we want a serial console
  2. Telling init that we want a login prompt on the serial device

Kernel command line

It is possible to specify a serial console using the console parameter on the kernel command line. The kernel receives its command line parameters from the bootloader (GRUB or GRUB2). Here's how to set that up:

System-wide default

Regardless of whether I'm running and older SLE11 machine with GRUB or a newer openSUSE or SLE12 machine with GRUB2, first I edit /etc/sysconfig/bootloader to modify the DEFAULT_APPEND setting by adding onsole=tty0 console=ttyS0,115200n8 to whatever is already there:
change, e.g., DEFAULT_APPEND="   splash=silent quiet showopts" to

DEFAULT_APPEND="   splash=silent quiet showopts console=tty0 console=ttyS0,115200n8"

Now, this value will only ever be used for future kernels. To enable the serial console right from the next boot, I will need to edit the existing kernel command lines in the GRUB configuration file. How to do that depends on whether my system is using GRUB or GRUB2.


For GRUB v.1 machines, the file is /boot/grub/menu.lst. Add the following to the end of each kernel command line:
console=tty0 console=ttyS0,115200n8


For GRUB v.2 machines, edit the file /etc/default/grub and add that text to the end of the GRUB_CMDLINE_LINUX_DEFAULT option and then do:
# grub2-mkconfig -o /boot/grub2/grub.cfg

Login prompt

And to get login prompt on the serial console, enable ttyS0 in inittab like this:
tim:~ # grep ttyS0 /etc/inittab
S0:12345:respawn:/sbin/agetty -L 115200 ttyS0 vt102

And of course add ttyS0 to /etc/securetty and run 'init q'

No comments:

Post a Comment