I have a raw image that includes my Windows disk, including 87Gb of C: ; 80 Gb of unallocated space ; 3 Mo of D: ; 147Gb of unallocated space.

How can I delete the unallocated space from my hypervisor disk loosing as few performance as possible?

My hypervisor is kvm, my system is CentOS 7.5.

  • What is the format use ? the hypervysor ? – Kiwy Jun 8 '18 at 9:58
  • Can the VM be stopped? – Hermann Jun 8 '18 at 9:59
  • The generic solution would be to fill the unallocated space with zeroes within the VM, stop the VM and then create holes in the disk image using fallocate. – Kusalananda Jun 8 '18 at 10:13
  • Kusalananda's intentions are promising. What is the file system on the hypervisor disk? – Hermann Jun 8 '18 at 20:34

I think you need to convert your raw image to qcow2 using qemu-img. The qcow2 image will only allocate disk as it is needed (sparse).

For example:

$ qemu-img convert -O qcow2 myimage.raw myimage.qcow2

And then replace the disk image in your VM definition with the qcow2 one.

  • This will only sparsify the blocks filled with zeroes. To optimize the process, one would have to zerofill the disk first, something like dd if=/dev/zero of=/mountpoint/zerofile; rm -f /mountpoint/zerofile – dyasny Jun 8 '18 at 14:17

The standard utility to deal with this situation is virt-sparsify. RAW files do not support sparseness, so you'll need to switch to qcow2 of course.

@tonioc has a more manual approach, but it will definitely also work.

  • Sorry, but raw do support thin allocation... – MUY Belgium Jun 9 '18 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.