Kernel Virtual Machine - Resize Disk

Seems strange that they say that. I don’t know of any libvirt commands that can actually resize a disk, so the qemu-tools are pretty much the only real way to do it. Although I haven’t found anything via a quick google, I could be wrong.

Generally, if I’m going to resize to a specific size without the + sign, then I just check the size of the existing image first, for example:

-rw------- 1 root root  41G Oct 17 21:05 portainer-docker.qcow2
-rw------- 1 root root  41G Oct 17 21:05 portainer.qcow2
-rw------- 1 root root  41G Nov 22 17:59 rocky-fw.qcow2
-rwxr-xr-x 1 root root  344 Apr 22  2020 shrink_vm_image.sh
-rw------- 1 root root  61G Nov  9 11:22 ufo-build.qcow2
-rw------- 1 root root 201G Nov 25 08:43 win10.qcow2

so the 41GB ones, I could effectively then use the first command I gave you, but replace 20 with 60. Or, use the second command and just do +20G which would effectively be the same.

The shrink script I have is when I prepare OpenStack images, if I create the VM with 10GB, then the disk image is 10GB. But I don’t want to upload empty space to OpenStack, so I shrink it to the used disk space size, which can be about 1GB for a minimal install. Shrinking is done like this:

qemu-img convert -O qcow2 -c $OLDIMAGE $NEWIMAGE

so if I was to shrink the win10.qcow2:

qemu-img convert -O qcow2 -c win10.qcow2 win10-new.qcow2
1 Like