Reduce VM disk size

Virt-sparsify is a tool which can make a virtual machine disk (or any disk image) sparse a.k.a. thin-provisioned. This means that free space within the disk image can be converted back to free space on the host.

Virt-sparsify tries to zero and sparsify free space on every filesystem it can find within the source disk image.

However if a virtual machine has multiple disks and uses volume management, then virt-sparsify will work but not be very effective.

https://libguestfs.org/virt-sparsify.1.html

Sparse files are created differently than a normal (non-empty) file. Whenever a sparse file is created metadata representing the empty blocks (bytes) of disks is written to the disk, rather than the actual bytes which make up block, using less disk space.

When reading sparse files, the file system transparently converts metadata representing empty blocks into “real” blocks filled with null bytes at runtime.

https://www.geeksforgeeks.org/sparse-files/

Sparse disk image formats such as qcow2 only consume the physical disk space which they need. For example, if a guest is given a qcow2 image with a size of 100GB but has only written to 10GB then only 10GB of physical disk space will be used.

https://www.jamescoyle.net/how-to/323-reclaim-disk-space-from-a-sparse-image-file-qcow2-vmdk

Only the qcow2 format supports encryption or compression. qcow2 encryption uses the AES format with secure 128-bit keys.

https://docs.fedoraproject.org/en-US/Fedora/18/html/Virtualization_Administration_Guide/sect-Virtualization-Tips_and_tricks-Using_qemu_img.html

The resize [raw image] doesn’t actually allocate any disk blocks; the image file is left as a sparse file. If you have expanded the partition and filesystem in the image, you will be able to write more data to files inside, and as data gets written to new blocks of the image file for the first time, actual disk blocks will be allocated.

https://superuser.com/questions/981113/raw-img-file-virtual-space-extended-but-disk-size-still-same

A virtual disk in thin format uses only as much space on the datastore as needed. This means that, if you create a 10 GB virtual disk and place 3 GB of data in it, only the 3 GB of space on the datastore will be used, but the performance will not be as good as with the other two disk types.

You can convert a thin disk to a thick disk by inflating it to its full size.

https://geek-university.com/vmware-esxi/inflate-thin-disk/

Leave a comment