Walkthrough: Create an Optimized Windows PE Image with Profiling

Applies To: Windows 8, Windows Server 2008 R2, Windows Server 2012

You can reduce the size of your Windows® Preinstallation Environment (Windows PE) image by using Windows PE profiling. The profiling feature tracks the files that the system uses during a particular scenario, such as deploying a Windows image, while the scenario is in progress. The profiling feature then saves the list of files that were used for the scenario to a profile. You can use the profile to create an image that is optimized to include only the relevant files for the particular scenario by using the Dism /Apply-Profile command.

Important

In Windows® 8, Windows PE profiling is deprecated. This functionality is available in this release, however it might be removed in a future release.

In this topic:

  • Step 1: Set Up a Windows PE Build Environment

  • Step 2: Mount the Base Windows PE Image

  • Step 3: Enable Profiling

  • Step 4: Add More Customization (Optional)

  • Step 5: Commit Changes

  • Step 6: Create a Bootable Windows PE RAM Disk

  • Step 7: Build a Profile

  • Step 8: Create an Optimized Image

Prerequisites

To complete this walkthrough, you need the following:

  • A technician computer that has the Windows® Assessment and Deployment Kit (Windows ADK) installed.

  • Your own custom applications.

Step 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. On your technician computer: Click Start , and type deployment . Right-click Deployment and Imaging Tools Environment and then select Run as administrator .

    A Deployment and Imaging Tools Environment Command Prompt window opens with environment variables automatically set to point to all the necessary tools. By default, all tools are installed in the C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Deployment Tools (64-bit Windows installation) or C:\Program Files\Windows Kits\8.0\Assessment and Deployment Kit\Deployment Tools (32-bit Windows installation) folder.

  2. At the command prompt, enter the following Copype command with the architecture and the working directory for the Windows PE files.

    Copype amd64 C:\winpe_amd64
    

    The following directory structure is created.

    <workingDirectory><workingDirectory>
      \media
    
        <workingDirectory>
      \mount
    

    Note

    When Copype copies the Windows PE base image (Winpe.wim) to the <workingDirectory> \media\sources folder, it renames the base image from Winpe.wim to Boot.wim.

Step 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 optional components.

  • At the command prompt, mount the Windows PE base image (Boot.wim) to the local \mount directory so that you can add or remove optional components and make other customizations. In the following example, <image_index> is the number of the selected image on the .wim file.

    Dism /mount-image /imagefile:C:\winpe_amd64\ISO\sources\boot.wim /index:
        <image_index>
       /mountdir:C:\winpe_amd64\mount
    

Step 3: Enable Profiling

In this step, you enable profiling, the feature that tracks and traces all the file calls in the booted image to streamline a Windows PE image. The process of creating a Windows PE image executes profiling to capture memory-mapped dynamic-link libraries (DLLs). To enable profiling, you add Windows Management Instrumentation (WMI) support and run the Dism /Enable-Profiling command. WMI is the infrastructure for management data and operations on Windows-based operating systems.

Important

In Windows® 8, Windows PE profiling is deprecated. This functionality is available in this release, however it might be removed in a future release.

  1. Run the Dism /Add-Package command to add WMI support, as shown in the following examples.

    Dism /image:C:\winpe_amd64\mount /add-package /packagepath:"C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Deployment and Imaging Tools\Windows Preinstallation Environment\amd64\WinPE_OCs\winpe-wmi.cab"
    
    Dism /image:C:\winpe_amd64\mount /add-package /packagepath:"C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Deployment and Imaging Tools\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\winpe-wmi_en-us.cab"
    
  2. Use the Dism /Enable-Profiling command and specify both the path of the image and a location to save the profile to enable profiling, as shown in the following example.

    Dism /image:C:\winpe_amd64\mount /enable-profiling
    
  3. To make sure that your image has been updated with your settings, use the Dism /Get-MountedWimInfo command to review the settings of the image.

Step 4: Add More Customization (Optional)

In this step, you can install additional applications and other updates based on a customer's order. For more information about how to add a custom application to your image, see How to Add an Application to Windows PE.

Step 5: Commit Changes

In this step, you save and unmount the image.

  • Use the Dism /Unmount-Image command together with the /Commit option, as shown in the following example.

    Dism /unmount-image /mountdir:C:\winpe_amd64\mount\ /commit
    

Step 6: Create a Bootable Windows PE RAM Disk

In this step, you put your customized Windows PE RAM disk image on removable media to boot into memory. To create this disk, follow the instructions in Walkthrough: Install Windows PE to CD, USB Flash Drive, or USB Hard Drive. After you create bootable media, your test image is ready. You can then create a profile and, subsequently, an image based on that profile.

Step 7: Build a Profile

In this step, you build a profile by booting the image on the test computer and then testing all actions that will be used in the actual environment. For example, if you use Notepad, you must use the Save As command if you want to save a Notepad file. When you boot the image, the profiling feature starts logging any file reads during the session, and then marks the files that have been used. If a file is not used, it is removed when the profile is applied to the Windows PE image.

  1. Boot a computer that has your custom Windows PE image.

  2. From a running Windows PE session, test the scenario that will use your custom image. If you use multiple applications, you must run all the desired commands for each application.

  3. After you test and run all the desired commands for all applications, run the Wpeutil Saveprofile command with the path of the profile. Then, save the profile to an external source, as shown in the following example.

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

    Note

    You can create multiple profiles from the same Windows PE image. To do so, boot the image again, run different applications, and save new profiles. When you run the /Apply-Profiles command, DISM combines the profiles into one.

Step 8: Create an Optimized Image

In this step, you build an optimized image on which to mount the test image. To do so, use the DISM tool to apply your profile, and then commit the changes to the image.

  1. Optional: If you plan to compare your original image to the optimized image after you run the Apply-Profiles command, make a copy of the boot.wim file before you continue.

  2. Mount the original base image. In the following example, <image_index> is the number of the selected image in the .wim file.

    Dism /mount-image /imagefile:C:\winpe_amd64\iso\sources\boot.wim /index:
        <image_index>
       /mountdir:C:\winpe_amd64\mount
    
  3. Use DISM to apply the profiles that you created to the test image, as shown in the following example.

    Dism /image:C:\winpe_amd64\mount /apply-profiles:E:\Optimize_Profile.txt
    

    Note

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

  4. Commit the changes by using the Dism /Unmount-Image option together with the /Commit option, as shown in he following example.

    Dism /unmount-image /mountdir:C:\winpe_amd64\mount /commit
    
  5. Optimize the image by exporting it to a new image file. When you modify an image, DISM stores additional resource files that increase the overall size of the image. Exporting the image by using DISM removes unnecessary resource files. In the following example, <image_index> is the number of the selected image in the .wim file.

    Dism /export-image /sourceimagefile:C:\winpe_amd64\iso\sources\boot.wim /sourceindex:
        <image_index>
       /destinationimagefile:C:\winpe_amd64\iso\sources\boot2.wim
    
  6. Delete the original Boot.wim file and rename Boot2.wim to Boot.wim.

Next Steps

You can create bootable Windows PE RAM disk on removable media. For more information, see Walkthrough: Install Windows PE to CD, USB Flash Drive, or USB Hard Drive. You can also deploy your optimized Windows PE image onto a network share or hard disk.

See Also

Tasks

Walkthrough: Create a Custom Windows PE Image
Walkthrough: Add Multilingual Support to Windows Setup

Reference

Image Management Command-Line Options
Windows PE Servicing Command-Line Options