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.
Published Tuesday, January 15, 2008 12:55 AM by svdoever
Filed under:

Comments

Thursday, January 17, 2008 6:39 AM by Sander Schutten

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

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.

Sunday, January 20, 2008 6:52 PM by lzandman

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

I prefer using VisionCore's vOptimizer (www.vizioncore.com/vOptimizer.html) to shrink virtual harddisks. At the click of a button it can shrink VHD's from both Virtual PC and VMWare. It costs about $80, which isn't very much I think.

Greetz,

Leon

Thursday, February 07, 2008 11:05 AM by Dawid

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

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

Sunday, February 24, 2008 8:15 AM by Saif

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

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

Sunday, June 29, 2008 8:49 PM by Dave Black

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

Be careful using vOptmizer by VizionCore.  They DO NOT support Vista x64, have no plans for doing so, and have crappy technical support.

Leave a Comment

(required) 
(required) 
(optional)
(required)