Use Qemu Monitor

Accessing the monitor

This segment of the guide describes how to access the Qemu monitor.

Monitor

How does a person know when they are accessing the monitor? Well, the monitor has a text prompt. The prompt may look like this:

QEMU #.#.# monitor - type 'help' for more information
(qemu)

The method of how to access the monitor can depend a bit on how Qemu was started. Let's start by take a look at the process recommended by this guide, which is used by this script.

Using Telnet

With the script that this guide recommend, there is a -monitor parameter that uses the ${VMNUM} parameter. The easiest way to see the actual TCP port number, used by the Qemu monitor, may be to check the command line. (To see that Qemu command line, jsut review and follow the steps just described earlier: check if Qemu is running. Then, look to see if a -monitor command is specified by that command line.

For example, if the Qemu command line uses: “ -monitor telnet:127.0.0.1:7211”, then the command to run would be:

telnet 127.0.0.1 7211

(That example probably will require customization. Each Qemu virtual machine has its own monitor, and so a system that runs multiple virtual machines will have multiple monitors. You'll need to use the correct monitor to affect a specific virtual machine. The script file that is used by this guide uses ${VMNUM} as part of the Telnet server's TCP port number. So, the above example will need to be adjusted.)

Note that the telnet command line does not use a colon.

Note: In the opinion of the author of this guide, the Qemu documentation for this option may be a bit difficult to notice. The Qemu documentation: “Invocation” section has a sub-section for “-monitor dev”. Also, an earlier section of the documentation (not much earlier) discusses the “-serial dev” option. It is in the section about the “-serial dev” that the “telnet:” option gets discussed.

Note: The Telnet server is only minimally responsive until the NIC startup configuration scripts complete. If there is a NIC startup configuration script that takes some time to perform, then Qemu may accept the Telnet connection, but then not interact (by showing a prompt) until the NIC startup configuration scripts complete. One way to verify if this is happening is to use ps to see if the NIC configuration script is running. If so, then simply waiting for the NIC configuration script will result in the Telnet server eventually shoiwng the NIC startup configuration script. (That, of course, only happens if the NIC startup configuration script completes successfully. If the NIC startup configuration script returns a non-zero error code, then Qemu will quit. In that case, the Telnet session will be closed.)

Using TCP

As a quick side note, another alternative is to use “ -monitor tcp:netAddress:TCPportNum”, e.g.: “ -monitor tcp:127.0.0.1:7211”. In theory, that ought to work since using Telnet is quite similar to just using a TCP connection. (That is discussed further on the page about the Telnet protocol, in the section called “Differences between Telnet and TCP.)

In practice, that has been known to work just fine. In fact, using “ -monitor tcp:” has the advantage of working with older versions of Qemu, because that “ -monitor tcp:” option existed before the option of using “ -monitor telnet:” was an option that Qemu supported. However, experience has shown that using “ -monitor tcp:” would not seem to recover as gracefully after the first network connection was lost. Re-connecting to it did not work well. That experience was improved by upgrading to a newer version of Qemu and using the “ -monitor telnet:” option.

Just using keystrokes

Qemu documentation: Keys notes that you can press Alt-Ctrl-2 to switch from the system's main display to the monitor.

First, it should be noted that (it might be true... this should probably be re-verified sometime) this only works if there is not a -monitor option that changes how the monitor gets accessed.

Still, that seems like an easy way to deal with the monitor. So why does this guide recommend messing around with telnet?

Using that keyboard combination works okay if using Qemu with SDL output that can be interacted with using an X Window display. However, experience has found that this doesn't seem to work when running over a VT100 terminal (or something similar, like a VT220 terminal), which is particularly common when people are using an SSH connection. This isn't too surprising, since the Alt key often doesn't work in a very straightforward manner (although sometimes some software can manage to send a code when the Alt key is pressed, and that might effectively work well enough for some software.) Speculation: Trying to use the Qemu monitor, in this way, might commonly also be less likely to work for people aren't using a graphical user interface.

The Qemu documentation: Keys also notes some additional keystrokes, involving pressing Ctrl-A, when using the -nographic option. However, that approach will presumably only work if using the -nographic option.

So the main reason why the “-monitor telnet” option is generally recommended is because that is a way that works rather consistently, which is great for people who are trying to learn how to make things actually work successfully. If people want to try experimenting with another way of doing things that may have some potential to be easier in some ways, there might be little harm in trying. (It may be a good idea to wait until the system can be successfully controlled using a remote access method, so that the system can be shut down cleanly if there are unexpected problems during experimentation.)