OpsanBlog

Michael Coates - Microsoft Pragmatic Evangelist

My Latest Tweet

     

    MIX by the numbers, baby!

    Posted with:
     Windows Live Writer
     Download Live Writer

    My Windows Live Local Collections:
     Las Vegas
     Los Angeles
     San Jose
     Seattle
     Washington, DC
     My Walks

    Article Categories

    Archives

    Post Categories

    Bloggers

    Optimize Virtual PC 2004 Images

    When working in the VPC environment, you may notice notice growth in the the virtual hard disk (.VHD) files.  As files are saved within the VPC environment, dynamic VHDs will expand to meet the need.  However, the VHDs do not return the space to the host hard drive without manual optimization.

    No warranty, expressed or implied. This is just a record of what I did.  Please be sure to read the entire article before doing anything; I had some issues with VPC SP1, for which I provide a workaround.

    Notes:

    • The compacting and zeroing operations require VPC Service Pack 1.
    • Make a backup of the VPC image before performing optimization.
    • Do not perform optimization without shutting down the VPC image to be optimized (i.e., do not perform optimization on a "saved state" VHD).
    • These steps assume an administrator account.
    • You will need lots of disk space on the host to perform these operations; the VHD file will grow during the process prior to optimization and the optimization process iteself takes space roughly equivalent to the size of the VHD being processed.

    Steps:
    Defragment the host drive(s).  Prior to defragmentation:

    • Empty the recycle bin on all HDDs on the host.
    • Disable hibernation while defragmenting the drive containing the 'hiberfil.sys' file. Doing this should remove the file, but if it doesn't, remove the file manually once hibernation is disabled and reboot.
    • Unmount/move/remove any unused VPC/VCD/ISO images while defragmenting.  Restore them after defragmenting is complete.

    Note: if your images are stored on a data drive (say D:\), the drive to which the TEMP environment variable points (typically C:\) will also need to be cleaned and defragmented.  The compacting process uses significant temporary space.

    Now we can defragment the drive.  In Windows Explorer:

    • Right-click the hard drive to defragment.
    • Click the "Tools" tab.
    • Click "Defragment Now". 
    • Have a cup of coffee, as this will take some time, depending on the size of your hard drive.

    Repeat the process for the system and data HDDs.

    Remove unnecessary items from the VPC image.

    Notes:

    • Your individual needs will be the ultimate determining factor as to applications, backups, etc. 
    • The steps below assume a Windows Server 2003 SP1 virtual image.
    • Start your VPC image; do NOT perform these steps on the host.
    • Use 'Shift-Delete' when deleting files so the files are not moved to the recycle bin.

    Remove the paging file on the virtual computer:

    • Log in as an administrator account.
    • Click Start, Settings, Control Panel, System, Advanced, Performance, Settings, Advanced.
    • Click the Virtual memory section and click Change.
    • In the Virtual Memory dialog box, under "No Paging file", click Set, Yes and OK.
    • Click OK to all changes and close System settings.
    • Reboot the VPC.

    Clear the DLL cache on the virtual computer:

    • Log in as an administrator account.
    • Open a command prompt; click Start, Run, type "cmd" and click OK.
    • At the command prompt type "sfc /cachesize=1" and press enter.
    • Close the command prompt window.
    • On the Start Menu, click Shut Down.
    • In the Shut Down Windows dialog box, click "Operating System: Reconfiguration (Planned)" with "DLL Cache Cleared" as the reason and click OK.

    Purge the DLL Cache on the virtual computer:

    • Restart the VPC.
    • Log in as an administrator account.
    • Open a command prompt; click Start, Run, type 'cmd' and click OK.
    • At the command prompt type "sfc /purgecache" and press enter.
    • Close the command prompt window.

    Clear the C:\Windows\Driver Cache\i386 folder on the virtual computer:

    • In Windows Explorer, navigate to C:\Windows\Driver Cache\i386.
    • Select the "driver.cab" file and click Shift-Delete.

    Clear the C:\Program Files\WindowsUpdate folder and Update uninstall programs on the virtual computer:

    • In Windows Explorer, navigate to C:\Program Files\WindowsUpdate.
    • Select all files in this folder and delete.
    • Navigate to C:\windows and highlight all the $NTUninstall$ folders left behind by Windows Update.
    • Click Shift-Delete to delete the files.

    Note: Do not remove "$hf_mig$". See "Description of the contents of Windows XP Service Pack 2 and Windows Server 2003 software update packages" for details.

    Clear the C:\Windows\System32\WBEM\Autorecover folder on the virtual computer:

    • In Windows Explorer, nagivate to C:\Windows\System32\WBEM\Autorecover.
    • Select all files in this folder and click shift-Delete.

    Clear the C:\Windows\Web\Wallpaper folder on the virtual computer:

    • In Windows Explorer, navigate to C:\Windows\Web\Wallpaper.
    • Select all files in this folder and click shift-Delete.

    Stop any application services on the virtual computer:

    • Check for BizTalk, MSSQL, MSSQL AS, MSSQL RS, etc.
    • Stop these services.

    Delete unnecessary log files on the virtual computer:

    • In Windows Explorer, right-click the C:\ drive icon and click Search.
    • In the Search Results window, select the 'All or part of the file name' text box and enter '*.log'.
    • Click the Search button.
    • In the results window, select all the files EXCEPT for the following:
      • C:\Windows\debug\PASSWD.log
      • C:\Windows\debug\usermode\chkacc.log
      • C:\Windows\SoftwareDistribution\edb.log
      • C:\Windows\SoftwareDistribution\ReportingEvents.log
      • C:\Windows\WindowsUpdate.log
      • C:\Windows\system32\msdtc\msdtc.log
      • C:\Windows\system32\msdtc\trace\dtctrace.log
      • C:\Windows\system32\wbem\logs\wmiprov.log
    • Delete all files except those above by pressing Shift-Delete.  You may find other files that cannot be removed; exclude them from the deletion process as you encounter them.

    Set and clear Event Logs on the virtual computer:

    • Open Event Viewer
    • For each log, perform the following steps:
      • Click the Action menu and Properties.
      • Set the Maximum log size to 512.
      • Select "Overwrite Events as Needed" (creating a circular log).
      • Click Clear Log (without saving)

    Clear the temp directory on the virtual computer:

    • In Windows Explorer, right-click Start and click 'Explore all users'.
    • Navigate to the current logged-in user, click Local Settings, and Temp.
    • Select all files and delete.  If you encounter files that are being used by the system, exclude them from deleting.

    Some other optimization opportunities on the virtual computer:

    • Disable the clock.
    • Use ClearType instead of the default smooting screen fonts (Display, Effects).  Skip this if you're using the image to present on a projector as it may make it difficult for the audience to read.

    Defragment the virtual disk on the virtual computer:

    • Empty the Recycle bin.
    • Open the My Computer icon.
    • On the File Menu, right click C:\ drive and click properties.
    • On the Tools tab, click Defragment now.

    At this point, if you have not installed VPC SP1 on the host, you will need to do so.  Shut down the VPC (do not save state) and apply the Service Pack to the host.  Restart the VPC once SP1 is applied.

    Mount the Virtual Disk Precompactor on the host:

    • Using an ISO-as-CD utility (I use Daemon Tools), mount the “Virtual Disk Precompactor.iso“ file from “C:\Program Files\Microsoft Virtual PC\Virtual Machine Additions“.
    • If you have AutoPlay, the application will prompt you to prepare the disk for compaction. Say “No“ (you won't perform this action on the host drive).

    Zero the free space on the disk on the virtual computer:

    • Log on to the virtual machine as an administrator.
    • Confirm application services (MSSQL, BizTalk, etc.) are stopped.
    • In the CD menu of VPC, use the physical drive you just mounted. The application will prompt you to perform the precompact; answer "yes".
    • Once precompacted, the application will prompt you to shut down.  Before doing so, clear the event logs and temp directory.

    Compress the virtual hard disk:

    • In the Virtual PC Console on the host, click File, Virtual Disk Wizard.
    • On the Welcome page, click Next.
    • On the disk options page, select “Edit an existing virtual disk” and click Next.
    • On the Virtual disk to Edit page, browse to the location and file name of the VHD file and click Next.
    • On the Virtual Disk Information and Options page, ensure “Compact it” is selected and click Next.
    • On the Virtual Hard Disk Compaction page, select “Replacing the original file“, unless you want to save the new file under a different name (prudent, but requires more disk space).

    The process will take several minutes; click Finish when complete.

    Once the disk is compacted, restart the VPC:

    • Add a Windows-managed paging file.
    • Restart/Autostart any services you stopped during the process.
    • Test, before deleting the original image backup.

    This process reduced the size of a 512MB RAM VHD containing Windows 2003 Server with SP1 from 3.038GB to 1.756GB (with the new paging file).

    This process reduced the size of a 512MB RAM VHD containing Windows 2003 Server with SP1, MSSQL, VS.NET, BizTalk and a variety of other developmen tools from  from 7.833GB to 5.117GB (with the new paging file).

    posted on Tuesday, May 10, 2005 8:38 PM

    Feedback

    # re: Optimizing Virtual PC 2004 Images 7/7/2005 3:48 AM John Paul Cook

    Zeroing out bits and using the compaction tool takes far longer than using Ghost, plus Ghost (or any similar product) provides better compaction. A quick summary of the steps can be found at http://www.dbazine.com/sql/sql-articles/cook14.

    # Optimizing Virtual PC 2004 Images on Windows 2000 7/19/2005 6:11 PM John Paul Cook

    Do not run sfc /purgecache on a Windows 2000 machine.

    # re: Optimizing Virtual PC 2004 Images 7/29/2005 9:23 AM syassy

    Why must not run sfc /purgechache on a W2K machine ?

    # re: Optimizing Virtual PC 2004 Images 8/31/2005 10:28 AM John Paul Cook

    Running sfc /purgecache causes Windows File Protection to start. WFP asks for the installation media.

    # re: Optimizing Virtual PC 2004 Images 8/31/2005 11:57 AM opsan

    I saw that on a physical server the other day, but never on a VPC. I don't know if WFP is doing a comparison or a 'get' from the original media. Inserting the CD should allow it to proceed.

    # re: Optimize Virtual PC 2004 Images 10/6/2005 6:03 PM syassy

    Oh I see. Fortunately, WFP did not bother me despite my running sfc /purgecache on W2K machine.

    I will take care of myself about running sfc at next time. Thank you anyway.

    # Is your Flash drive a PC experience or file repository? 10/9/2005 3:39 PM OpsanBlog

    # Is your Flash drive a PC experience or file repository? 10/9/2005 6:02 PM OpsanBlog

    # re: Optimize Virtual PC 2004 Images 12/1/2005 4:33 AM JRH

    Instead of using a 3rd-party tool to mount the Virtual Disk Precompactor on the host and then capturing that "drive" on the VPC, why not just use the CD|Capture ISO Image function on the VPC window?

    # re: Optimize Virtual PC 2004 Images 12/1/2005 9:57 AM Michael Coates

    Great comment, thanks for posting it. When I wrote this article, I didn't know about the capture ISO function.

    I'll redo the post when I get a few minutes after this mad world tour I'm on.

    Thanks again.

    # 3rd party tool vs. Capture ISO 12/10/2005 9:37 AM John Paul Cook

    Capture ISO on VPC has a 2 gb limit. You still need a third party tool or Microsoft's unsupported Virtual CD Control Panel: http://download.microsoft.com/download/7/b/6/7b6abd84-7841-4978-96f5-bd58df02efa2/winxpvirtualcdcontrolpanel_21.exe

    # Virtual Server r2 : premiéres impressions 4/19/2006 6:29 AM The Mit's Blog


    Suite aux techdays et moultes dicussions avec Pierre Lagarde et Bernard Fedotoff, je me suis tenté...

    # What about deleting sp1.cab or sp2.cab? 5/8/2006 5:49 AM John Paul Cook

    Within C:\Windows\Driver Cache\i386, there can also be sp1.cab or sp2.cab. Should/can this be safely deleted along with drivers.cab?

    # re: Optimize Virtual PC 2004 Images 8/30/2006 8:17 PM William A Cromarty

    Everyone is trying to recover more space, But I want to increase the size of my current windows 2003 Image above 50 GIG, So I Can Copy a SQL DB on to the virtual machine. It keeps telling me there is not enough space it auto grew to 13 GIG and seem to have stopped. Any one have any ideas on how to make a Virtual PC 2004 Image very big, perhaps upto 100 gigs, The host computer can have terribytes of Space available if needed, so its not the host that is limiting it.

    # re: Optimize Virtual PC 2004 Images 8/30/2006 11:19 PM opsan

    My guess: you can convert the VHD image to a fixed hard disk instead of a dynamic hard disk (the dynamic disk increases in size, but not always as quickly as you'd like).

    Use the VPC console and run the Virtual Disk Wizard. You'll see the 'fixed disk' option.

    # re: Optimize Virtual PC 2004 Images 8/31/2006 8:10 AM William A Cromarty

    I looked at this befor, but never actually tried it, It looked like there was no options for setting the fixed size. Well I just did it and as expected There was no option for setting the size. Any Ideas on how to set the size of a fixed size Virtual Dist or a Dynamic HD.

    # re: Optimize Virtual PC 2004 Images 8/31/2006 9:01 AM opsan

    Ah, I see you cannot set the size of the fixed disk. This means you'd have to recreate the VPC with the desired fixed size in the beginning.

    A workaround might be to load very large files (from the sounds of your first comment s-l-o-w-l-y) and then convert to fixed disk.

    I've never worked with a fixed disk; I'm curious what options you have once the size is set to fixed. Might tinker with that later.

    I dug about a bit; there are some third-party products that refer to fixed disks, but nothing specific. You might check the forums.

    Oh. Duh; perhaps the most obvious: take a look at Virtual Server: http://blog.opsan.com/archive/2006/04/06/25379.aspx. It's now available as a free download.

    HTH

    # Optimisez ses VPC : optimisation et compression 9/4/2006 8:23 AM The Mit's Blog

    Comme beaucoup le savent déja, je suis un afficionados de la virtualisation.

    Vm Ware depuis la version...

    # re: Optimize Virtual PC 2004 Images 9/18/2006 3:17 PM Luc

    I did everything mentioned here. 4G became 3.7G. (???) I don't know where I did wrong.

    # re: Optimize Virtual PC 2004 Images 9/18/2006 3:52 PM opsan

    I just posted "Virtual PC is now free" at http://blog.opsan.com/archive/2006/09/18/70809.aspx.

    This should make it easier to get the right version on your PC / laptop.

    # re: Optimize Virtual PC 2004 Images 12/21/2006 10:38 PM Steve Harman

    Great post Mike... I was only able to reduce my .vhd file by about 2.2GB (from 8.9 to 6.7) but I still consider that to be pretty good for a fully loaded and configured dev box (WinXP SP2, Visual Studio 2005 SP1, SQL Server 2005 Dev Edition, version control tools, etc...)

    Thanks again!

    # re: Optimize Virtual PC 2004 Images 12/25/2006 9:10 AM Fred

    I have two VPC files. Both of them are running W2003 R2 standard edition. Both are using fix hard drive size -- 27G Yesterday, I perform the defragmentation on my first one. After that, the system CAN NOT be logged on when I click on ctrl-del-alt menu item. So I brought up another VPC and assigned the broken one as my second hard drive. I can see the contents of them.
    Has anyone here experienced such problem?

    # re: Optimize Virtual PC 2004 Images 4/8/2007 6:07 PM aaronelmore

    is it possible to convert .vpc files to a true running/booting os environment? i.e. .vpc to bootable hdd

    # Convert VPC files to a physical machine - V2P 5/30/2007 9:50 AM John Paul Cook

    Yes aaronelmore, this can be done. It is a Virtual to Physical conversion, often referred to as P2V. Some companies build their standard images in a virtual environment before deploying to physical machines. Just be sure you include the drivers for the physical machines in the virtual machine. Image copy out of the virtual machine to a physical environment.

    # re: Optimize Virtual PC 2004 Images 7/18/2007 6:50 AM Lance Garcia

    I had follow you instructions correctly and i have compacted my .vhd file but it also created two other files a .vo1 and .vo2 and it has not reduced the size of the file enough. i want to remove these files but the vm cannot load without them. what should i do?

    Title  
    Name  
    Url
    Comments   

    The opinions expressed herein are my own and are not intended to represent those of my employer.