Unable to recreate a VM on libvirt host where it was originally stored

Hi all,

I’m having an issue with Foreman when trying to recreate a VM on a host where the VM was previously deleted.

I am getting the following error:

Failed to create compute {HOST_name} instance {VM_name}: Call to virStorageVolCreateXML failed: storage volume {VM_name} exsists already.

I am testing a method for automating VM migration so following the dump and copying of the XML and qCow files to another host, I ran the these commands to remove the VM from my source host:

virsh undefine vm
rm /path/to/file/vm.qcow2

I went to retry this process again and upon attempting to create the same VM again on the original source host I received an error from Foreman stating that the vm.qcow2 file already exists on that host.

Running virsh list --all on the source VM does not show any trace of the previous VM. I have also ran a find command on the host and cannot find any file associated with the VM name.

I am unable to any libvrt specific logs to further debug. I am wondering have anyone come across a similar issue before, or have any suggestions as to what to try next?

Any help is greatly appreciated, thanks!

Try refreshing the storage pool - iirc libvirt caches what’s on disk, so when the file is deleted, libvirt doesn’t notice.

Ah okay, I didn’t realise libvirt cached the files. Thank you for your help!

Edit - Commands I used to refresh storage pool for future users:

virsh pool-list #check pools
virsh vol-list qcow #List particular files cached in storage-pool
virsh pool-refresh qcow #refresh storage pool
1 Like