This walkthrough describes how to reduce the size of your Windows® Preinstallation Environment (Windows PE) image. An optimized Windows PE image is an image that has been modified to support a scenario by removing any files not needed in that scenario. For example, you might want a smaller Windows PE image to make it easier to deploy from a network. You create an optimized Windows PE image using the Deployment Image Servicing and Management (DISM) /apply-profile option. This feature tracks what files are necessary for the scenario while the scenario is in progress and saves the list to a profile. The 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. This removes any file from the base image that is not in the profile. This walkthrough takes you through the following three steps:

Prerequisites

To complete this walkthrough, you need the following:

  • A technician computer that contains all of the tools and the source files. For more information, see Building a Technician Computer.

  • Custom applications.

Step 1: Build a test image

In step 1, you create a Windows PE build environment, mount the image, add profiling support, add packages, commit changes, and then burn the image to media.

Step 1.1: Set up a Windows PE Build Environment

In this step, you create a required directory structure that supports building a Windows PE image.

  1. Click Start, point to All Programs, point to Windows OPK or Windows AIK, right-click Windows PE Tools Command Prompt, and then select Run as administrator. By default, all tools are installed at C:\Program Files\Version\Tools, where Version can be Windows OPK or Windows AIK.

  2. At the command prompt, run the Copype.cmd script. This script requires two arguments: hardware architecture and destination location. For example,

    copype.cmd <architecture> <destination>
    
    where <architecture> can be x86, AMD64, or IA64 and <destination> is a path to the local directory. For example,

    copype.cmd x86 c:\winpe_x86
    
    The script creates the following directory structure and copies all of the necessary files for that architecture. For example,

    \winpe_x86
    \winpe_x86\ISO
    \winpe_x86\mount
    
  3. Copy the base image (winpe.wim) into \Winpe_x86\ISO\sources folder and rename the file to boot.wim.

    copy c:\winpe_x86\winpe.wim c:\winpe_x86\ISO\sources\boot.wim
    

Step 1.2: Mount the Base Windows PE Image

In this step, you mount the base image to a local directory so that you can add or remove packages. At the command prompt, mount the base Windows PE image (Boot.wim) to the \Mount directory by using the DISM tool. For example,

Dism /Mount-Wim /WimFile:c:\winpe_x86\ISO\sources\boot.wim /index:1 /MountDir:c:\winpe_x86\mount

Step 1.3: Enable-Profiling

In this step, you will add Windows Management Instrumentation (WMI) support and enable profiling using the Dism /Enable-profiling command-line option. WMI is the infrastructure for management data and operations on Windows-based operating systems.

Profiling is executed during Windows PE creation, to ensure that memory-mapped DLLs are captured. This feature tracks and traces all of the file calls in the booted image.

  1. Add WMI support using Dism /Add-Packages, For example,

    Dism /image:C:\winpe_x86\mount /Add-Package /PackagePath:"C:\Program Files\<version>\Tools\PETools\x86\WinPE_FPs\winpe-wmi.cab"
    
    Dism /image:C:\winpe_x86\mount /Add-Package /PackagePath:"C:\Program Files\<version>\Tools\PETools\x86\WinPE_FPs\en-us\winpe-wmi_en-us.cab"
    
  2. Enable Profiling.

    Use the DISM /enable-profiling option to enable profiling. You must specify both the path to the image and a location to save the profile when using the /Enable-profiling option. For example,

    Dism /image:C:\winpe_x86\mount /Enable-profiling
    
Important:

You can use the DISM /Get-PESettings option to review the settings of the image to ensure your image has been updated with your settings.

Step 1.4: Add Customization

In this step, you add your custom applications and scripts to your Windows PE image. For more information see,

Step 1.5: Commit changes

Commit changes to the image. In this step, you commit the changes to the original image file by using the DISM /unmount option with the /commit option. For example:

dism /Unmount-Wim /MountDir:C:\winpe_x86\mount\ /Commit

Step 1.6 Create Windows PE Media

You now have a customized Windows PE RAM disk image that you can place on bootable media, such as a CD-ROM or USB flash drive (UFD).

To create a bootable CD-ROM

To CD-ROM or create a bootable DVD-ROM using custom Windows PE image, follow Step 4 of Walkthrough: Create a Bootable Windows PE RAM Disk on CD-ROM topic.

To create a bootable UFD

To create a bootable UFD using custom Windows PE image, follow Step 4 of Walkthrough: Create a Bootable Windows PE RAM Disk on a USB Flash Disk topic.

Step 2: Build a profile

To build a profile, you boot the image on the test computer, and then test all actions that will be used in the actual environment. For example, if you use Notepad, you must use the Save As function if you want the ability to save a Notepad file. When you boot the image, it begins logging any file reads during the session. It then marks the files that have been used. If a file is not used, it is later removed when the /apply-profiles command-line option is initiated.

Once you complete your testing, run the wpeutil /saveprofile command from the running Windows PE session to save a profile.

  1. Boot a computer with your custom Windows PE image.

  2. From a running Windows PE session, test the scenario on how your custom image will be used. If multiple applications are used, you must run all of the desired commands for each application.

  3. After running all of the desired commands for all applications, run the wpeutil saveprofile <path to profile> command. Save the profile to an external source. For example,

    wpeutil saveprofile E:\Optimize_Profile.txt "Image Optimization Profile" 
    
  4. End the Windows PE session.

    Note:

    You can boot from the same Windows PE image again, run different applications, and save new profiles. Later DISM combines the profiles when you use the /apply-profiles option

Step 3: Build an optimized image

In building an optimized image you mount the test image, use the DISM tool to apply your profile, and then commit the changes to the image. On the technician computer, do the following:

Important:

If you want to compare images from your original to the image after the Apply-Profile command is run, make a copy of the boot.wim file before starting the following procedure.

  1. Mount the original test image you created in Step 1.

    Dism /Mount-Wim /WimFile:C:\winpe_x86\iso\sources\boot.wim /index:1 /MountDir:C:\winpe_x86\mount
    
  2. Use DISM to apply the profiles to the test image. For example,

    Dism /image:C:\winpe_x86\mount /Apply-Profiles:E:\Optimize_Profile.txt
    
    Note:

    A Windows PE image that has been customized using any profile is not serviceable. The /Apply-Profiles option automatically disables profiling.

  3. Commit the changes using the DISM /unmount-Wim option with the /commit option. For example,

    Dism /Unmount-Wim /MountDir:C:\winpe_x86\mount /Commit
    
  4. Optimize the image by exporting to a new image file. When you modify an image, ImageX and DISM stores additional resource files that increase the overall size of the image. Exporting the image using ImageX will remove unnecessary resource files.

    imagex /export C:\winpe_x86\iso\sources\boot.wim 1 C:\winpe_x86\iso\sources\boot2.wim 
    
  5. Delete the original boot.wim and rename boot2.wim to boot.wim.

Next Step

You now have an optimized Windows PE image that you can place on bootable media, such as a CD-ROM, UFD, or network server.

See Also