1

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)?

2 Answers2

2
  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
Igor Schaefer
  • 41
  • 1
  • 5
  • You also can try the trick from my [topic](https://serverfault.com/questions/882806/kvm-snapshotting-how-to-see-whats-inside-the-qcow2-file) – Igor Schaefer Nov 17 '17 at 08:38
  • Just read that - interesting... I'll have to look into the differences between 'qemu-img convert' and 'virt-sparsify'. Thanks again! :-) – Ollie Sheridan Nov 18 '17 at 18:13
0

use "--sparse=always" parameter with cp. Example: sudo cp --sparse=always ktun.edu.tr.qcow2 /var/lib/libvirt/images/ktun.edu.tr.qcow2

Source: https://www.whonix.org/wiki/KVM