How do you create a qcow2 file that is small yet commodious on a Linux server?

I believe that there are qcow2 files that displace a small amount of gigabytes on a server (as verified with a df -h on the physical server) yet allow for lots of space when you log into the virt-manager VM and issue a df -h. How do you create such a file? How does the physical server know that there won't be a problem if/when the VMs grow to their maximum size and potentially fill up the physical server?

The truncate command doesn't create small qcow2 files. Virtual Machine Manager's GUI allows the creation of "hardware" via the GUI. Both of these methods of creating .qcow2 files create files that are the maximum size.


To create a qcow2 image for a virtual disk size of 100MB do:

qemu-img create -f qcow2 foobar.qcow2 100M

The created foobar.qcow2 will be about 200KB.

You can easily create a very big virtual disk with this which will take only very small space on the host filesystem, e.g. 100TB virtual disk would take only about 2MB on the host, but when the disk is being used on the guest the file will grow on the host. That will eventually fill the host filesystem and prevent guest doing further writes to any location that is not already allocated. Allocating more resources for guest that is really available on the host is called thin provisioning, see https://en.wikipedia.org/wiki/Thin_provisioning for more info.

Simplest way to avoid problems, when disk is being thin provisioned, is to monitor the disk usage of the host system (with automated alarms being sent to admins) and add more disk space before the host system filesystem fills up.