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: