Create mountable compressed disk image
- Install tools
apt install -y qemu-utils libguestfs-tools
- Sparsify the disk
virt-sparsify -v --in-place disk.img
- Convert the disk to dynamic VHD
qemu-img convert -p -o subformat=dynamic -f raw -O vpc disk.img disk.vhd
Batch
for i in *.img; do virt-sparsify -v --in-place $i; done for i in *.img; do echo $i; qemu-img convert -p -o subformat=dynamic -f raw -O vpc "$i" "${i%%.img}.vhd"; done