how to delete a guest after creating it with virt-install
64,047
According to the manual of virsh this is:
virsh destroy _domain-id_
virsh undefine _domain-id_
virsh vol-delete --pool vg0 _domain-id_.img
And it further says: "Undefine (destroy) the configuration for an inactive domain. Since the domain is not running the domain name or UUID must be used as the domain-id."
Related videos on Youtube
Author by
Erik Sjölund
E-mail: [email protected] Employed at Karolinska Institute https://careers.stackoverflow.com/eriksjolund
Updated on September 18, 2022Comments
-
Erik Sjölund almost 2 years
I created a KVM guest from the command line with
virt-install
where I used the command line options--disk pool=vg0,size=20
and--name virt1.example.com
.How can I delete this KVM guest from the command line? I don't need it anymore.
Just for the record the whole command line was
virt-install --debug --hvm --vnc --name virt1.example.com --os-type=linux --os-variant=rhel6 --pxe --network network=default,model=e1000,mac=02:54:00:13:be:e4 --disk pool=vg0,size=20 --ram 1024 --vcpus=1
and here is some extra information
[root@server ~]# virsh vol-list vg0 Name Path ----------------------------------------- lv0 /dev/vg0/lv0 lv_swap /dev/vg0/lv_swap virt1.example.com.img /dev/vg0/virt1.example.com.img [root@server ~]# virsh list Id Name State ---------------------------------- 3 virt1.example.com running
Update
Running these three commands seems to remove the installed KVM
virsh destroy virt1.example.com virsh undefine virt1.example.com virsh vol-delete --pool vg0 virt1.example.com.img
For more details see the terminal session:
[root@server ~]# virsh list --all Id Name State ---------------------------------- 3 virt1.example.com running [root@server ~]# virsh undefine virt1.example.com error: Failed to undefine domain virt1.example.com error: Requested operation is not valid: cannot delete active domain [root@server ~]# virsh destroy virt1.example.com Domain virt1.example.com destroyed [root@server ~]# virsh list --all Id Name State ---------------------------------- - virt1.example.com shut off [root@server ~]# virsh undefine virt1.example.com Domain virt1.example.com has been undefined [root@server ~]# virsh list --all Id Name State ---------------------------------- [root@server ~]# virsh vol-list --pool vg0 Name Path ----------------------------------------- lv0 /dev/vg0/lv0 lv_swap /dev/vg0/lv_swap virt1.example.com.img /dev/vg0/virt1.example.com.img [root@server ~]# virsh vol-delete --pool vg0 virt1.example.com.img Vol virt1.example.com.img deleted [root@server ~]# virsh vol-list --pool vg0 Name Path ----------------------------------------- lv0 /dev/vg0/lv0 lv_swap /dev/vg0/lv_swap [root@server ~]# cat /etc/issue CentOS Linux release 6.0 (Final) Kernel \r on an \m [root@server ~]# virsh --version 0.8.1
-
nmtoken almost 10 yearsFor others looking at this answer, if your error is at the virsh undefine virt1.example.com step (with an error like 'Refusing to undefine while domain managed save image exists'). Then you may need an additional command like: virsh managedsave-remove virt1.example.com.
-
-
Erik Sjölund almost 13 yearsThanks @mailq I think I managed to delete the KVM. Maybe you could update your answer accordingly?
-
mailq almost 13 yearsNow it reflects the solution
-
Rick Chatham over 8 yearsFor those who are curious, this is what those commands do:
virsh destroy
does a forced shutdown of the vm,virsh undefine
removes the configuration from KVM, andvirsh vol-delete
removes the actual disk image. If you need to get the_domain-id_
typevirsh list --all
to get a list of your VMs. -
imz -- Ivan Zakharyaschev over 7 yearsThis recipe has been scripted in virt-delete from virt-utils, which also has a few other useful scripts.
-
ILMostro_7 over 5 yearsYou can do
virsh undefine yourdomainname --storage vda
in one step. Be careful not to use--remove-all-storage
, unless you know what you're doing. -
olivecoder over 3 yearsIn my case an additional step was required:
virsh managedsave-remove aaa-db1