KVM guest qcow2 larger than disk size

I have a Windows 10 VM running on a server that I need to move to another server. The trouble is that the qcow2 file size is too large for the target server.

What's odd about this is that the partition it's on (on the source server) shows the following in terms of used disk space:

Size  Used Avail
680G  147G  499G

However, the size of the qcow2 file is actually 501G. This doesn't make sense (147G used but a file of 501G is on it), as I thought that the disk size would grow as space was actually used (inside the VM Windows reports 31.3G used of C: which has 467G free), also that the file size is actually larger (when displayed with ls) than the used data on the disk. In other words, I have used 147G of disk space on the partition, but 'ls' says the qcow2 file is 501G.

As I want to copy this onto another machine, I have the same issue; lack of disk space. I've gzipped the qcow2 file & XML data to move the VM over (which comes to ~26G) but when inflating the gzipped file on the target (new) server it expands to 501G of 'really used' disk space, which is more space than I can afford to allocate to it.

So I guess my question is twofold:

  • Why does the file on the original server report as larger than the used space on the partition?
  • How can I reduce the size of the qcow2 file so that it only uses the disk space used by the VM (i.e. 31.3G)?

  1. May be you have snapshot of this VM?
  2. Try to convert this qcow2 file. This command will "shrink" qcow2 file. Delete your snapshots if they are and use qemu-img convert -p -f qcow2 ./vm-disk-original.qcow2 -O qcow2 ./vm-disk-shrinked.qcow2