How to enable QEMU guest agent in KVM

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • KVM
  • libvirt guest-agent

Issue

  • How to enable QEMU guest agent for KVM guests?
  • How to connect KVM libvirtd guests using the channel?

Resolution

RHEL host modifications:

1. Edit the guest configuration:

# virsh edit <guest-name>

2. Find the <devices> section in the xml file and add the following new device.

RHEL 6 Host

<channel type='unix'>
   <source mode='bind' path='/var/lib/libvirt/qemu/<guest-name>.agent'/>
   <target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>

RHEL 7 Host

<channel type='unix'>
   <target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>

3. Save the modified guest description.

Guest side modifications:

4. Install the guest-agent:

# yum install qemu-guest-agent

5. Enable the agent

RHEL 6 Guest

# chkconfig qemu-ga on
# service qemu-ga start

RHEL 7 Guest

# systemctl start qemu-guest-agent
# systemctl enable qemu-guest-agent

Test the communication

6. Test the communication from the KVM Host:

# virsh qemu-agent-command <guest-name> '{"execute":"guest-info"}'

It should return something like this:

{"return":{"version":"1.5.3","supported_commands":[{"enabled":true,"name":"guest-set-vcpus"},{"enabled":true,"name":"guest-get-vcpus"},{"enabled":true,"name":"guest-network-get-interfaces"},{"enabled":true,"name":"guest-suspend-hybrid"},{"enabled":true,"name":"guest-suspend-ram"},{"enabled":true,"name":"guest-suspend-disk"},{"enabled":true,"name":"guest-fstrim"},{"enabled":true,"name":"guest-fsfreeze-thaw"},{"enabled":true,"name":"guest-fsfreeze-freeze"},{"enabled":true,"name":"guest-fsfreeze-status"},{"enabled":false,"name":"guest-file-flush"},{"enabled":false,"name":"guest-file-seek"},{"enabled":false,"name":"guest-file-write"},{"enabled":false,"name":"guest-file-read"},{"enabled":false,"name":"guest-file-close"},{"enabled":false,"name":"guest-file-open"},{"enabled":true,"name":"guest-shutdown"},{"enabled":true,"name":"guest-info"},{"enabled":true,"name":"guest-set-time"},{"enabled":true,"name":"guest-get-time"},{"enabled":true,"name":"guest-ping"},{"enabled":true,"name":"guest-sync"},{"enabled":true,"name":"guest-sync-delimited"}]}}

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.