Showing posts with label serial. Show all posts
Showing posts with label serial. Show all posts

2013-12-12

Quickly check serial ports with setserial

When I want to quickly check what serial ports are active on a machine, I use the setserial command:
# which setserial
/usr/bin/setserial
# man setserial
...
# setserial -g /dev/ttyS?
/dev/ttyS0, UART: unknown, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: unknown, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3
/dev/ttyS4, UART: 16550A, Port: 0xf0e0, IRQ: 19
/dev/ttyS5, UART: unknown, Port: 0x0000, IRQ: 0
/dev/ttyS6, UART: unknown, Port: 0x0000, IRQ: 0
/dev/ttyS7, UART: unknown, Port: 0x0000, IRQ: 0
/dev/ttyS8, UART: unknown, Port: 0x0000, IRQ: 0
/dev/ttyS9, UART: unknown, Port: 0x0000, IRQ: 0

This is on my laptop, which of course has no physical serial port. The output of setserial -g shows whatever hardware the kernel thinks it can see. With today's laptops, one typically uses a USB-to-serial adapter. In that case, after connecting the adapter I would do:
# dmesg
... review the last few kernel log messages, which will hopefully confirm 
    that the device was recognized ... 
# setserial -g /dev/ttyUSB?
... hopefully see that the device is present, with UART, Port, and IRQ all 
    set up and ready to use ...

2013-10-04

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.

GRUB


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

GRUB2


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'