virsh undefine delete guest configuration file in kvm

Sometimes you may execute “virsh undefine” command .. but if you really didnt meant to delete the guest configuration from disk, please make sure you have a backup of the guest configuraiton file in a location which is NOT default for libvirt ie /etc/libvirt/qemu. Otherwise you may wonder where it went after virsh undefine command.

libvirt code path does do a “unlink” operation on the guest configuration file when you execute virsh undefine” command.

This is the snip from my system::

[terminal]
[root@humbles-lap ~]# cd /etc/libvirt/qemu
[root@humbles-lap qemu]# ls
networks rhel5.4-x86_64-kvm_backup.xml rhel5.4-x86_64-kvm.xml RHEL-5.xml rhevh.xml Window-2008.xml
[root@humbles-lap qemu]# virsh define rhel5.4-x86_64-kvm.xml
Domain rhel5.4-x86_64-kvm defined from rhel5.4-x86_64-kvm.xml

[root@humbles-lap qemu]# virsh list –inactive
Id Name State
———————————-
– RHEL-5 shut off
– rhel5.4-x86_64-kvm shut off
– RHEV-H-Server shut off
– Window-2008 shut off

[root@humbles-lap qemu]# pwd
/etc/libvirt/qemu
[root@humbles-lap qemu]# cp rhel5.4-x86_64-kvm.xml /tmp/

[root@humbles-lap qemu]# ls
networks rhel5.4-x86_64-kvm_backup.xml rhel5.4-x86_64-kvm.xml RHEL-5.xml rhevh.xml Window-2008.xml
[root@humbles-lap qemu]# virsh undefine rhel5.4-x86_64-kvm
Domain rhel5.4-x86_64-kvm has been undefined

[root@humbles-lap qemu]# ls
networks rhel5.4-x86_64-kvm_backup.xml RHEL-5.xml rhevh.xml Window-2008.xml
[root@humbles-lap qemu]#
[/terminal]