0

What are the ways of accessing qemu monitor inside the guest i.e VM other than pressing Ctrl+Alt+2 buttons? Is there any way we can access the qemu monitor using telnet from the guest?

1 Answer 1

0

Yes, but please keep in mind that access to QEMU monitor equals access to host

Many of the commands exposed will instruct QEMU to access content on the host file system and/or trigger spawning of external processes.

Thus think about encryption, authentication, see https://www.berrange.com/posts/2016/08/16/improving-qemu-security-part-6-tls-support-for-character-devices/. Thus it allows only TLS auth.

qemu-system-x86_64 -chardev socket,help | sed 's/^/    /'
chardev options:
  abstract=<bool (on/off)>
  append=<bool (on/off)>
  backend=<str>
  chardev=<str>
  cols=<num>
  debug=<num>
  delay=<bool (on/off)>
  fd=<str>
  height=<num>
  host=<str>
  ipv4=<bool (on/off)>
  ipv6=<bool (on/off)>
  localaddr=<str>
  localport=<str>
  logappend=<bool (on/off)>
  logfile=<str>
  mux=<bool (on/off)>
  name=<str>
  path=<str>
  port=<str>
  reconnect=<num>
  rows=<num>
  server=<bool (on/off)>
  signal=<bool (on/off)>
  size=<size>
  telnet=<bool (on/off)>
  tight=<bool (on/off)>
  tls-authz=<str>
  tls-creds=<str>
  tn3270=<bool (on/off)>
  to=<num>
  wait=<bool (on/off)>
  websocket=<bool (on/off)>
  width=<num>

If you want to have a multi-user access to QEMU monitor, probably think about using conserver (https://www.conserver.com/) in from of individial QEMU monitor consoles, this way you can define user/group etc...

See also: https://qemu.readthedocs.io/en/latest/system/invocation.html#hxtool-6 or https://documentation.suse.com/sles/15-SP2/html/SLES-all/cha-qemu-monitor.html

Quick example, display via GTK GUI, using userspace networking, monitor TCP port binded 192.168.1.194:1234.

qemu-system-x86_64 \
  -mon chardev=monitor0 \
  -chardev socket,id=monitor0,server=on,wait=off,telnet=on,host=192.168.1.194,port=1234,ipv4=on,ipv6=off \
  -netdev user,id=network1,ipv6=off \
  -device e1000,netdev=network1 \
  -cdrom /tmp/alpine-virt-3.13.3-x86_64.iso \
  -display gtk

And access the monitor TCP from Alpine via netcat (yes, plaintext, should be TLS!, this is just an example).

nc 192.168.1.194 1234
QEMU 5.2.0 monitor - type 'help' for more information
(qemu) info version
5.2.0openSUSE Tumbleweed
(qemu) info status
VM status: running
(qemu) info block
ide1-cd0 (#block192): /tmp/alpine-virt-3.13.3-x86_64.iso (raw, read-only)
    Attached to:      /machine/unattached/device[22]
    Removable device: locked, tray closed
    Cache mode:       writeback

floppy0: [not inserted]
    Attached to:      /machine/unattached/device[16]
    Removable device: not locked, tray closed

sd0: [not inserted]
    Removable device: not locked, tray closed
6
  • Thanks for letting me know about the security issue. But I haven't found any command line options which lets me connect to qemu monitor from the guest, so can you please help with that. Mar 29, 2021 at 16:29
  • You seem not to understood it. You must change how you run your QEMU VM, ie, you must redefine device for monitor console - use -chardev socket,..., bind it to TCP for example, then you will be able to access it over TCP/IP (ie. even from your VM if your networking is configured to do so). Without such change it cannot work, default is that QEMU monitor is multiplexed into display output (eg. SPICE, GTK, SDL...).
    – Jiri B
    Mar 29, 2021 at 16:32
  • Yes I get your point and I have tried with the chardev option to bind the qemu monitor but I am not able to do it. Can you please provide how the qemu monitor binding can be done to with chardev option so that I can access it. Because I am little bit confused as the chardev option lets us create some file or socket in the host which can be accessed after the vm creation but I am not sure it can be accessed inside vm. Please bear with me as I am a biginner in this and please correct me if I understood anything wrong. Thanks for your help. Mar 29, 2021 at 16:45
  • But we neither know your QEMU command line nor your network setup. If you cannot access host from the VM, then you have to validate your network setup. What do you use? Bridge, MACVTAP, user,... At least you have to share more details (ps -axo args | grep '[q]emu'). If you are a beginner, maybe you should switch for libvirt and virt-manager.
    – Jiri B
    Mar 29, 2021 at 16:52
  • I am using qemu comamnd line options to create a windows vm from which I should be able to access the qemu monitor. I want to know how can we access the monitor using the chardev and tcp options to make it work. Like there is no problem while accessing host from vm its just that i don't know how to to it for the qemu monitor. Mar 29, 2021 at 17:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .