Shrink Qcow2 Disk Files: Difference between revisions

From Proxmox VE
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[[Category:HOWTO]]
[[Category:HOWTO]]
Over time the *.qcow2 disk files can grow larger than the actual data stored within them. This can also happen faster if you defragment the drives within the XP VM itself. In order to shrink the *.qcow2 files, you'll need to zero out all free space of the drives within the XP VM first. Below are (very rough) notes on how to do this:
Over time the *.qcow2 disk files can grow larger than the actual data stored within them. This can also happen faster if you defragment the drives within the guest itself. In order to shrink the *.qcow2 files, you'll need to zero out all free space of the drives/partitions contained within the guest first. Below is the process:
==Windows Guest Preparaton==
==Windows Guest Preparaton==
* Defragment your VM's Windows 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].
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].
* 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]. See either section below:
===Using SDelete===
===Using SDelete===
Line 18: Line 19:
** '''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.
** '''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.
==Shrink the Disk File==
==Shrink the Disk File==
These steps are all performed within the ProxmoxVE host shell.
* Shut down the VM.
* Shut down the VM.
* Log into the Proxmox shell and go to the VM's disk storage directory.
* Log into the Proxmox shell and go to the VM's disk storage directory.

Revision as of 15:04, 7 September 2012

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

Windows Guest Preparaton

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. See either section below:

Using SDelete

  • Download SDelete and save it somewhere on your system (eg. C:\windows\system32\).
  • Run SDelete and zero free space:
sdelete -z

Using Eraser

  • Download and install the latest 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.

Shrink the Disk File

These steps are all performed within the ProxmoxVE host shell.

  • Shut down the VM.
  • Log into the Proxmox shell and go to the VM's disk storage directory.
  • Note: These next two steps assume that source is your original disk and shrunk us the new shrunken disk. Change the file names to meet your needs.
qemu-img convert -c -O qcow2 source.qcow2 shrunk.qcow2
  • Backup the original disk file and move the shrunken disk into its place:
mv source.qcow2 source-bak.qcow2
mv shrunk.qcow2 source.qcow2
  • 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.