Virt-Manager / Qemu: Create and convert dynamically growing hard drives with qcow2

If you create virtual machines under QEMU/KVM with Virt-Manager, it can happen that the virtual hard disc immediately occupies the entire storage space – even if you use the .qcow2 format.

This is not only annoying, but can quickly waste valuable space on the SSD. In this article, I’ll show you how to correctly create dynamically growing data carriers, what the different storage formats are all about and how you can efficiently convert existing hard drive images. This will help you get the most out of your system and avoid unnecessary memory wastage.

Video

Reduce the size of existing virtual disks

I have already created two virtual machines, which now occupy 128 GB of storage space. As I don’t want to install the virtual Windows again, I would like to convert the existing virtual discs.

Fortunately, this can be done with the following command:

qemu-img convert -O qcow2 win11.qcow2 win11-small.qcow2

The file then only uses the memory actually required.

Creating a new virtual machine

When creating a new virtual machine, the entire memory space is used by default. Basically a rarely stupid default setting.

Instead of accepting the default values, we create a customised medium.

This takes us to the administration. Here we have the option of creating a new data carrier. There is also the option to use only the required storage space.

In my case, however, this did not work. The setting was ignored and the file was created with the full size. Not cool.

Create virtual disk via terminal

The alternative: create the data carrier in advance via the terminal:

qemu-img create -f qcow2 /var/lib/libvirt/images/win11-new.qcow2 128G

Adjust file name and size if necessary. After creation, the file initially only takes up a small amount of memory.

We can now select the file in the administration.

Conclusion

Cumbersome, but at least there is the option of downsizing existing VMs or data carriers and thus saving the time needed to set them up again. Why the memory-consuming default setting is the standard in the software is not clear to me.

Leave a Reply

Your email address will not be published. Required fields are marked *