How to configure and use qemu-guest-agent in Ubuntu 12.04? My main aim is to get the IP address of guest VM from Host machine

Solution 1:

  1. First of all install latest version of libvirt-bin(>=1.0.0) on the host system. Installing libvirt-bin(>=1.0.0) on Ubuntu12.04 is itself a challenge because of dependencies.This link may help to do so: https://tad-do.net/2013/02/22/testing-new-libvirt-features-on-ubuntu-12-04/

    Then execute following commands on host:

    mkdir -p /var/lib/libvirt/qemu/channel/target
    chown -R libvirt-qemu:kvm /var/lib/libvirt/qemu/channel
    
  2. Add the following to the bottom of /etc/apparmor.d/abstractions/libvirt-qemu:

    /var/lib/libvirt/qemu/channel/target/* rw,
    
  3. Install qemu-guest-agent in guest VM.

    sudo apt-get install qemu-guest-agent
    
  4. virsh edit VMNAME and add following lines in the devices:

    <channel type="unix">
      <source mode="bind"/>
      <target type="virtio" name="org.qemu.guest_agent.0"/>
    </channel>
    
  5. Shutdown and start the VM and execute following command to get the IP Address. There are many other things which can be done using guest-agent.

    virsh qemu-agent-command VMNAME '{"execute":"guest-network-get-interfaces"}'
    

References:http://wiki.stoney-cloud.org/wiki/Qemu_Guest_Agent_Integration