Keeping clean and small Virtual Machines
I have about a dozen virtual machines that I use for development and other purposes. I normally have 4-5 running at anyone given time on my development machine, and I also do development on the host as well.
I use desktop virtualization because it has better desktop integration with the host with things like the clipboard, drag and drop of files between them, mouse and keyboard interaction, and graphics performance in most cases is better.
The contest between Microsoft and VMWare in the server virtualization space is hot and competitive with both offering compelling features. The desktop space is no contest however with VMWare Workstation simply obliterating Virtual PC.
I am looking closely at Hyper-V as well, however it only runs on Windows 2008 server. Each time I've used a server operating system as my host I run into third party packages that fail to install on server operating systems or charge ten times the amount to purchase the software as the version for desktop operating systems.
This also requires a decent backup strategy. Virtual Machines take up more space than raw data, but there are ways to keep the size down as well as keep them running efficiently.
Separate the Swap
The amount of RAM I allocate to my guests varies from 256 MB to 1024 MB. In general Windows will make a swap file about the same size as memory. Backing up the swap file makes no sense and takes up a lot of room.
To avoid this, make a second virtual disk 2 GB in size and from within the guest operating system move the swap file to the second disk. After reboot you will need to then delete the swap file from the C: drive. You should also perform a shrink disk after deleting it.
You should also turn off the low disk warning for the swap drive so Windows will not annoy you with the system tray pop up each time you boot.
Now you can back up the virtual machine, but exclude Swap.vmdk. If you ever need to restore, just create another virtual disk and reset the swap file in the guest operating system.
Turn off system restore for all drives in the guess operating system. You are backing up the whole virtual machine anyways so you can always revert to a backup if you need such functionality.
Uninstall services and applications that you do not need. A full Windows XP install including Microsoft Office and basic dev tools easily fits in about 5 GB. Such a virtual machine compresses with RAR on best setting down to 1.5 GB. With this strategy you have plenty of room to grow and keep your virtual machine backed up on a single DVD.
From within the guest operating system:
- From explorer options, turn on "Show hidden and system files". Now go to c:\Windows and you will see many folders that start with $xxxxx, where x are numeric digits. These are uninstall files for Windows Updates, and they take up quite a bit of room. Delete all of them. Do not delete $hf_mig$ or $Reconfig$
- Run disk clean up wizard and allow it to take all actions except compress old files.
- Delete c:\Windows\*.log. WindowsUpdate and a few others may give you access denied, but delete the rest. Several of the log files are over a megabyte and they add up as well.
- Delete the contents of the c:\Windows\SoftwareDistribution\Downloads folder. You can actually delete all the contents of c:\Windows\SoftwareDistribution but you will loose your update history. The downloads folder contains updates that are already installed and accounts for most of the data by size. For example my SoftwareDistribution folder was 205 MB, 199 MB of which was in the Downloads folder. Eventually Windows cleans this folder up, but you can safely delete it as these updates are already applied on your system.
- Open VMWare tools and select Shrink Disks.
There are tools to mount VMWare virtual disks from the host and these steps 1 to 4 could be automated to run without needing to boot the guest.
For step 4, there is a vmware command line utility that can shrink the disks. I guess I need to make a nice FinalBuilder script to do this all. Or maybe the FinalBuilder guys could add some nice new VMWare actions including mount disk, shrink disk, etc.
Before backing make sure the virtual machine is powered off and not just suspended or in snapshot mode. Now delete any folders that match *.lck, and *.log files. Use RAR on best compression and compress the remaining files excluding Swap.* (Assuming you named your swap virtual disk Swap). Unless you have really bloated your virtual machine, the resulting file will easily fit on a single DVD. If not you can set RAR to split the files at 4300 MB and burn more than one DVD.
Third Party Tools
- Invirtus vOptimizer - vOptimizer can peform many of these tasks for you in an automated fashion. I have not yet tried it myself but have read mixed reviews about it. Additional feedback on this product is welcome.
- Parallels Compressor - Parallels compressor works on VMWare as well as Virtual PC.
- Perfect Disk - Its buried down in one of the whitepapers, but there is an interesting feature:PerfectDisk 2008 for VMWare goes beyond basic disk degragmentation by automaticaly degragmenting host disk drives and virtual disk drives of VMWare workstations and VMWare servers, and reclaims disk space by shrinking the virtual drives.
Use my contact form to contact me directly.