Microsoft Virtual Server and Virtual PC Windows Guest Optimization

Keeping a Windows virtual machine running well using a Microsoft virtualization system is fairly simple, and here are the best practices that I’ve come up with (through trial and error and reading).

First, if you use Virtual Server rather than Virtual PC make sure you’re using SCSI disks, and regardless, always try to use the most current virtual tools in your guest.

Second, if you use dynamically expanding disks you need to compact them occasionally to decrease the size; you might as well defrag them in the guest before doing the compact and clean off unnecessary files as well; and if you have the time, defragment the host as well.  The reason for keeping the dynamically expanding disks as small as possible is caching and head travel — small is good.

Third, if you’re running something like SQL server inside a virtual machine, or software that tends to grow and shrink the store, consider using a pre-allocated disk rather than a dynamic one, it will probably be much better in the long run.

 

Now, here are a few of the “tools” I use to make my life easy.  first, I create a batch file that contains:

  1. if EXIST “C:\Program Files\OO Software\Defrag Professional\oodcmd.exe” set oodcmd=”C:\Program Files\OO Software\Defrag Professional\oodcmd.exe”
  2. if EXIST “C:\Program Files\OO Software\Defrag Server\oodcmd.exe” set oodcmd=”C:\Program Files\OO Software\Defrag Server\oodcmd.exe”
  3. REM Disk Clean
  4. regedit /S cleanmgr-0666.reg
  5. start /WAIT cleanmgr /sagerun:666
  6. REM Defrag
  7. %oodcmd% /COMPMOD:ALL
  8. REM pre-compactor
  9. precompact -silent
  10. REM shutdown
  11. shutdown /f /s /t

I use O&O Software’s OODefrag to defragment my disks; some of my machines have the professional version installed, and some have the server version installed; so lines 1 & 2 just figures out which of the versions is installed.

Line 4 setups up for calling the disk cleaner manager, because Microsoft really didn’t create a very good command line interface to it, you have to write a job detail into the registry.  You actually only need do it once, but rather than see if it’s there, I just write the “current” version to it.  666 is an arbitrary choice of labels.  I put a copy of what’s in the reg file at the end of the post, use MSDN to decipher it.

Line 5 invokes the disk cleaner manager with the job that was setup in line 4.

Line 7 defragments all the drives.

Line 9 invokes the precompactor (comes with virtual server, but works for virtual pc as well).

Line 11 shutsdown the system.

After the system is shut down, you need to run the compactor from the host, you can invoke that with Virtual Server with a script, or through the web interface (inspect disk); with Virtual PC you’ll need to do that with the virtual disk wizard.

After the compactor is finished, consider defragmenting your host disk (at least occassionally).

I actually have permutations of this procedure for use with Parallels and VMware.  Both Parallels and VMware have an interface for this, but it really doesn’t do that great of a job in the guest, so you can definitely improve on it by doing the same procedures I do for the Microsoft products before calling their “built in” functions.

 

If you use UNDO disks and always throw away your changes, you only need to do this procedure once (with UNDO turned off), degragment the host files, then enable UNDO.  Since the base disks never change (until you need to apply service packs, patches, etc), you never need to worry about cleanup.  But don’t let UNDO disk change sets grow extremely large or your performance will suffer.

One more word of advice, if you copy your virtual machines (and this is true of any of the virtualization systems), make sure you allow the virtualization software to create a new descriptor file (to avoid MAC address duplication, though Virtual Server can handle this), and make sure you run NewSid.exe (or a similar program) in a Windows host to change it’s name and security identifier.

________________________________________

cleanmgr-0666-reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches] [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Compress old files] “StateFlags0666″=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Content Indexer Cleaner] “StateFlags0666″=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Microsoft_Event_Reporting_2.0_Temp_Files] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Remote Desktop Cache Files] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files] “StateFlags0666″=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\WebClient and WebPublisher Cache] “StateFlags0666″=dword:00000002

 

Originally posted 2008-05-18 20:46:42.