How to Permanently Remove a VM from virsh List After Deleting Its XML and QCow2 Files


2 views

When you delete a VM's configuration files (.xml) and disk images (.qcow2) manually but the VM still appears in virsh list --all, it's because libvirt maintains an internal state. The hypervisor isn't automatically aware of filesystem-level changes.

1. Verify VM State:
virsh dominfo your_vm_name
Check if the VM is in "shut off" state. Active VMs require forced removal.

2. Undefine the VM:
virsh undefine your_vm_name
This removes the VM from libvirt's configuration. Add flags as needed:
--remove-all-storage for associated disks
--snapshots-metadata for snapshots

If standard undefine fails, try:
virsh undefine your_vm_name --managed-save
or
virsh undefine your_vm_name --nvram

# List all VMs
virsh list --all

# Destroy if running
virsh destroy problematic_vm

# Undefine with storage removal
virsh undefine problematic_vm --remove-all-storage

# Verify removal
virsh list --all

Always use libvirt tools for VM management:
virsh shutdown before deletion
virt-manager GUI for visual confirmation

Check these locations for leftover files:
/etc/libvirt/qemu/
/var/lib/libvirt/images/
/var/run/libvirt/


When you delete a KVM virtual machine by removing its XML definition file and QCOW2 disk image, but it still appears in virsh list --all, you're dealing with libvirt's persistent configuration. Here's why this happens and how to completely clean it up.

Libvirt maintains configuration separately from the actual VM files. Even after deleting:

/etc/libvirt/qemu/your_vm.xml
/var/lib/libvirt/images/your_vm.qcow2

The VM remains registered in libvirt's internal database until properly undefined.

First verify the VM state:

virsh list --all

If the VM shows as "shut off" but persists, destroy its libvirt registration:

virsh undefine your_vm_name

For VMs with additional storage volumes or snapshots:

virsh undefine --remove-all-storage your_vm_name

If standard undefine fails, try these advanced methods:

# Force removal
virsh undefine --nvram your_vm_name

# Check for lingering volumes
virsh vol-list --pool default

# Manual cleanup in libvirt storage
virsh pool-refresh default

Confirm complete removal with:

virsh list --all
find /etc/libvirt/qemu -name "your_vm*"
find /var/lib/libvirt/images -name "your_vm*"

Always use proper VM deletion workflow:

virsh destroy your_vm_name       # If running
virsh undefine your_vm_name      # Remove config
rm /path/to/your_vm.qcow2        # Delete storage