Reduce the size of a virtual hard disk before delivery for reuse

When delivering a virtual hard disk to your team to build their virtual machines on I perform the following steps to minimize the size of the virtual hard disk. It is assumed that Virtual Server 2005 R2 SP1 is installed.

  1. Make sure you merged the Undo disks, and that differencing disks are merged with their parent disks
  2. Disable undo disks
  3. Start the virtual machine to compact
  4. In the virtual machine download CCleaner on http://www.ccleaner.com . This is a great tool to clean your disk from history files, cache files etc. I run this almost daily on my virtual machines and my host system. Thanks Danny for introducing me to this great tool.
    Quote from their website:
    CCleaner is a freeware system optimization and privacy tool. It removes unused files from your system - allowing Windows to run faster and freeing up valuable hard disk space. It also cleans traces of your online activities such as your Internet history. But the best part is that it's fast (normally taking less than a second to run) and contains NO Spyware or Adware! :)

    During installation beware of the option to install the Yahoo toolbar, you often overlook this co-packaging options from Microsoft, Google and Yahoo:
    clip_image002
  5. In the virtual machine run CCleaner with the options you prefer, my options are:
    clip_image004
  6. Shut down the virtual machine
  7. Mount the virtual hard disk to compact using vhdmount (part of Virtual Server 2005 R2 SP1):
    "C:\Program Files\Microsoft Virtual Server\Vhdmount\vhdmount" /p “drive:\folder\YourVirtualHarddiskToCompress.vhd”
  8. Go to Start > My Computer; Right-click and select Manage. Now defragment the disk mounted in step 6
    clip_image006
  9. "C:\Program Files\Microsoft Virtual Server\Vhdmount\vhdmount" /u /c “drive:\folder\YourVirtualHarddiskToCompress.vhd”
  10. Now start your virtual machine, and mount the ISO image C:\Program Files\Microsoft Virtual Server\Virtual Machine Additions\Precompact.iso. I personally use VMRCPlus to mount the ISO, right-click on CD-Drive and select Attach Media Image file… as shown in the screenshot below
    clip_image008
  11. When you navigate to the drive where the ISO image is mounted, the precompaction starts. The precompaction writes zero’s in all unused space in the disk, so the disk can be compacted in the next steps.
  12. Shut down the virtual machine
  13. Now start compaction of the virtual disk. This can be done in VirtualPC 2007, in the administrative web Virtual Server 2005, or in VMRCPlus, which I use here. Navigate to Tools > Virtual Disks > Inspect Virtual Hard disk, select your vhd to compact and select disk operation Compact
    clip_image010
  14. Done! Make your virtual hard disk read only, and start creating differencing disks based on your new base disk.

3 Comments

  • You could get even better results when you disable the Paging-file before compacting the disk. It makes no sense having a Paging-file in your base disk. Depending on the amount of physical memory it could save you a few hundred megabytes.

  • Well, this technique is really nice but a "little bit" complex.
    The fastest way with the best "compacting" results is to map virtual disk for reuse along with a new empty virtual disk. Boot Windows PE iso and GHOST drive to drive. Takes a minute or two (depending on the size of virtual disk for reuse) and the result is fully defragmented and absolutely clean (thanks to file approach of GHOST imaging). You can get 1.5 GB VHD with basic installation of W2k3 Server originally sized 2.6 GB.

    PS Sander: Page file is not a part of VHD

  • I huv a problem whenever i scan it reduces my disk space i tried everything advice from here and other places but it still didn't work help plz

Comments have been disabled for this content.