The switch to systemd from init has been wonderful in the world of *nix. Here’s how you could quickly get a getty running on a serial ttyUSB device in the old system:
- Create a
/etc/init/and fill it with
start on stoppedand
RUNLEVELinformation, followed by an
execstatement, that reads something like:
/sbin/getty -L 9600 ttyUSB0 vt102. (see addendum)
- Tell init to pick it up, by adding to
sudo start ttyUSB0.
(Warning: this is the way I do it, which naturally means there’s something ugly about it!).
Here’s how you’d do this through systemd:
- Modify the system-file in
/lib/systemd/system/serial-getty@.serviceto change the baud-rate to what you need (technically you shouldn’t do this, but we need to get moving quick).
ExecStart:-/sbin/agetty 9600 %I $TERMinstead of
--keep-baud. This will tell it to use a specific baudrate as opposed to scanning through a list.
- The systemctl daemon needs to know that you meddled with the file (which you shouldn’t have, you know.. but we did anyway, spilt milk). Do:
sudo systemctl daemon-relaod
- Fun part: just enable this setup once, and systemd will remember over reboots:
sudo systemctl enable serial-getty@ttyUSB0
Of course you can
stopthis. Apparently it is not smart enough to ignore you when you start it twice. The way it enables is by creating a symlink from
/lib/systemd/system/serial-getty@.service, in case the command doesn’t work (note that the latter is the file you edited previously). Feel free to explain this to me after reading more on this RHEL KB. :)
My old setup (using
init) had this inside the
start on stopped rc RUNLEVEL=
stop on runlevel [!2345]
exec /sbin/getty -L 9600 ttyUSB0 vt102
Ooh, how do you know if you’re using systemd or init? If you’re system is up, then PID 1 should tell you :)