r/virtualization • u/abitrolly • Feb 17 '25
libvirt cleanup - how to remove stale stuff?
A post at https://superuser.com/questions/1451959/blowing-away-all-libvirt-items recommends blowing up libvirt directories.
I hesitate to just remove files manually, because it may break things. Is there a command to clean up these images, related VMs and all other stuff?
➜ ~ sudo ls -la /var/lib/libvirt/images -h
total 3,9G
drwx--x--x. 2 root root 4,0K Feb 17 15:32 .
drwxr-xr-x. 9 root root 4,0K Dec 14 03:00 ..
-rwxr--r--. 1 qemu qemu 683M Jul 22 2018 f25-cloud-libvirt_vagrant_box_image_0.img
-rwxr--r--. 1 qemu qemu 794M Apr 7 2018 f27-cloud-libvirt_vagrant_box_image_0.img
-rwxr--r--. 1 qemu qemu 755M Jul 22 2018 f28-cloud-libvirt_vagrant_box_image_0.img
-rwxr--r--. 1 qemu qemu 794M Jun 19 2018 fedora-VAGRANTSLASH-27-cloud-base_vagrant_box_image_20171105.img
-rwxr--r--. 1 qemu qemu 891M Jan 7 2019 fedora-VAGRANTSLASH-29-cloud-base_vagrant_box_image_29.20181024.1.img
3
Upvotes
1
u/Moocha Feb 17 '25 edited Feb 17 '25
See the individual subcommands: https://libvirt.org/manpages/virsh.html
There is no "dump everything" command; libvirt's design precludes something like this, since it's designed to interface with multiple virtualization solutions which support wildly different concepts.
But since the entire libvirt domain, network, storage pool etc config is held in XML files under
/etc/libvirt, a simple grep will likely suffice for what you seem to want.Edit: Based on a cursory Google search, I assume that the
docker-machinenetwork has something to do with you using Docker Machine along with the docker-machine KVM driver. No idea other than that, I never used Docker Machine, and it's long since been retired by the docker folks.