If you’re running virtual machines with KVM (Kernel-based Virtual Machine), setting up a shared folder between the host and guest can make transferring files much easier. Whether you’re testing applications or developing software inside your VM, a shared folder saves time and effort.
This guide walks you through how to set up a shared folder between your KVM host and a Linux guest using VirtioFS — the recommended modern method.
What You Need
- A KVM host with
libvirt
andvirt-manager
installed - A Linux guest OS (like Ubuntu or Fedora)
- Root or sudo access on both host and guest
- QEMU 5.0+ and libvirt 6.2.0+ (for VirtioFS support)
Step 1: Create a Shared Directory on the Host
Pick or create a directory on your host that you want to share:
mkdir -p /home/youruser/shared-folder
Change the permissions if needed:
chmod 777 /home/youruser/shared-folder
Step 2: Add the Shared Folder to the VM (VirtioFS)
- Open virt-manager
- Select your VM → Click Shut Down if it’s running
- Right-click the VM → Open
- Go to Details → Click Add Hardware
- Choose Filesystem
- Set:
- Driver: VirtioFS
- Source Path:
/home/youruser/shared-folder
- Target Path:
sharedfolder
(this is how it appears inside the guest) - Mode:
Mapped
orPassthrough
depending on your access needs
- Click Finish, then Apply
Step 3: Mount the Shared Folder in the Guest
Start the VM and open a terminal inside the guest.
First, install the virtiofsd
package if it’s not already present:
sudo apt install virtiofsd -y # For Debian/Ubuntu
# or
sudo dnf install virtiofsd -y # For Fedora/RHEL
Create a mount point:
sudo mkdir /mnt/sharedfolder
Mount the shared folder:
sudo mount -t virtiofs sharedfolder /mnt/sharedfolder
You can now access the files from both host and guest.
Step 4: Make the Mount Permanent (Optional)
To auto-mount on boot, add this line to /etc/fstab
in the guest:
sharedfolder /mnt/sharedfolder virtiofs defaults 0 0
Troubleshooting Tips
- Make sure your VM is shut down before editing hardware in virt-manager
- Ensure that both the host and guest are updated with recent
libvirt
andqemu
packages - If
virtiofs
doesn’t show up, your system may not support it — consider upgrading
Wrapping Up
Setting up a shared folder between your KVM host and guest with VirtioFS is quick and efficient. It beats juggling file transfers and streamlines your development or testing workflow. Once set up, the folder behaves like any local directory inside your VM.
Let me know in the comments if you ran into any issues or if you’d like a version of this tutorial for Windows guests.
Leave a Reply