1

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.

Lon Kaut
  • 151
  • 5
  • I accomplished something similar to this by passing through a USB serial adapter to a guest, and connecting that serial adapter to the serial console port of the host. I did it that way because I generally have a lot of serial devices, and wanted the guest to be able to connect to them - yet also connect to the host in case of networking failure by simply swapping a cable. It's worth noting that this guest was using GPU and USB passthrough much like you're doing. – Spooler Jul 09 '20 at 17:43
  • Why don't you just ssh in like everyone else? This serial port method will come back to bite you when you can't do simple things like copy files or have curses apps work properly. – Michael Hampton Jul 09 '20 at 17:54
  • @spooler I've done that, and I know it works, however, just looking at the cables and my office, I'd like to "keep it clean". Also, it bothers me having a cable connecting from my computer to my computer. lol. Good suggestion though. – Lon Kaut Jul 09 '20 at 18:30
  • @MichaelHampton , of course I use SSH mainly, but as stated in my post, this serial connection is for when something goes wrong with the network stack. For example, right now, I have this problem when every the host is rebooted, the main interface has no IP address even though it is set for DHCP. Looking to fix this problem as a separate effort altogether. This would be a more practical failsafe if anything happens with network connectivity. – Lon Kaut Jul 09 '20 at 18:33
  • This also, begs the question: "What is the virtual serial port for anyway on a KVM guest?" If I can echo strings between my guest and host, then I should be able to run a getty on it. – Lon Kaut Jul 10 '20 at 16:19

1 Answers1

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/mgetty-pts@.service:

[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.

Majenko
  • 244
  • 1
  • 3