Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
For 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. –  nmtoken Aug 5 at 12:09

1 Answer 1

up vote 6 down vote accepted

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."

share|improve this answer
    
Thanks @mailq I think I managed to delete the KVM. Maybe you could update your answer accordingly? –  Erik Sjölund Aug 11 '11 at 12:35
    
Now it reflects the solution –  mailq Aug 11 '11 at 12:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.