WinPE: Optimize and shrink the image
Speed up Windows Preinstallation Environment (WinPE) boot time by cleaning up the image after adding drivers, languages, or packages.
Mount the Windows PE boot image
Dism /Mount-Image /ImageFile:"C:\WinPE_amd64\media\sources\boot.wim" /index:1 /MountDir:"C:\WinPE_amd64\mount"
However, don't unmount the image just yet.
Prepare to clean the image
This process marks files that can be removed during the export process.
DISM /Cleanup-Image /Image="C:\WinPE_amd64\mount" /StartComponentCleanup /ResetBase
Unmount the image
Commit the changes and unmount the WinPE image:
Dism /Unmount-Image /MountDir:"C:\WinPE_amd64\mount" /Commit
Export and then replace the image
The exported image should be smaller than the old image. Replace the original image with the new one.
Dism /Export-Image /SourceImageFile:"c:\winpe_amd64\media\sources\boot.wim" /SourceIndex:1 /DestinationImageFile:"c:\winpe_amd64\mount\boot2.wim" Del "C:\WinPE_amd64\media\sources\boot.wim" Copy "C:\WinPE_amd64\mount\boot2.wim" "c:\winpe_amd64\media\sources\boot.wim"
Try it out
Create bootable media, such as a USB flash drive.
MakeWinPEMedia /UFD C:\WinPE_amd64 F:
Boot the media. WinPE starts automatically. After the WinPE window appears, the wpeinit command runs automatically. This may take a few minutes. Verify your customizations.