1

I have a serial console working for a centos7 guest without graphics, which I access with virsh console vm. The guest has the appropriate console=ttyS0,115200n8 kernel command line parameter for it.

Is it possible to configure additional consoles, so that I can say virsh console vm --devname vc1 and get a login prompt?

Instinctively, I was thinking of connecting somehow to the character devices of the guest's first 6 virtual consoles; I've looked into libvirt domain format and virtio-serial as it seemed I should go in that direction, but couldn't get it to work.

Background: We had network issues which took a significant amount of time to fix, during which we needed one team member to work on network issues and the other to continue his work on the VM uninterrupted, thus the need for multiple consoles under no networking.

I am aware that having

<graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'>
  <listen type='address' address='127.0.0.1'/>
</graphics>

enables VNC access with 6 virtual terminals, I was simply wondering if it is possible to have such 6 virtual terminals via the virsh console <domain> --device <device> syntax in any reasonable way, simply because virsh console is far more convenient.

Software:

# cat /etc/fedora-release # host
Fedora release 24 (Twenty Four)
# virsh --version
1.3.3.3
# qemu-system-x86_64 --version
QEMU emulator version 2.6.2 (qemu-2.6.2-8.fc24), Copyright (c) 2003-2008 Fabrice Bellard

# cat /etc/centos-release # guest
CentOS Linux release 7.3.1611 (Core)
  • have you considered screen or tmux in the VM? – cas Aug 3 '17 at 10:09
  • I've added some background info that should explain why I need it the way I described it: no network, one serial console, two guys. – Irfy Aug 3 '17 at 19:14
1

I frequently use multiple "consoles" on my VMs - one for an interactive console showing the boot-up and ending with a login prompt, and another to log all of that to a text file (usually /var/lib/libvirt/consoles/<domain>.log)

I don't know if you can have multiple interactive "consoles" in a VM, but you can add as many serial ports as you like, and then run getty on them in the VM for the login prompt.

These serial ports in the VM can be connected to, e.g., a file, or a socket, or a TCP port on the host that speaks telnet protocol. Easiest to work with is probably a telnet port.

e.g. to add a serial ttyS1 serial port which can be accessed via telnet, save the following XML fragment to /tmp/serial1.xml:

<serial type='tcp'>
  <source mode='bind' host='127.0.0.1' service='4555' tls='no'/>
  <protocol type='telnet'/>
  <target port='1'/>
  <alias name='serial1'/>
</serial>

Then run virsh attach-device --config <domain> /tmp/serial1.xml.

That will add a serial port device to the VM, which will be activated the next time the VM restarts. (There may be some way to add it as a hot-pluggable USB device rather than a non-USB serial port, and avoid the need to restart the VM. I've never cared enough to find out).

After the VM has rebooted, run a getty on the port. e.g. with sysvinit, edit /etc/inittab and run telinit q.

With systemd:

systemctl enable getty@ttyS1.service
systemctl start getty@ttyS1.service

To connect to the VM's serial port from the KVM host, run telnet 127.0.0.1 4555.

You can create as many serial ports as you like, each listening on a different port. Just change the tcp port number (service=), target port, and alias name in the XML fragment.

If you need to access it from another machine, you can make it listen on a different IP address (although you probably want tls='yes' in that case, and use a tls-enabled telnet client to connect, which will require setting up a certificate for qemu to use).

For example, I added two serial ports to a Debian Stretch VM:

First, ttyS1 on localhost:4555

$ telnet localhost 4555
Trying 127.0.0.1...
Connected to localhost.mydomain.
Escape character is '^]'.

Debian GNU/Linux 9 stretch ttyS1

stretch login: 
telnet> quit
Connection closed.

Then ttyS2 on localhost:4556

$ telnet localhost 4556
Trying 127.0.0.1...
Connected to localhost.mydomain.
Escape character is '^]'.

Debian GNU/Linux 9 stretch ttyS2

stretch login: 
telnet> quit
Connection closed.
  • The project where we needed this was cancelled and I never got to test this out. But it seems promising, and reasonable, so I'm tentatively accepting it as the answer. – Irfy Sep 23 '18 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.