How do you decrease or shrink the size of a KVM virtual machine disk?
I allocated a virtual disk of 500GB (stored at /var/lib/libvirt/images/vm1.img), and I'm finding that overkill, so now I'd like to free up some of that space for use with other virtual machines. There seems to be a lot answers on how to increase image storage, but not decrease it. I found the virt-resize tool, but it only seems to work with raw disk partitions, not disk images.
Edit: I'm using an LVM with an Ext4 formatted partition.
Edit: GParted screenshot showing my LVM parition layout. I need to do a lot more then just resize the filesystem. I know of no safe way to resize an LVM. And please don't tell me to use pvresize
. Despite its name, it does not support resizing LVMs.
I did try sudo pvresize /dev/vda5
, but it just says physical volume "/dev/vda5" changed
but doesn't actually reduce the size.
I tried start parted
to manually set the partition size (very dangerous), but doing print all
just gives me the error "/dev/sr0 unrecognised disk label".
Edit: By following these instructions, I was able to successfully shrink both my logical and physical volumes (although I had to remember to activate and deactivate lvm before and after certain commands, which the instructions omit.
Now GParted is showing 250G of unallocated free space. How do I remove this from the KVM disk image and give it back to the underlying hypervisor?
qemu-img -O qcow2 vm1.img vm1-compact.qcow2
.