Optimize a Windows PE Image (Standard 7 SP1)
7/8/2014
This walkthrough describes how to reduce the size of the Windows Preinstallation Environment (Windows PE) 3.0 image. An optimized Windows PE image is an image that has been modified to support a scenario by removing files not needed in that scenario.
You create an optimized Windows PE image by using the /apply-profile
option for the Deployment Image Servicing and Management (DISM) tool. The /apply-profile
option tracks which files the scenario requires while the scenario is in progress. The /apply-profile
option saves the file list to a profile. For more information about DISM, see Deployment Image Servicing and Management Technical Reference.
The optimization process requires you to build a test image, build a profile, and then build the optimized image by applying the profile to the base Windows PE image. Applying the profile removes files from the base image that are not in the profile.
Hardware and Software Assumptions
To complete this walkthrough, you must have the following:
- An x86-based or x64-based computer running Windows 7, Windows Vista, Windows Server 2008, or Windows Server 2003.
- Custom applications that you want to add to the Windows PE image.
- If using a CD or DVD, a CD or DVD burner and image-burning software to create a bootable CD or DVD, and a blank CD or DVD.
- If you are using a USB flash device (UFD), be sure that the UFD has enough memory to store your Windows PE image and associated files, with at least 64 MB still available.
Step 1: Set up a Windows PE build environment
- Follow the instructions for setting up a build environment in Create a Windows PE Build Environment.
Step 2: Mount the base Windows PE image
Mount the base image to a local directory by using the DISM tool so that you can add or remove packages. Consider the following example:
dism /Mount-Wim /WimFile:c:\winpe_x86\ISO\sources\boot.wim /index:1 /MountDir:c:\winpe_x86\mount
Step 3: Enable profiling
Add Windows Management Instrumentation (WMI) support by using the
dism /Add-Packages
command-line option. Consider the following example:dism /image:C:\winpe_x86\mount /Add-Package /PackagePath:"C:\Program Files\Windows Embedded Standard 7\Tools\PETools\x86\WinPE_FPs\winpe-wmi.cab" dism /image:C:\winpe_x86\mount /Add-Package /PackagePath:"C:\Program Files\ Windows Embedded Standard 7\Tools\PETools\x86\WinPE_FPs\en-us\winpe-wmi_en-us.cab"
Enable profiling by using the
dism /Enable-profiling
command-line option. Specify the path to the image and a location for saving the profile. Consider the following example:dism /image:C:\winpe_x86\mount /Enable-profiling
You can use the
dism /Get-PESettings
option to review the settings of the image to verify that the image has been updated with your settings.Profiling executes during Windows PE creation to ensure that memory-mapped DLLs are captured.
Step 4: Add custom applications and scripts
Add your custom applications and scripts to the Windows PE image. For more information, see the following:
Step 5: Commit changes
Commit changes to the Windows PE image by using the
dism /unmount
option with the/commit
option. Consider the following example:dism /Unmount-Wim /MountDir:C:\winpe_x86\mount\ /Commit
Step 6: Create Windows PE media
Follow the steps for creating a bootable CD in Boot Windows PE from RAM Using a CD.
- or -
Follow the steps for preparing a UFD in Boot Windows PE from RAM Using a UFD.
Step 7: Build a profile
Boot a computer with your custom Windows PE image.
From the Windows PE session, complete the scenario for which your image is intended. If the scenario spans multiple applications, run the commands required by the scenario for each application.
Run the
wpeutil saveprofile <path>
command to save the profile to an external source. Consider the following example:wpeutil saveprofile E:\Optimize_Profile.txt "Image Optimization Profile"
End the Windows PE session.
You can boot from the same Windows PE image again, run different applications, and save new profiles. DISM combines the profiles when you use the
/apply-profiles
option.
Step 8: Build an optimized image
If you want to compare your original custom image to optimized versions of the same image, make a copy of the Boot.wim file.
Mount your custom Windows PE image. Consider the following example:
dism /Mount-Wim /WimFile:C:\winpe_x86\iso\sources\boot.wim /index:1 /MountDir:C:\winpe_x86\mount
Use DISM to apply the profiles to the Windows PE image. Consider the following example:
dism /image:C:\winpe_x86\mount /Apply-Profiles:E:\Optimize_Profile.txt
You cannot service a customized Windows PE image by applying a profile because the
/Apply-Profiles
option disables profiling.Commit the changes by using the
dism /unmount-Wim
option with the/commit
option. Consider the following example:dism /Unmount-Wim /MountDir:C:\winpe_x86\mount /Commit
Optimize the image by exporting a new image file. When you modify an image, ImageX and DISM store additional resource files that increase the overall size of the image. Exporting the image by using ImageX removes unnecessary resource files. Consider the following example:
imagex /export C:\winpe_x86\iso\sources\boot.wim 1 C:\winpe_x86\iso\sources\boot2.wim
Delete the original Boot.wim file and rename Boot2.wim to Boot.wim.