The QEMU Guest Agent (qemu-ga) is a service that runs inside a guest VM and facilitates communication between the host and the guest OS over a virtio-serial channel. It enables the host to execute structured commands that require coordination with the guest OS, such as initiating a graceful shutdown, freezing the filesystem for snapshots, or retrieving system information.
This document covers how to compile qemu-ga for Windows targets from a Linux host (cross-compilation), how to install the resulting binaries, and how to interact with the agent from the host side.
To build qemu-ga for Windows using cross-compilation with MinGW, you need to install the appropriate compilers, headers, libraries, and build tools.
The following packages are required:
Note: The version constraints are important — some packages include fixes required for QEMU Guest Agent to build and function properly.
To enable communication between the QEMU Guest Agent inside the Windows guest and the host system, the virtual machine must expose a virtio-serial device with a dedicated channel named org.qemu.guest_agent.0.
This channel allows the host to send JSON commands to the guest.
Add the following options:
...
-chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0 \
-device virtio-serial \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0
If the VM is managed with libvirt, add a <channel> element to the domain XML:
<devices>
...
<channel type='unix'>
<source mode='bind'/>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>
</devices>
To build the QEMU Guest Agent (qemu-ga) for Windows from source, you can use the traditional configure and make build system with MinGW cross-compilation tools on a host.
git clone https://github.com/qemu/qemu.git
cd qemu
You can build both 32-bit and 64-bit versions of the guest agent using the appropriate MinGW cross-compilers.
./configure \
--disable-docs \
--disable-system \
--disable-user \
--cross-prefix=i686-w64-mingw32- \
--enable-guest-agent \
--enable-guest-agent-msi \
--enable-qga-vss || cat config.log
make qemu-ga
The following output files will be generated:
./configure \
--disable-docs \
--disable-system \
--disable-user \
--cross-prefix=x86_64-w64-mingw32- \
--enable-guest-agent \
--enable-guest-agent-msi \
--enable-qga-vss || cat config.log
make qemu-ga
The following output files will be generated:
The QEMU Guest Agent can be installed inside a Windows virtual machine in two ways.
Before installation, verify that the VirtIO-serial driver is installed and working.
If you built the agent with --enable-guest-agent-msi, you can install it like any standard Windows package:
msiexec /i qemu-ga-x86_64.msi /qn /norestart
.exe (Without MSI)You can also install the agent manually by copying the built qemu-ga.exe together with its required DLLs from the host to the Windows guest,
and then registering it as a Windows service.
Using the MSI is easier because it automatically includes all required files and sets up the service.
After installation, ensure that the QEMU Guest Agent service is running.
Once the QEMU Guest Agent is installed and running in the Windows guest,
you can communicate with it from the host to perform tasks such as graceful shutdown,
querying guest information, or freezing filesystems for consistent snapshots.
Commands are sent as JSON objects.
virsh (with libvirt)If your VM is managed by libvirt, you can interact with the agent using:
virsh qemu-agent-command <vm-name> '<JSON command>'
virsh qemu-agent-command win-vm '{"execute":"guest-ping"}'
Expected output: {}
If you started QEMU manually and added a virtio-serial port for the agent you can send commands directly through the socket using socat:
echo '{"execute":"guest-ping"}' | socat - UNIX-CONNECT:/tmp/qga.sock
| Command JSON | Description | Example Output (shortened) |
|---|---|---|
{"execute":"guest-ping"} |
Test connectivity | {} |
{"execute":"guest-info"} |
General info about guest & agent | {"version":"8.2.0","supported_commands":...} |
{"execute":"guest-get-osinfo"} |
Detailed Windows OS info | {"name":"Microsoft Windows 10 Pro", ...} |
{"execute":"guest-shutdown"} |
Graceful shutdown | |
{"execute":"guest-shutdown","arguments":{"mode":"reboot"}} |
Graceful reboot | |
{"execute":"guest-fsfreeze-freeze"} |
Freeze all filesystems for snapshot | {"return":1} (number of frozen filesystems) |
{"execute":"guest-fsfreeze-thaw"} |
Thaw frozen filesystems | {"return":1} (number of thawed filesystems) |
{"execute":"guest-fsfreeze-status"} |
Query freeze status | {"return":"thawed"} or "frozen" |
{"execute":"guest-get-fsinfo"} |
List mounted filesystems | JSON array with drive letters and info |
{"execute":"guest-get-time"} |
Get guest system time (ns) | {"return":1693149886000000000} |
For the complete list of available QGA commands,
see the QEMU Guest Agent QAPI schema.