Create sparse disk images

Omar Khalil

New Member
Aug 22, 2017
4
1
3
32
Hello,

I'm trying to create sparse disks using the GUI, so far no success, I can only create VMDK and it would be automatically sparse (occupying the actual used disk space not the maximum disk space),
but not for qcow2 and raw.

Using SCSI with VirtIO SCSI controller and with discard option on in hope that the non-used free space will be reclaimed by host, but no success.

I tried so far almost every combinations of bus types and image formats to no avail.


With qcow2, It was possible to get it sparsed by creating a raw image and converting it to qcow2, using qemu-img convert command:

Code:
qemu-img convert -f raw -O qcow2 vm-100-disk-2.raw vm-100-disk-2.qcow2


Now checking the space occupied by the newly converted image it will report only 200MB and not 32GB, that's perfect.

But converting back again to raw format:

Code:
qemu-img convert -f qcow2 -O raw vm-100-disk-2.qcow2 vm-100-disk-2.raw

Sadly, It will occupy again the full 32GB and not only the used space of 200MB.


Using another technique to sparsify a disk image:

by filling the empty space inside the guest with zeroes using the dd command and syncing the changes, then delete the file, and trying to cp with --sparse=always parameter after turning of the guest machine:

Code:
dd if=/dev/zero of=zerofile bs=1M
sync
rm zerofile

Code:
cp --sparse=always vm-100-disk-2.raw vm-100-disk-2-sparsed.raw


Sadly also this method failed.

So is there any things on the host that I'm not aware of, is my host system filesystem doesn't support sprase files.

Any help or tip is highly appreciated

Host Informations:
I installed proxmox using the proxmox repository and I have the latest upgrades as of today
 
Checking the actual disk usage using:

Code:
du -h vm-100-disk-2-sparsed.raw

We see that the sparsed image shows only the occupied space which is zero.

But doing ls:

Code:
 ls -lh vm-100-disk-2-sparsed.raw

Will show the full allocated space for this image, so I think ls will show the allocated space of this file, but the file is already successfully sparsified.
 
  • Like
Reactions: Dark26

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!