Share Folder Between Guest and Host in virt-manager (KVM/Qemu/libvirt)

3 min


In this guide, you will learn how to share a folder between host and guest in virt-manager using KVM, QEMU and libvirt.

The virt-manager application or package uses the libvirt library to provide virtual machine management services. It has a desktop interface that helps to create, delete, and manage multiple virtual machines.

The virt-manager desktop interface and its components provide flexible virtual machine management services for various personal and business use cases. it is a free and open-source application primarily used for KVM virtual machines. However, it can also support other hypervisors such as Xen and LXC.

In the earlier article, I explained how to create a virtual machine using virt-manager. This article covers how you can seamlessly access files and folders between guest and host virtual machines.

To share a folder between a Windows guest and a Linux host, visit this tutorial.

A note about virtiofs

The sharing files and folders are powered by the libvirt shared file system called virtiofs. It provides all the features and parameters to access the directory tree on the host machine. Since most of the virt-manager virtual machine configurations are translated to XML, the share files/folders can also be specified by the XML file.

Share folder in virt-manager

  • First, make sure your guest virtual machine is powered off. From the virt-manager GUI, select the virtual machine and click on Open to pull up the console settings.
Open the settings
Open the settings
  • Click on the icon which says show virtual hardware details in the toolbar. And then click on Memory on the left panel.
  • Select the option “Enable shared memory“. Click Apply.
Enable the shared memory option
Enable the shared memory option
  • And then click “Add hardware” at the bottom.
Click on add hardware
Click on add hardware
  • Select File system from the left panel in the add new hardware window.
  • Then select Driver=virtiofs in the details tab. Click on browse > browse local and select the host path you want to access inside the guest VM.
  • In the target path, mention any name you want. It’s just a file tag which will be used during mount.
  • So, if I want to access the Pictures/Screenshots folder (/home/debugpoint/Pictures/Screenshots), sample settings could be the following:
Add a new file system hardware
Add a new file system hardware

The XML settings are below for the above configuration. You can find it in the XML tab.

<filesystem type="mount" accessmode="passthrough">
  <driver type="virtiofs"/>
  <binary path="/usr/libexec/virtiofsd"/>
  <source dir="/home/debugpoint/Pictures/Screenshots"/>
  <target dir="mount_tag_pictures"/>
  <alias name="fs1"/>
  <address type="pci" domain="0x0000" bus="0x08" slot="0x00" function="0x0"/>
</filesystem>

Click on Finish. In the main virt-manager window, right-click on the VM and click Run to start the virtual machine. Make sure to click on the “show the graphical console” (monitor icon in the toolbar – if the VM is not showing.

In the guest machine, create a folder where you want to mount the host folder. For this example, I have used /mnt/pictures.

sudo mkdir /mnt/pictures

And finally, mount the host folder using the tag you created in the above step to this new folder. Use the following command to do that from the terminal. Ensure to change the tag and folder name in the below command as your system.

sudo mount -t virtiofs mount_tag_pictures /mnt/pictures

Now you can browse the folders and add/delete items seamlessly in virt-manager between host and guest.

Access host files from virt-manager guest
Access host files from virt-manager guest

To share a folder between a Windows guest and a Linux host, visit this tutorial.

Wrapping Up

I hope this solution helps you to access host files and folders from the guest machine. Remember, your user Id, which is used to launch the virt-manager app, should have the same access to the host folder.

If you run into any errors, the above guide helped you drop a note below.

Reference


Arindam

Creator and author of debugpoint.com. Connect with me via Telegram, 𝕏 (Twitter), or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

23 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments