The QEMU Monitor is a command-line interface (CLI) that provides control over a running QEMU virtual machine (VM). Through the QEMU monitor, users can interact with the VM to perform administrative tasks such as managing the virtual machine's resources, configuring devices, or inspecting the system's state.
It is similar to a console for managing a QEMU virtual machine (VM) and allows for tasks like pausing, resuming, and shutting down a VM, as well as querying hardware information, managing snapshots, and performing other low-level operations.
- Control and Management: Pause, resume, or reset the virtual machine.
- Inspection: View and modify the state of the virtual machine, including memory, CPU, and devices.
- Device Management: Add, remove, or configure virtual devices (e.g., disk, network interfaces, serial ports).
- Snapshotting: Create, list, and manage snapshots.
- State Queries: Get information about the VM's running state (e.g., CPU usage, memory usage, and device status).
There are several ways to access the QEMU monitor depending on how the VM is started.
-
Through the
-monitoroption: You can specify how the QEMU monitor is accessed when launching a virtual machine using the-monitoroption:qemu-system-x86_64 -hda /path/to/disk-image.qcow2 -m 2048 -monitor stdio
-monitor stdio: This option makes the monitor accessible through the terminal (standard input/output).- Other options include:
-monitor telnet::port: Open a monitor session over a TCP connection.-monitor unix:/path/to/socket: Use Unix domain sockets for communication.
-
Via the QEMU Monitor Console: Once the monitor is accessible, you can enter commands interactively by typing them directly into the monitor console.
To get a list of available monitor commands, you can type:
helpThis will return a list of commands available in the QEMU monitor, such as info, device_add, and quit.
To exit the QEMU monitor, type:
quitThis will exit the monitor interface and terminate the QEMU process. You can also use exit or Ctrl+D to quit the monitor.
To get information about the virtual machine's status, such as the CPU, memory, and devices, use:
infoTo get more detailed information on a specific aspect, you can query subcommands like:
info cpus: Lists CPU information.info mem: Displays memory usage.info block: Shows information about block devices.
To pause the virtual machine:
stopTo resume the virtual machine:
contTo gracefully shut down the virtual machine (equivalent to issuing a shutdown command inside the guest OS):
system_powerdownTo reset the virtual machine:
system_resetThis command will restart the VM, similar to pressing the reset button on a physical machine.
You can manage virtual devices in a QEMU VM using monitor commands. Some examples include:
- Add a new device:
device_add pci-bridge,id=pcie.0,bus=pcie.0
- Remove a device:
device_del <device-id>
Snapshots allow you to save the current state of a virtual machine and return to that state later. Some common snapshot-related commands include:
-
Take a snapshot:
snapshot_save snapshot-name
-
List snapshots:
snapshot_list
-
Revert to a snapshot:
snapshot_load snapshot-name
-
Delete a snapshot:
snapshot_delete snapshot-name
While a VM is running, you can modify its configuration:
-
Add memory:
memory_add 512M
This command adds 512MB of memory to the VM.
-
Change CPU:
cpu_add 1
You can access the serial console of the virtual machine using the monitor interface:
consoleThis command will redirect the output to the VM’s console.
-
Start the VM with a monitor interface:
qemu-system-x86_64 -hda /path/to/disk-image.qcow2 -m 2048 -monitor stdio
-
In the QEMU monitor console, pause the VM:
stop
-
Perform any necessary actions (e.g., check the VM state, change configurations).
-
Resume the VM:
cont
-
Start the VM with a monitor interface:
qemu-system-x86_64 -hda /path/to/disk-image.qcow2 -m 2048 -monitor stdio
-
While the VM is running, take a snapshot:
snapshot_save my-snapshot
-
Later, you can revert to the snapshot:
snapshot_load my-snapshot
For a complete list of QEMU monitor commands, refer to the official documentation:
- QEMU Monitor Documentation: QEMU Monitor Interface
The monitor interface is a powerful tool for controlling and managing virtual machines in real-time, making it an essential feature for advanced QEMU users.