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 have multiple inactive domains in libvirt and I want to delete them all:

# virsh list --inactive
 Id Name                 State
----------------------------------
  - instance-0000000c    shut off
  - instance-0000000f    shut off
  - instance-00000010    shut off

Is there a simple way to tell libvirt to delete all inactive domains, or do I have to manually do:

# virsh undefine instance-0000000c
# virsh undefine ...
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Something like this should work:

$ virsh list --inactive | grep instance | cut -d " " -f 4 | xargs -n 1 virsh undefine

If you want to review that list before killing them:

$ virsh list --inactive | grep instance | cut -d " " -f 4 > inactive_domains
$ vi inactive_domains

Then if everything looks good:

$ cat inactive_domains | xargs -n 1 virsh undefine
share|improve this answer
    
I don't think you can pass multiple arguments to virsh undefine. –  Lorin Hochstein Feb 24 '12 at 19:54
    
@LorinHochstein - fixed. –  EEAA Feb 24 '12 at 20:42

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.