Shrink Qcow2 Disk Files: Difference between revisions

From Proxmox VE
Jump to navigation Jump to search
Line 6: Line 6:
These steps are all performed within the Windows guest.
These steps are all performed within the Windows guest.
* Defragment your Windows guest's drives either by using the built in defragment program or a 3rd party one such as [http://www.piriform.com/defraggler Defraggler] or [http://ultradefrag.sourceforge.net/en/index.html UltraDefrag].
* Defragment your Windows guest's drives either by using the built in defragment program or a 3rd party one such as [http://www.piriform.com/defraggler Defraggler] or [http://ultradefrag.sourceforge.net/en/index.html UltraDefrag].
* Zero out the free space either using [http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx SDelete] ('''recommended''') or [http://eraser.heidi.ie/ Eraser]. See either section below:
* Zero out the free space either using [http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx SDelete] ('''recommended''') or [http://eraser.heidi.ie/ Eraser] (using '''British HMG IS5 (Baseline) (1 pass)''').  
===Zero Using SDelete===
===Zero Using SDelete===
* Download [http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx SDelete] and save it somewhere on your system (eg. <code>C:\windows\system32\</code>).
* Download [http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx SDelete] and save it somewhere on your system (eg. <code>C:\windows\system32\</code>).
Line 17: Line 17:
sdelete -z e:
sdelete -z e:
</pre>
</pre>
===Zero Using Eraser===
* Download and install the latest [http://eraser.heidi.ie/ Eraser] inside the XP VM.
* Load Eraser.
** Edit main settings. Change default file erasure and unused space erasure methods to '''British HMG IS5 (Baseline) (1 pass)'''. This will zero out space instead of using random data.
** Create a new job under Erase Schedule and add the free space from the C:\ drive (and any other drive you want to shrink).
** Run the job.
** '''Note:''' I've had Eraser crash during this process. If this happens, it will leave a directory under the root of your drive with all sorts of random data in it. You'll want to delete this folder and start the process again. Keep running the process until it goes through without crashing. Hopefully the folks at Eraser are working on the stability of this new version.


==Linux Guest Preparation==
==Linux Guest Preparation==

Revision as of 18:50, 16 March 2016

Over time a guest's *.qcow2 disk files can grow larger than the actual data stored within them. This can also happen faster if you defragment the partitions within the guest itself. In order to shrink the *.qcow2 files, you'll need to zero out all free space of the partitions contained within the guest first. Below is the process.

NOTE: Have backups ready, you never know!

Windows Guest Preparation

These steps are all performed within the Windows guest.

  • Defragment your Windows guest's drives either by using the built in defragment program or a 3rd party one such as Defraggler or UltraDefrag.
  • Zero out the free space either using SDelete (recommended) or Eraser (using British HMG IS5 (Baseline) (1 pass)).

Zero Using SDelete

  • Download SDelete and save it somewhere on your system (eg. C:\windows\system32\).
  • Run SDelete and zero free space:
sdelete -z
  • If there is more than one partition, then for eg., drive E:\, use:
sdelete -z e:

Linux Guest Preparation

Use the following command to zero out your disk:

dd if=/dev/zero of=/mytempfile
# that could take a some time
rm -f /mytempfile

Shrink the Disk File

  • Shut down the VM.
  • Log into the Proxmox node and go to the VM's disk storage directory.
  • IMPORTANT: Create a backup of your existing VM disk file:
mv image.qcow2 image.qcow2_backup
  • Option #1: Shrink your disk without compression (better performance, larger disk size):
qemu-img convert -O qcow2 image.qcow2_backup image.qcow2
  • Option #2: Shrink your disk with compression (smaller disk size, takes longer to shrink, performance impact on slower systems):
qemu-img convert -O qcow2 -c image.qcow2_backup image.qcow2
  • Example: A 50GB disk file I shrank without compression to 46GB, but with compression to 25GB. Time to compress was almost twice as long as an uncompressed shrink.
  • Boot your VM and verify all is working.
  • When you verify all is well, it should be safe to either delete the backup of the original disk, or move it to an offline backup storage.