After many trial and error runs, I’ve finally been able to reduce my fully updated Windows XP SP2 Virtual Machine to aÂ rather leanÂ 802 MB (uncompressed) 276 MB (compressed). WOW!! 🙂
Â In order to get the XP VM at a reasonable size, follow these steps:
*You must be using a Dynamically Expanding VHD, I’ve not tested the other formats VPC supports!
- Clean your VM by removing all unnecessary programs/documents.
- Defrag your drive, use Dave Whitney’s Defrag Utility (no need to install anything!) It works 10X better than Windows bulit-in defrag utility by completely evacuating files and then replacing them.
- Run a disk Pre-Compactor program, if using Virtual PC, mount the included Pre-Compactor under “Virtual Machine Additions” in the Virtual PC install directory. Immediately shut down the VM.
- Load the Virtual Disk Wizard and select “Edit an existing virtual disk”, enter the location of your vhd file and selectÂ “Compact It”Â then “Replacing the original file”.
- Watch your vhd file shrink like crazy!
This entire process could literally take a couple hours to 10 minutes, depending on the size of your vhd.
- To reduce the size of your vhd, turn off the paging file temporarily, then defrag. Try leaving the paging file off for now, you can always turn it back on. This freed up 500MB of space, I’ll turn it back on later, XP will tell me it needs it when it needs it! 🙂
- Don’t just defrag once, it took meÂ 4 defrags to get my vhd to the size it is at…
- Remove XP’s default loaded games, they take up 13 MB.
- Only use Windows defrag utility to view a graph of your drive to check for fragmented files. You should see a solid blue bar followed by a solid green bar. The Windows defrag utility works, but not good enough!
“What does the pre-compactor do for the VHD?”
To understand how the pre-compactor works, you need to understand how a standard hard drive works!
When a hard drive saves data to the disk, it attempts to place all the data in a contiguous form. If data is deleted, that leaves a blank hole on the disk where data used to be stored. Now, for example, you install a program that takes up a large portion of your hard disk, the hard drive will fill in data where you previously deleted thusÂ the new data will be fragmented or scattered throughout the various holes on the disk!
In a typical hard drive, when data is deleted the hard drive “un-links” the data from the OSÂ so you cannot access it, but it is technically still written on the hard drive until it is overwritten by new data. This is why there are data recovery specialist in the world! 🙂
The same is true in a virtual environment! Since your virtual hard disk is continuously expanding, it sees this “un-linked” data as good data and keeps it stored in the VHD file which is really just wasted space! The pre-compactor program finds these data chunks and permanently deletesÂ them by writing zeros in place of that data. The VHD compactor is able to then remove zero-ed data from your VHD file, thus reducing the size of the VHD!
“What is the whole purpose of compacting your VHD??”
Well,Â it really depends on what you’re doing withÂ your Virtual Machine! It all boils down to efficiency when sending the VHD across
In our environment, we useÂ VPC as a testing tool. When we need a fresh install of XP to test a new solution we grab our VHD from the network, load it in VM,Â and test away.
Unfortunately, installingÂ aÂ freshÂ XP each time you want to testÂ takes a little while… It is far more efficient to stage a fresh XP and store it on the network, to be downloaded whenever needed. Changes can be made on an “Undo Disk”, which is a great feature of VPC 2007, thereby always maintaining a fresh XP VHD!