How to fix libvirt shared directory with host: Permission denied / Operation not permitted errors
In the VM definition XML, you must select accessmode='mapped'
for the shared directory:
<filesystem type='mount' accessmode='mapped'>
<source dir='/home/vm-data'/>
<target dir='mylabel'/>
</filesystem>
Note that <target dir='mylabel'/>
is not the directory on the VM but an arbitrary label:
In /etc/libvirt/qemu.conf
you must add the following configs (by default, they are commented out):
user = "root"
group = "root"
dynamic_ownership = 0
Furthermore, add the following in the VM’s /etc/fstab
:
mylabel /data 9p trans=virtio,rw,noatime 0 2
Here:
mylabel
is the label you used in the VM definition XML/data
is the directory on the VM where the shared directory will be mounted9p
is the filesystem (i.e. driver) type
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow