Can you start a getty on /dev/pts/x ? Want a serial connection between my Linux KVM server host and Windows Guest

Here's what I have going on:
I have a Debian server running several services in Docker and a couple in KVM.
One of the KVM hosts is a Windows 10 VM that I actually use as a desktop by using PCI passthrough of GPU, USB and some other things.
On the Windows VM, I also have a virtual serial device which attaches to /dev/pts/1

If I fire up Putty on the windows VM and attach to Com1, I can echo "something" > /dev/pts/1 on my host server and it shows up in my putty window. I can also cat /dev/pts/1 and type data into my putty window and it shows up in the cat output.

What I'm trying to do: I want a getty to run on /dev/pts/1 so that I can simply open a putty window and get the console of my host device.

This mainly came up when I've noticed that I've done something to the network stack on my host device and couldn't ssh to it. I've tried just running agetty -s 115200 -t 600 /dev/pts/1 linux which does nothing. It seems /etc/inittab no longer exists.
I've considered just adding a separate vnic attached directly to my host, but I just don't want to do that.


Solution 1:

I have found that agetty, the default terminal login handler, doesn't like PTS devices. However mgetty works fine with it. It's a little tricky to set up though.

First install mgetty - on Ubuntu that's sudo apt-get install mgetty.

Next you need to set up a systemd unit file for it. I've made one that specifically works on /dev/pts files. Save this as /lib/systemd/system/[email protected]:

[Unit]
Description=Smart Modem Getty(mgetty)
Documentation=man:mgetty(8)
Requires=systemd-udev-settle.service
After=systemd-udev-settle.service

[Service]
Type=simple
ExecStart=/usr/sbin/mgetty -r /dev/pts/%I
Restart=always
PIDFile=/var/run/mgetty.pid.pts%I

[Install]
WantedBy=multi-user.target

And reload the systemd configuration to pick up the changes:

sudo systemctl daemon-reload

Next you need to set up the terminal types for any incoming connections. This is done in /etc/mgetty/mgetty.config. For each pts you need to add:

port pts/2
    term vt220

Change the /2 to whatever pts you are working with, and select the terminal type appropriately.

Finally enable and start the service for your chosen pty:

sudo systemctl enable mgetty-pts@2
sudo systemctl start mgetty-pts@2

You should now have a login available on the virtual machine's serial. You can start as many mgetty sessions as you like on different pts devices by specifying a different pts number in the service enable/start. For /dev/pts/3 it would be:

sudo systemctl enable mgetty-pts@3
sudo systemctl start mgetty-pts@3

So just make sure you use the right numbers throughout.