Do you need to set up a shared folder between your host OS and guests running in virt-manager? I will show you how to do it on your Fedora system which involves a SELinux policy change.
First of all, if you don’t have it already, install virt-manager and create a virtualized guest which should be pretty straightforward. Afterwards create a future share folder on your host and set up the permissions (for the purpose of this article I will grand all permissions):
root@host# mkdir /share root@host# chmod 777 /share
Afterwards shut down the guest if it’s running and attach the new filesystem in virt-manager:
- Switch the view to detail hardware view: View > Details
- Go to Attach hardware > Filesystem
- Fill in the name of the source path (/share in our case) and virtual target path (anything you like, I will go with /sharepoint)
- Switch mode to Mapped if you need to have write access from the guest
- Confirm and start the VM again
Now you can mount your shared folder from the VM:
root@guest# mkdir /share root@guest# mount -t 9p -o trans=virtio /sharepoint /share
Or permanently add it to /etc/fstab file:
root@guest# cat /etc/fstab ... /sharepoint /share 9p trans=virtio,version=9p2000.L,rw 0 0
If you don’t have SELinux enabled everything should work now. If you do (which I recommend), you will need to add a policy for files under your /share folder on your host. SELinux won’t allow you to share this folder until it’s labeled svirt_image_t. Here is how to add this policy on your host using semanage:
root@host# semanage fcontext -a -t svirt_image_t "/share(/.*)?" root@host# restorecon -vR /share
That should be it. If not, check the logs :).
← BUY THE PRE-RELEASE
I am writing a complete guide on web application deployment. Ruby with Puma, Python with Gunicorn, NGINX, PostgreSQL, Redis, networking, processes, systemd, backups, and all your usual suspects. 19 chapters and 2 case studies already available.