Enabling Serial Console on Ubuntu
This is a brief blog post for other people like me (or me from the future when I need to reinstall my distro again) who might want to set up a serial console for their old computers (or for backup connections on a server} on a more modern Linux system.
In my case, I wanted to connect a TRS-80 Model 100 to my laptop, which was running Xubuntu at the time. The most clear guide for this was written in 2008 and was for Ubuntu 6. Needless to say, things have changed since then.
The first thing to do was to make sure the two machines could talk to each other at all. I have them connected via a USB-RS232 DB9 cable, with a null modem connector in the middle, and a DB9-DB25 converter.
In order to get a stable connection with all the text that Ubuntu likes to throw through the terminal, I found that 600 baud was the maximum speed. If you're only sending to the modern computer, 9600 baud works quite nicely.
The connection string for 600 baud is:
48n1e
Taking this apart, this sets the speed to 4 (600baud), number of bits to 8, parity off, 1 stop bit, and XONXOFF flow control.
To confirm connection on the modern computer, you can use the command screen /dev/ttyUSB0 600, substituting ttyUSB0 for whatever your serial solution is.
With that confirmed, it's time to set up the login session, since it's a lot more fun to use the Model T to act as a real, honest-to-goodness terminal for the supercomputer it's connected to.
There are 4 commands required to set up the TTY console. stty to set the getty up that will give us the actual session, two GRUB-related commands to enable it at boot, and a call to systemctl to start up the getty after.
The stty command I found worked best (based on the article here) was:
(sudo) stty -F /dev/ttyUSB0 speed 600 cols 40 rows 13 erase ^H ixon ofdel
Essentially, I made the backspace match, set the baud rate, and set the columns and rows, as well as enabled software flow control.
Next is the GRUB config. It's described in more depth here, but essentially you add “console=ttyUSB0” to the end of the “GRUB_CMDLINE_LINUX” string. You can (probably) find your default GRUB config at /etc/sysconfig/grub.
Next, run update-grub to update GRUB.
Finally, use the following to start the getty:
(sudo) systemctl start getty@ttyUSB0
And that's it! You should now be able to start a terminal session from your terminal when plugged in!
Some extra notes for usability:
You probably want to change your bash prompt to something short (“$>” is mine, and the Model 100 will occasionally add more characters)
Likely, some of the control codes your modern computer will throw at the terminal won't register. I just ignore those, but if you find an easy addition to the stty command (or elsewhere), please let me know!