Recommendations for MED-V Image Optimization: Reducing the Image Footprint
MED-V leverages virtual machines and guest operating systems to provide seamless integration for legacy applications, and the seamless integration of these applications into the host desktop is proving to be an excellent way of resolving application compatibility concerns for Windows Vista and Windows 7 (with MED-V 1.0 Service Pack 1.)
Virtual machines leverage virtual hard disk images (.VHDs.) With the use of virtual machines, optimization of virtual machines is necessary to reduce transfer times and image footprint costs when leveraging image distribution servers or other methods such as SCCM. The bottom line is the deployment of images needs to be as optimized as much as possible to reduce delivery times for images and to make more efficient use of network bandwidth. A key ingredient to optimizing image distribution requires compressing the image to the smallest size possible.
The MED-V image packing process (performed in the MED-V Management Console) is often able to reduce the original .VHD files down to 50% of their size in the Compressed Kidaro Format (.CKM). While in the case where a 7-8 GB VHD can get compressed in half to 4 GB by simply packing the image, the image size can be further reduced by implementing pre-packing and pre-compaction procedures.
I am often asked how to fit the procedure into the overall procedure for workspace image preparation. I have found doing this right after everything else in the preparation process with the exception of running sysprep (needed for domain-managed images.) The pre-compaction process basically consists of the following actions:
- Uninstalling unnecessary applications
- Removing unnecessary files and folders.
- Defragment all volumes.
- Run precompaction utility.
- Offline file removal.
- Edit/Compact Disk.
In the example below, we have a Windows XP virtual machine that is currently using a .VHD that is 6.54 GB. I will use this as an example for demonstrating the process. It almost goes without saying that this is also using dynamically expanding virtual hard disks. While fixed-size virtual hard disks can be used with MED-V and packed into CKM images, they will not be able to be pre-compacted or reduced in size prior to packing the image into a CKM image file.
Uninstall Unused Programs and Delete Unnecessary Files
Start the virtual machine, and then remove all nonessential files from the virtual hard disk that you want to use for deployment. Bear in mind that this will be a decision based on the applications and operating system components you will or will not use with the deployed image.
Here are some suggested items you might want to consider deleting (NOTE: These are only suggestions. Each one must be weighed against post-deployment image use.)
- Uninstall any software not being used (in the Control Panel – Add/Remove Programs)
- Remove Windows components not being used (in the Control Panel – Add/Remove Programs)
- Remove Service Pack uninstallation files and additional uninstallation files from updates (NOTE: This will prevent uninstallation of these updates and hotfixes)
- Remove all temporary files.
- Remove all unnecessary user profiles (local and locally cached roaming.)
Defragment all Volumes
It is recommended to defragment the volume prior to pre-compaction. Dynamically expanding .vhds that may be heavily fragmented will not compact well.
Depending on the operating system inside the VM, the defragmentation steps may vary slightly. All guest operating systems supported by MED-V version 1 have a built-in disk defragmentation utility. One universal method is the following:
1. Click Start, and then click My Computer.
2. Right-click the hard disk that you want to defragment, and then click Properties.
3. Click the Tools tab, and then click Defragment Now.
4. Click Defragment.
Another way is to access the utility directly from within the Computer Management MMC snap-in.
You can also do this from the command prompt. To do this, follow these steps:
1. Click Start, click Run, type cmd, and then click OK.
2. Type defrag /? to view a list of the available options for the Disk Defragmenter tool.
Run the Precompaction Tool
Once all unnecessary removable files have been deleted and the drive has been defragmented, you can now, while remaining in the virtual machine, run the Virtual Disk Precompactor tool to prepare the virtual hard disk for compacting. In order to do this, you must first capture the Virtual Disk Precompactor ISO file and mount it as a CD/DVD drive in the virtual machine. You can find Virtual Disk Precompactor.iso in the following folder:
%systemdrive%\Program Files\Microsoft Virtual Server\Virtual Machine Additions\
If your virtual machine is running when you capture Virtual Disk Precompactor.iso, Virtual Disk Precompactor starts automatically. If you click Yes when you are prompted, Virtual Disk Precompactor pre-compacts all the virtual hard disks for this virtual machine. If Virtual Disk Precompactor does not start automatically, you can start it by browsing to the CD drive of the guest operating system and double-clicking Precompact.exe.
Once the disk has finished, you can then run the VM Pre-requisites Tool, and SYSPREP to finish preparation of the MED-V Workspace.
Offline File Removal
After the virtual machine has been shut down, it is also recommended to mount the VHD as a drive from within Windows 7 or Windows 2008 R2. One of the nice new features about Windows 7 is the capabilities of removing additional files within the VHD after it has shut down by mounting it as a drive within the disk management tool.
To mount a VHD from the Disk Management snap-in in Windows 7, do the following:
1. From the Start button, navigate to “All Programs” or “Control Panel” and select “Administrative Tools.” Then select “Computer Management.”
2. Under “Storage,” right-click “Disk Management” and select “Attach VHD.”
3. Select the VHD you want to mount as a drive.
The drive will now show as an additional drive that can be accessed directly from the host by drive letter.
An alternative to using the GUI, is the diskpart.exe utility in Windows 7 or Windows Server 2008 R2. To prepare the VHD for servicing from the command line, attach the VHD using the DiskPart tool. At an elevated command prompt, type:
diskpart
select vdisk file=c:\windows7.vhd
attach vdisk
assign letter=v
exit
The VHD appears as a lettered drive on the computer.
Once we have the drive mounted, we can proceed to remove some addition files. The files to remove are:
- Pagefile.sys (File will be created upon initial startup of guest OS post-deployment.)
- Hiberfil.sys (if still there.) Power Management Features such as “Suspend” should be disabled in the guest operating system.
After you have removed the files, dismount the VHD by right-clicking on the disk and selecting “Detach VHD” from within Computer Management or with the diskpart utility. Be sure NOT to select the option to delete the VHD.
Compress the Disk using the Virtual PC Edit Disk Feature
Finally, you will need to compact the VHD using the Virtual PC edit disk feature:
- Start Virtual PC
- From the File menu, select “Virtual Disk Wizard.”
- Click “Next” and then select “Edit an Existing Virtual Disk.” Click “Next.”
- Select the VHD. Then click “Next.”
5. Select “Compact it” for the option. Click “Next.”
Once the disk has finish compressing, close the wizard and now view the new size in Explorer or from a command prompt. As you can see below with our example, the original VHD file of 6.5 GB has now been reduced to a size just below 5GB.
OK, so now I have reduced the image size from 6.54 GB to 5GB. Initially, this does not seem like the best improvement, but an optimized VHD will compress better once the MED-V compression is applied further compressing the file size down further into a .CKM file.
I have found these procedures to also lead to significantly reduced CKM file sizes. In the above example, once I packed the image from the MED-V management console the total size was reduced to 1.7 GB where the original CKM file was 3.1 GB prior to performing the additional image optimization. Moving the CKM size from 3.1 to 1.7 GB is indeed a substantial improvement and makes this extra effort worthwhile.
Steve Thomas | Senior Support Escalation Engineer
Comments
Anonymous
January 01, 2003
I agree!Anonymous
January 01, 2003
Nice post Steve!!! Perhaps rough..but if your goal is to save more diskspace you can delete hotfix backup files (%systemroot%)and installers directory (%systemroot%installers). Depending of number of installed programs and hotfixes this can save a lot of diskspace.