bijavix blog

External QEMU VM Images

bijavix <[email protected]>

Migrate your QEMU VM disk images to an external drive, set-up the libvirt storage pool and resolve virt-manager permission errors.

1. Prepare target folder on external drive

cd /media/user/drive/VM/
sudo mkdir images
cd images

Verify the current images directory:

sudo ls -alZ /var/lib/libvirt/images

2. Move VM image from local libvirt storage

sudo mv /var/lib/libvirt/images/VM.qcow2 /media/user/drive/VM/images
sudo chown libvirt-qemu:kvm /media/user/drive/VM/images/VM.qcow2
sudo chmod 600 /media/user/drive/VM/images/VM.qcow2

3. Point the VM definition to the new location

Edit the virtual machine definition:

sudo virsh edit VM

Replace the <source> element so it references the external path:

<!-- Before -->
<source file='/var/lib/libvirt/images/VM.qcow2'/>

<!-- After -->
<source file='/media/user/drive/VM/images/VM.qcow2'/>

4. Create the new storage pool

In virt-manager:

  1. Open Connection Details > Storage.

  2. Click Add Pool and choose dir as the type.

  3. Point it to /media/user/drive/VM/images.

  4. Refresh the pool; the Volumes list should now show your image.

5. Adjust storage-pool permissions

You may see an error when starting the VM:

libvirt.libvirtError: Cannot access storage file (as uid:64055, gid:104): Permission denied

Quick fix method, inside virt-manager

  1. Run sudo virt-manager.

  2. Create a dummy VM whose disk lives in the new pool.

  3. Accept the prompt that offers to correct path permissions.

Manual ACL method

Grant execute permission on the mount point so libvirt-qemu can traverse it:

setfacl -m u:libvirt-qemu:--x /media/user

This will set the Access Control Lists (ACLs) to add the user libvirt-qemu with execution permissions for the mounted media.

Check ACLs:

getfacl /media/user
# file: media/user
# owner: root
# group: root
user::rwx
user:user:r-x
user:libvirt-qemu:--x
group::---
mask::r-x
other::---