virt-sparsify in Proxmox?

mlanner

Renowned Member
Apr 1, 2009
190
1
83
Berkeley, CA
I have a need to maintain a VM in Proxmox as a template that gets shipped as a .qcow2 or .vmdk disk. However, before shipping it, I'd like to make it as small as possible. During installation of software inside the VM I download fairly large files, which then add a lot of "used" space in the image. I've read about 'virt-sparsify' being a good tool to "trim" down the image size. Does anyone a) have any experience with virt-sparsify, and b) it's not in the Debian repos -- so is there a plan to include it with Proxmox?
 
I think I found the answer to my own question. It looks like the 'virt-sparsify' is part of the 'libguestfs-tools' package. My only concern now is if it will conflict with any Proxmox package. Hopefully it won't. I'll try to install it on a PVE test host and report back here once I've got that going have done some testing.
 
  • Like
Reactions: mjw
You could use zerofree available in the debian archive to fill the unused block of the partitions with 0. I have not tested yet on Qcow2 disk images, but with vmdk it makes a huge win to reduce the disk size.

Zerodisk requires you to be in single user mode.
You can also try the following scripted approach, whihc works in multi user setups:
https://anonscm.debian.org/cgit/clo...packer-virtualbox-vagrant/scripts/minimize.sh
 
- If you use "move disk" option offline to convert the disk, it'll be sparse (move disk online don't create sparse image)
- you can do a backup/restore
- you can use fstrim inside a vm, if you use virtio-scsi + discard option.
 
  • Like
Reactions: mjw
I found that the libfsguest-tools had too many missing dependencies.

Thanks for all the ideas. I'm going to automate the build by running a backup of the image and then restoring it to another VMID. Seems to be the simplest option at this point.
 

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!