Create serial console on plug in USB serial device

consolekernelserial port

I have a CentOS 7 headless system with no serial ports. I sometimes want to access the server using a serial cable, so I plug in a USB serial cable (to my laptop's serial port) but I can't get a console/BASH from the connection.

Is there something I have to do to tell the kernel to always create a serial console on appearance of a USB serial port?

Best Answer

EDIT: This won't work if you have a recent udev version, because udev prevents you from starting long-lived background processes in RUN scripts. You may or may not be able to get around this by prefixing the getty command with setsid but in any case it's discouraged if not outright disallowed. If you have a system which uses systemd then there is another way to achieve this, which I hope someone will supply with another answer. In the meantime, I'm leaving this answer here in case it works for you.


You cannot use a USB serial port as a console because USB is initialized too late in the boot sequence, long after the console needs to be working.

You can run getty on a USB serial port to allow you to log in and get a shell session on that port, but it will not be the system's console.

To get getty to start automatically, try this udev rule:

ACTION=="add", SUBSYSTEM=="tty", ENV{ID_BUS}=="usb", RUN+="/usr/local/sbin/usbrungetty"

Put that in a rules file in /etc/udev/rules.d and then create this executable script /usr/local/sbin/usbrungetty:

#!/bin/sh

/sbin/getty -L "$DEVNAME" 115200 vt102 &
Related Question