Raspberry Pi as a serial console server
This is a very brief overview on how to configure a Raspberry Pi as a serial console server using conman and a USB to serial port adapter.
In the early days of Linux, the kernel would crash or a configuration error would occur taking the server off the network. I’d have to go down to the home “server room” fire up the KVM and try and figure out what went wrong with one of the PCs. This is not without cost or limitations:
- Required specialized hardware to switch between consoles (expensive)
- Required 3 custom cables per server (VGA, keyboard, mouse)
- Allowed for full graphics environment
- Limited distance
- Cheaper KVM switches didn’t have a remote capability over the network.
Graphics interface vs text interface
My middle school teacher (when typewriters were still heavily used) gave me sage advice:
Learn to type and you will have a valuable skill to use for the rest of your life.
My corollary is this:
Learn to operate a Linux machine through a text terminal and you will be more productive than most admins in the field.
My console management changed rather suddenly when I acquired a bunch of Sun SPARC servers. They didn’t have standard VGA, keyboard or mouse connectors, breaking my beloved KVM solution. I had to resort to using a null modem cable and Minicom. This limited me to a text based console. Fortunately for me, Linux was designed for complete administration over text. This led to a revelation:
- No custom equipment needed, just serial ports and null modem adapters.
- Only one RS-232 cable was needed per server.
- Only text based consoles
- The serial cable is cheap can max out at about 15 m (50 ft).
- Remote capability (keep reading)
You might be asking, so who cares about a serial console? This is only limiting your options. Not so!
- For Linux machines you can invoke the Magic SysRq key which allows the user to perform various low-level commands regardless of the system’s state. Including reboots!
- For PC machines with a proper BIOS. You can configure your BIOS entirely over the serial console!
- If you still have a Sun SPARC machine, Stop-A allows for similar BIOS access.
- Manage your networking equipment (provided it has a serial port)
- Connect to your serial console in Windows (yep it’s a thing) using Emergency Management Services (EMS). The bootcfg ems command enables the function.
- Raspberry Pi has a serial console too, you can manage multiple Pis with this solution!
- Oh and the usual Linux terminal prompt over serial.
Minicom and other terminal programs proved to be to laborious to manage multiple serial ports, trying to decide which computer was hooked up to ttyS0, ttyS1 etc. Enter a wonderful solution called conman:
- Logging (and optionally timestamping) console output to file
- Connecting to a console in monitor (R/O) or interactive (R/W) mode
- Connecting to multiple consoles for broadcasting (W/O) client output
- Sharing a console session amongst multiple simultaneous clients
- Allowing clients to share or steal console “write” privileges
- Executing Expect scripts across multiple consoles in parallel
- The DB-9 serial cable you use must be a null modem and both ends must be female. How you get there with gender changers etc is up to you. Much of my solution is patched together serial cables I’ve collected over the years.
- The Startec hub gets it’s power from USB. This is a bad thing, loosing power corrupts the serial connection. Highly recommend getting a 5V DC plug to power the unit externally.
- My solution used a 4 port serial hub. If you need more, buy a hub with more serial ports, it’s easy to address each com port on one adapter vs many one port adapters.
- Find one baud rate and stick with it, this will save you a lot of confusion. Most systems will do 115200 by default.
- Don’t use /dev/ttyUSB device names. These can change as devices get plugged/unplugged. Use the serial by-id format: /dev/serial/by-id/usb-FTDI_USB-Serial_Cable_FT3Q2OW0-if00-port0
- If you want to save money and have a bunch of Cat5/6 patch cables lying around there are cheap adapters that convert from RJ45 to DB9. Don’t plug these into your network switch!
- The conman service listens on 127.0.0.1:7890. For remote access and a lot of security I’d recommend SSHing in to this machine, then run the conman client.
Raspberry Pi configuration
- Use any Pi that has a USB port. Any version of Raspberry OS will do fine as well.
- Install the conman from your favorite package manager
- Plug in your serial adapter and make all the proper connections
Edit your /etc/conman.conf file and add a configuration line for each serial port. Your device id’s may be slightly different.
console name="larry" dev="/dev/serial/by-id/usb-FTDI_USB__-__Serial_Cable_FT3Q2OW0-if00-port0" seropts="115200"
console name="moe" dev="/dev/serial/by-id/usb-FTDI_USB__-__Serial_Cable_FT3Q2OW0-if01-port0" seropts="115200"
console name="curly" dev="/dev/serial/by-id/usb-FTDI_USB__-__Serial_Cable_FT3Q2OW0-if02-port0" seropts="115200"
console name="shemp" dev="/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0" seropts="115200"
Ensure conman is set to autostart and launch it’s background task.
systemctl enable conman.service
systemctl start conman.service
Enter your favorite console (Help is the the following key strokes: &h)
I’ve been running this configuration for about 3-4 years now and it’s been rock solid as far as uptime as well as connectivity. To it’s credit conman can do far more than what small piece of functionality I’ve shown. If you’ve got something you’d like to add to help my bit of documentation, feel free and contact me!
Last Updated: 2021-10-24