How To Create A Shared Directory Between Host And Guest In KVM?

How To Create A Shared Directory Between Host And Guest In KVM?


This post was last updated on August 1st, 2020 at 02:39 pm

KVM or kernel-based virtual machine is a virtualization module of Linux kernel. It requires hardware with virtualization extensions such as Intel-VT or AMD-V to provide hardware-assisted virtualization. By using VirtIO it provides paravirtualization support for various operating systems such as Linux, FreeBSD, Windows, etc.

While working on VMs sometimes you may need to use a file that is on the host OS. You can do this in various ways one of them is 9p virtio sharing. In this article, we will see how you can create a shared directory between guest and host OS using virt-manager.

Host operating system

Host refers to a bare-metal machine and the operating system that runs directly on it is called the host OS. It installs the required virtualization packages and provides an environment to run an OS in a virtual machine.

Guest operating system

An OS installed on a virtual machine that is created on the top of the host machine is called guest OS. You can run multiple virtual machines simultaneously on a host.

Creating a shared directory

We will share files in /home/lalit/Share on the host. In the guest, they will show up in /home/lalit/Desktop/host_files. Now follow the steps given below to create a shared directory –

1. Create a directory that you want to share between both host and guest OS. Here I am creating this to /home/lalit/Share on the host. To create a directory you can use the following command in the terminal –

mkdir /home/lalit/Share

2. Change the owner of this directory to libvirt-qemu by using the following command –

chown libvirt-qemu /home/lalit/Share

3. Now, In the virt-manager open a guest by double-clicking on it and then click on show virtual hardware details as it is given below –

4. Here, click on Add Hardware option which is highlighted in the below image –

5. This will open a new window to fill the required information. Keep driver default, select mode squash and browse and select the directory which you want to share and insert the target path (not a path) used to refer filesystem. Once done click on finish.

6. Next, it will ask you for the confirmation press yes

7. Now open the terminal and create a directory where you will mount the created filesystem. Use the following command to create a new directory in guest OS terminal –

mkdir /home/guest_user/host_files

In my case, I will run,

mkdir /home/lalit/Desktop/host_files

8. Next thing is to reboot your guest OS to make changes effective. And then run the following command to mount the filesystem to host_files directory in the guest OS terminal –

mount -t 9p -o trans=virtio,version=9p2000.L /hostshare /home/lalit/host_files


The other possibility of creating a shared directory includes NFS or CISF/Sambha. Now I hope this article is helpful to you if you have a query you can write to us in the comments below.

Previous How To Switch Users In A Linux Or Unix Terminal?
Next How To Display List of Installed Packages In Debian, Ubuntu And Linux Mint?

About author

You might also like

How To 0 Comments

How To Find IP Address From Domain Name In Linux/Unix?

This post was last updated on August 1st, 2020 at 03:35 pmBefore we start running a command to find the IP addresses from the domain name. First, we will discuss

How To 0 Comments

How To Set Password On A RAR Archive In Linux?

This post was last updated on August 1st, 2020 at 01:19 pmFiles inside a RAR archive can have important data. So you may want to protect it from the unusual

How To 0 Comments

How To Install Or Remove A Package With Synaptic Package Manager In Ubuntu/Linux Mint?

This post was last updated on August 1st, 2020 at 02:05 pmSynaptic is a GTK-based GUI program. It is used as a frontend for the APT package manager. Generally, it


No Comments Yet!

You can be first to comment this post!

Leave a Reply