3

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

2 Answers 2

1

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
0
4

There is a much cleaner way to do it:

virsh list --inactive --name | xargs -r -n 1 virsh undefine

Be careful, it will removall all. Also it will not fail when there is nothing to clean up.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .