Compacting dynamically expanding virtual hard disks

Compacting dynamically expanding virtual hard disks

Warning

Compacting a virtual hard disk can use a large percentage of processor resources. We recommend that you do not perform this operation on a production computer. Compacting a virtual hard disk requires enough space to temporarily store the compacted file and the uncompacted file. This is because Virtual Server compacts a virtual hard disk by creating a new, compacted virtual hard disk and then deleting the original, uncompacted disk. If there is not enough space to complete the process, the problem is recorded in the Virtual Server event log.

Compacting a dynamically expanding virtual hard disk reduces the size of the virtual hard disk (.vhd) file as much as possible. Typically you would compact a virtual hard disk in situations such as the following:

  • After you install the guest operating system (which uses many temporary files)
  • After you delete large amounts of data
  • When you are preparing the virtual hard disk for archiving, for deployment to another computer or CD-ROM, or for distribution

You can compact a dynamically expanding virtual hard disk. You cannot compact any other type of virtual hard disk. However, you can convert a fixed-size virtual hard disk to a dynamically expanding virtual hard disk and then compact the disk. If you want to compact a differencing virtual hard disk or an undo disk, you must merge the changes to the parent disk and then compact the parent disk, if it is a dynamically expanding virtual hard disk. For instructions on converting disks, see Convert a virtual hard disk. For instructions on merging disks, see Merge a virtual hard disk.

To ensure that you get the smallest possible file size when you compact the virtual hard disk, you need to do some file system maintenance before you compact the disk. In the guest operating system of the virtual machine that is using the disk you want to compact, do the following:

  • Remove any temporary folders or unwanted folders or files.
  • Empty the Recycle Bin.
  • Defragment the disk.
  • Use a non-Microsoft disk utility program to "zero out" deleted data, which overwrites the data with zeros. When you delete files from a virtual hard disk, the data associated with the files is not actually removed until it is overwritten. Instead, the sector that stored the data is marked as available for use by the operating system. Zeroing out the data overwrites it with zeros, which enables the compact option to make the .vhd file smaller. When you compact a virtual hard disk, sectors that contain only zeros are removed from the virtual hard disk to reduce the file size.

After you complete the tasks described above, open the Administration Website to compact the virtual hard disk. For instructions, see Compact a dynamically expanding virtual hard disk.