virsh-undefine
Remove a virtual machine definition
TLDR
Delete only the virtual machine configuration file
Delete the configuration file and all associated storage volumes
Delete the configuration file and the specified storage volumes using the target name or the source name (as obtained from the virsh domblklist command)
SYNOPSIS
virsh undefine domain-name [--nvram] [--remove-all-storage] [--managed-save] [--wipe-after-delete]
PARAMETERS
domain-name
The name, ID, or UUID of the virtual machine to undefine.
--nvram
Also remove the NVRAM file associated with the domain.
--remove-all-storage
Also remove all storage volumes associated with the domain (DANGEROUS).
--managed-save
Also remove managed save image associated with the domain, if it exists.
--wipe-after-delete
Attempt to securely wipe the storage volumes after they have been removed. This option implies --remove-all-storage.
DESCRIPTION
The virsh undefine command removes the definition of a virtual machine from the hypervisor (libvirt) configuration.
This does not delete any virtual disk images or other data associated with the VM. It only removes the VM's XML definition, making it no longer visible to virsh commands like virsh list. If you want to use this virtual machine image you will need to define it using a definition file.
The VM must be shut down before it can be undefined. The command can be used to clean up unused VM definitions or to prepare for migrating a VM definition to another hypervisor. While the VM's state is not lost, it's important to remember that it will need to be manually managed outside of the hypervisor's management tools after being undefined.
Note: This command can be irreversible without backup of the VM's XML definition file.
CAVEATS
Using the --remove-all-storage option will permanently delete the virtual machine's disk images. This action is irreversible and will result in data loss. Always double-check the domain name before using this option. Make sure the VM is shut down before running virsh undefine. Data volumes can be lost without ability to restore.
If you want to save the definition file you can create a backup with virsh dumpxml domain > domain.xml
EXAMPLE
To undefine a VM named 'myvm': virsh undefine myvm
To undefine a VM named 'myvm' and also remove its NVRAM: virsh undefine myvm --nvram
To undefine a VM and remove all associated storage volumes (USE WITH EXTREME CAUTION): virsh undefine myvm --remove-all-storage
SEE ALSO
virsh(1), virsh-define(1), virsh-list(1), virsh-destroy(1)