How to start agetty on a serial port that is not the primary console
Environment
Red Hat Enterprise Linux 6
Issue
For RHEL6, upstart (the init process) starts an agetty process automatically if the primary console is the serial port (recall that the last console= parameter is the primary).
If we want to start agetty on a serial port that is not the primary console, How should we do?
Resolution
create a new /etc/init/serial-ttyS1.conf file with the following contents:
```
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [S016]
respawn
exec /sbin/agetty /dev/ttyS1 115200 vt100-nav
```
-
Then start the new
agettyby rebooting or by running[root@localhost ~]# initctl start serial-ttyS1 -
Note: if the keyboard is not working correctly on the new agetty, you may need to remove
console=ttyS1from the kernel parameters.-
Some background information:
-
As the system boots, it starts udev to handle hardware devices. The
/lib/udev/rules.d/10-console.rulesfile tells udev to check a number of devices, including /dev/console, and run the /lib/udev/console_check helper program against each device:# Console initialization - keyboard, font, etc. KERNEL=="tty0", RUN+="/lib/udev/console_init %k" # Check and set up serial and serial-like consoles if necessary KERNEL=="console", RUN+="/lib/udev/console_check %k" KERNEL=="ttySG*", RUN+="/lib/udev/console_check %k" KERNEL=="xvc*", RUN+="/lib/udev/console_check %k" KERNEL=="hvsi*", RUN+="/lib/udev/console_check %k" KERNEL=="hvc*", RUN+="/lib/udev/console_check %k" -
If console_check determines that
/dev/consoleis a serial console (by running some ioctl() system calls on it), then it runs this command:/sbin/initctl emit --no-wait fedora.serial-console-available DEV=ttyS0 SPEED=115200 -
This command sends a
fedora.serial-console-availableevent to the init daemon. The init daemon is configured for this event by/etc/init/serial.conf:start on fedora.serial-console-available DEV=* and stopped rc RUNLEVEL=[2345] stop on runlevel [S016] instance $DEV respawn pre-start exec /sbin/securetty $DEV exec /sbin/agetty /dev/$DEV $SPEED vt100-nav -
The init daemon launches agetty by running the command from the exec line in
serial.conf:/sbin/agetty /dev/ttyS1 115200 vt100-nav -
And this shows the login prompt on the serial console.
-
-
-
To check the status of the serial console, use the initctl command to query the init daemon's jobs:
[root@localhost ~]# initctl list | grep serial serial (ttyS0) start/running, process 1254 -
Or:
[root@localhost ~]# initctl status serial DEV=ttyS0 serial (ttyS0) start/running, process 1254 -
Note the
DEV=ttyS1parameter above. Without this parameter,initctlreturns a not-very-clear error message:[root@localhost ~]# initctl status serial initctl: Unknown parameter: DEV -
The DEV=ttyS1 parameter is necessary because of the job definition in
/etc/init/serial.confas shown above.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.