DevOps

How do I enable QEMU guest agent?

Qemu is used for creating a virtual machine within Linux, which helps users to use various machines and platforms from a single interface. Users can create multiple hosts through it, and to exchange information between the host and guest we need a tool, hence qemu guest agent is used for this purpose.Qemu guest agent acts as a helper for the guest system so that users can exchange various information such as IP address and other network information to the host. It’s installed on the guest system and used for the execution of commands on the guest. Here, in this article we’ll guide you on how to enable qemu guest agents.

Step-by-Step Guide

Following are the steps involved for enabling the qemu guest agent which involves the installation of qemu, kvm and libvirt as well in case you don’t have it in your system.

Step 1: Updating your Repository

Before any installation we need to update our repository and for that execute the below command:

$ sudo apt update

Step 2: Installing Qemu and libvirt

Now we need to have Qemu and libvirt on our system, for that execute the below command:

$ sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils

Step 3: Installing virt-manager

Next thing we need is to download the virtual manager in which we’ll create our virtual device, so execute the below command for the installation:

$ sudo apt install virt-manager

Step 4: Creating directory

Now after this we need to create a directory and for that execute the below command:

$ sudo mkdir -p /var/lib/libvirt/qemu/channel/target

After creating the directory we need to change the owner, so execute the below command in your terminal:

$ sudo chown -R libvirt-qemu:kvm /var/lib/libvirt/qemu/channel

Step 5: Changes in the libvirt file

Open the below file using the command provided:

$ sudo nano /etc/apparmor.d/abstractions/libvirt-qemu

This will open a file in which you’ve to add the given lines at the end and save the file:

/var/lib/libvirt/qemu/channel/target/* rw,

Step 6: Installing Qemu Guest Agent

Now we will install the guest agent on our system so for that execute the below command provided:

$ sudo apt-get install qemu-guest-agent

This will successfully install qemu guest agent on your system.

Step 7: Creating Virtual Device

After installing the agent we need to create a virtual device on the virtual manager, so open the virtual manager and create a device.

Here we’ve created a Ubuntu 20.04 virtual device using the ISO file, and name it “ubuntu20.04”, you can name it according to your choice but remember the name as we’ve to use it later.

Step 8: Virtual Terminal

Now we’ll enter the virtual device terminal by executing the below command:

$ virsh

Here we need to edit our virtual device so execute the below command and replace ubuntu20.04 with the name of your virtual machine:

virsh # edit ubuntu20.04

Here, you’ll be provided with various option so select the 1 option which will open a file in which you’ve to paste the following lines:

<channel type="unix">

<source mode="bind"/>

<target type="virtio" name="org.qemu.guest_agent.0"/>

</channel>

After pasting the lines simply save the file and following message will be displayed:

Now, restart you virtual machine and execute the below lines in your virsh terminal which will provide you the IP address:

virsh # qemu-agent-command ubuntu20.04 '{"execute":"guest-network-get-interfaces"}'

This was all for enabling the qemu guest agent on your systems.

Conclusion

Qemu guest agent helps the user exchange the information between host and guest, and acts like a helper daemon. In this article we guided you how to enable the qemu guest agent on your systems, also we provided you commands for the installation of qemu-kvm, libvirt and virt-manager which were pre-required for enabling the qemu agent. We also created a virtual device using the iso file and enabled the qemu agent to share ip addresses between host and guest.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.