Friday, 12 March 2010

VHD disk images being read while VirtualPC is not running?

I setup a Virtual PC recently and noticed my hard disks were very busy lately. My VirtualPC is not on, but checking what files were being accessed (Task Manager --> Performance --> Resource monitor) I noticed that the VHD virtual disk image was being read a lot. Which is really odd as it's not in use.

The solution was to disble the service "Superfetch". Hey presto, all is quiet again.

Superfetch was trying to keep my system running fast by pre-loading the VHD into memory. Madness.

I've had superfetch turned off all day, and my hard disks's have never been so quiet.


Now, if only there was a way to exclude folders from superfetch...
Having a Google around there's no exclusion list, however, there is a way to refine what's going on via the registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters

Modify the EnablePrefetcher key to one of the following settings:

  • Disable Caching: 0
  • Cache Applications Only: 1
  • Cache Boot Files Only: 2
  • Cache Everything (default): 3

Experiment with this key to see if caching applications or boot files rather than everything still provides enough of a performance boost without getting bogged down.

Thursday, 11 March 2010

HOWTO: Compress Virtual PC virtual hard disks (.VHDs)

If you use Virtual PC 2007 you know that the virtual hard drive files (.VHDs) can grow to extremely large sizes. The .VHD files dynamically expand when software is installed in the .VHD. After installation, the original setup files are deleted and no longer take up space in the .VHD. However the .VHD does not correspondingly dynamically shrink in size. Once a .VHD file expands - it doesn't shrink.

EXAMPLE: If the installation of a product uses 500MB to expand its setup files and only really consumes 200MB in the "C:\Program Files\" directory, the .VHD file expands accordingly. When the 500MB of setup files are subsequently deleted after installation has completed, the .VHD file doesn't shrink afterwards.

That is wasted host storage.

So the question is:
How do I shrink the size of a .VHD when I know it's inflated unnecessarily?

Here's how to do it:
  1. Clear out the machine of filler
    Install ccleaner from  which deletes all temporary files from the Windows installation, Internet Explorer cache, Recycle Bin, and any number of other "garbage"/"temp" directories in the Virtual PC.
  2. Disable hibernation
    Go into Power options in Control Panel and disable hiberation to get rid of the large hybernation file.
  3. Capture the Virtual Disk Precompactor .ISO In the menu of Virtual PC windows for your machine, capture the Virtual Disk Precompactor .ISO file which is located at:
    x32:  C:\Program Files\Microsoft Virtual PC\Virtual Machine Additions\Virtual Disk Precompactor.iso
    x64: C:\Program Files (x86)\Microsoft Virtual PC\Virtual Machine Additions\Virtual Disk Precompactor.iso
  4. Run the Precompactor
    Go to My Computer and double click on the mounted disk. It will begin to run the precompactor software which will essentially zero out all the free space on the disk, making it available for elimination from the file by the Virtual Disk Wizard, which we will use later. This process may take upwards of 15 minutes depending on the size of the VHD file.
  5. Shutdown the Virtual PC
  6. Run the Virtual PC - Virtual Disk Wizard
    From the Virtual PC console, click File --> Virtual Disk Wizard and "Edit an existing virtual disk" It will ask you to identify the .VHD file to reduce in size - select it.
  7. Compact the .VHD
    Select the "Compact" option then select "Replacing the original file". This again will take a while.
When this process finishes, you should have a .VHD file with a much smaller size.

The other final thing you can do is on your host PC, right-click and compress the folder:
C:\Users\Public\Downloads\My Virtual Machines

As an example:
  • Before compression: The size of my 8Gb VHD file (windows xp 32bit) was reported as only taking 3Gb physical space due to folder compression.
  • After compression: After following the steps above, the VHD file was 3.5Gb and was reported as taking 2.6Gb physical space due to folder compression.