1

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.

4
  • What is the format use ? the hypervysor ?
    – Kiwy
    Jun 8, 2018 at 9:58
  • Can the VM be stopped?
    – Hermann
    Jun 8, 2018 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, 2018 at 10:13
  • Kusalananda's intentions are promising. What is the file system on the hypervisor disk?
    – Hermann
    Jun 8, 2018 at 20:34

2 Answers 2

1

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.

1
  • 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, 2018 at 14:17
0

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.

1
  • Sorry, but raw do support thin allocation... Jun 9, 2018 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .