resize/compress vmdk files

weblike

Renowned Member
May 29, 2013
27
0
66
hi, we have large vmdk files, but the data from VM's is got smaller . it is possible to compress the vmdk files? thank you
 
I converted my .vmdk to .qcow2 using "qemu-img convert vmfile.vmkd -O qcow2 vmfile.qcow2".

Here are my shrink commands. MAKE BACKUPS FIRST!
=================================================================================
#!/bin/bash
# Run as root in VM
service apache2 stop
service mysql stop

#dd fill all of the unused space with zeros for qcow2 compression
dd if=/dev/zero of=/tmp/zerofile
sync
rm -f /tmp/zerofile
shutdown -h 0


=================================================================================
#!/bin/bash
# Run as root on Proxmox
qemu-img convert /ssd/100/vm-100-disk-1.qcow2 -O qcow2 /var/lib/vz/images/100/vm-100-disk-1.qcow2.small
mv /var/lib/vz/images/100/vm-100-disk-1.qcow2 /var/lib/vz/images/100/vm-100-disk-1.qcow2.old
mv /var/lib/vz/images/100/vm-100-disk-1.qcow2.small /var/lib/vz/images/100/vm-100-disk-1.qcow2
qm start 100


# If all is ok then delete the old file
rm /var/lib/vz/images/100/vm-100-disk-1.qcow2.old