Some Bits: Nelson's log

Linux serial console in 2025

I wanted remote access to my Linux PC and decided to try a very old fashioned idea, a serial console. Normally a Linux PC’s console is a keyboard and video device. But it can also just be a serial device. Either an old school DB9 connector on an ancient PC or some modern thing plugged in with a serial connection. Then you need a second device to act as a serial terminal.

In theory the serial device is simpler and is more likely to work even if the network isn’t working. In particular the Linux PC’s kernel is managing the serial console and so as long as Linux is operating, there’s a good chance that serial connection will be.

I tried using a Raspberry Pi Zero 2 W for the terminal, plugged in to my Linux PC via a USB cable.

I got this sort of working and then quit. I realized there’s few cases where a serial connection will really help. Ie: the Linux machine is up but its networking is down, however the whole LAN is still up. It happened to me this week! But I’m going to look for a full IP KVM solution so I can do things even if Linux is busted.

Update: this set of docs may be useful.

Serial connection: USB Gadget / On-the-Go

The first complication: who has a real serial port anymore? I haven’t seen a DB9 in years. It’s all USB ports. And you can’t just plug a USB cable in between two computers because they are both in host mode, not device mode.

There’s hardware hacks for true serial. Plenty of USB-to-Serial adapters out there that give you a DB9 (or an RJ45 with serial). Also RPi hardware has UARTs that you can use with the GPIO pins, hack up your own serial port. All that conversion seemed du mb to me, particularly since I’d need two adapters on either end.

The hack I’m using is OTG / Gadget mode on my RPi Zero 2 W. The micro USB port is an OTG port, you can plug that in directly with a cable to a PC’s USB A socket. The PC is a USB host, the OTG port is a USB device. This actually works! No special cable or adapter needed, just an ordinary USB cable between the two computers. (Mine was male Micro-B to male A.) However, it still takes a lot of doing to get it going.

Getting serial working manually

Here’s how I got a serial connection working manually in Linux.

On the RPi Zero 2 W: steps to enable OTG mode and use the USB as a serial port

  • enable dtoverlay=dwc2 in /boot/firmware/config.txt and reboot
  • modprobe dwc2
  • modprobe g_serial
  • verify there’s a new /dev/ttyGS0 on the RPi

On the Linux server (after the modprobe on the RPi)

  • lsusb and verify there’s something named “Linux-USB Serial Gadget”
  • Verify there’s a new /dev/ttyACM0
  • Run getty -L 9600 ttyACM0 vt100 to create a login prompt on the serial port

Back on the RPi, connect to the Linux server.

This all works! I can now connect from one machine to another via a serial interface.

Proper server setup

The next big step is getting the server to run that console all the time. The simple way is to add ttyACM0 to the list of things that systemd should run a getty on. But that doesn’t catch the kernel. What you really want is to modify the Linux kernel command line to treat this serial port as a second terminal, not just for getty but also for kernel errors, etc. I didn’t do this step.

Proper terminal setup: ConsolePi

Any old serial terminal would work and that screen hack I tried is actually not bad if you only have a single server to connect to. But there’s a fancy OS purpose-built for being a serial terminal with a lot of nice extra features: ConsolePi. The key component is ser2net, that’s a Linux service that proxies all serial ports to TCP network ports. Then ConsolePi wraps that up in a nice UI.

I tinkered with it a bit but didn’t get it working. Honestly I found the docs confusing and was running out of patience. The main snag I ran into is ser2net doesn’t seem to find devices named ttyGS* by default, or at least I couldn’t figure it out. I’m sure that’s hackable.

Update: Conserver may be worth a look as a different app for monitoring serial ports.