I was playing this weekend trying to get the VHD (Virtual Hard Disk) size down to the barest minimum. I thought I did OK – WS2003 SP1 with Support Tools, Admin Pack, Group Policy Management Console, Small Office 2003 installation running Word+Excel patched with Office SP1 and latest security fixes, sysinternals background info, Security Configuration Wizard and a few more utilities in just under 1MB as viewed from inside the VM.
On the host Virtual Server though, the image was some 2.5GB – a far cry from 1MB. Getting the disk size as small as possible is really important for me when building many machines for demonstration. Disk space is an expensive commodity on a slowish 80GB laptop hard disk, and also size is directly proportional to overall performance. With a bit of patience, it is possible to get the VHD size down on the host to 1.2GB in this configuration. Here’s some of the stuff I did which I hope you find useful:
– Change the page file on the VM to start at 16MB
– Delete *contents of* c:\windows\system32\dllcache
– Delete *contents of* c:\windows\cursors
– Delete *contents of* c:\windows\inf
– Run the disk cleanup wizard
(Note- there are many others things you _could_ delete, but this gets the big ones)
– Defragment the disk ***at least 5 times****
– Precompact the hard disk (you need VPC2004 SP1 for this – I see another blog entry coming on)
– Compact the hard disk in VS admin
– Select “Virtual Disks/Inspect”
– Find your .VHD file
– Select “compact”
– Wait 20 mins or more 🙂
For some more minimal shaving of space…. After doing the above, the VHD file was down to 1.3GB – some 340MB+ bigger than the data actually being used by the Virtual machine. I tried converting the VHD from an expanding disk to a fixed disk, and then back to an expanding disk again. This gave no improvement in disk size.
However, once you have the fixed disk, start the virtual machine up and precompact once more. (I also did a defrag again, just for good measure). Shut the machine down and convert it back to expanding disk again before finally compacting it. Net result – no change. However, sticking with the full-size disk, pre-compacting it, converting it back to expanding disk and compacting it again did shave a further 80MB off. Hence, hence net result 1.22MB which I thought wasn’t too bad.
So, can you do better or have any additional tricks?