libvirt Error reading QCOW2: Permission denied
We faced a scenario in our lab that may be of interest to some of you.
We re-purposed an old bare-metal server running CentOS 7.3 as a hypervisor/target server for a MetroÆ test. On our first attempt to install a VSD, we ran out of space when we copied the QCOW2 file to the configured images directory.
The KVM images file directory is specified in the common.yml deployments file. If not set, the images directory defaults to /var/lib/libvirt/images. On this particular target server, however, the hard disk was partitioned into two devices:
Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 50G 3.4G 47G 7% / <snip...> /dev/mapper/centos-home 865G 11G 855G 2% /home
/var/lib/libvirt/images is hosted on the centos-root partition and didn’t have enough space to hold the QCOW2 images.
Our first solution: Create a new images directory under $HOME. Unfortunately, when MetroÆ used the Ansible ‘virt’ module to create the VM, we saw the following error:
libvirtError: Cannot access storage file '/home/caso/images/vsd2.example.com/VSD-5.2.2_24.qcow2' (as uid:107, gid:107): Permission denied
We tried many things, including
- Disabling SELinux
- Modifying the ownership of the images directory
- Modifying the permissions of the images directory
In the end, we stumbled upon a post online that warned about using $HOME to hold your images directory. The author asserted that $HOME must have +x for all or it won’t be accessible by libvirt. Sure enough, chmod +x
on $HOME fixed the problem. That or create the images directory outside of $HOME. Either should work.