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

Conclusion

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

Linux Topics 0 Comments

[SHELL] How to know in which shell you are working in Linux or FreeBSD

There are several ways to know the current shell on which you are working. We will be using some shell commands to know in which Shell you are working on.

How To 0 Comments

How To Install Ubuntu 20.04 LTS?

This post was last updated on August 1st, 2020 at 12:51 pmUbuntu is among the most popular Linux distributions. It is easy to use, easy to install, and includes everything

How To 0 Comments

How to Capture Boot Time Error Messages

This post was last updated on June 3rd, 2020 at 04:28 pmOne of the easiest ways to capture boot time error messages (when no log file is present) is to

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply