As you all (should) already know, Windows Setup's install.wim file is growing with each new feature upgrade. It's coming close and soon going over the 4 GB size limit of a FAT32 formatted install media. Today, as I write this, (22-FEB-2022), downloading WIM-based most current public release install media as told here in Shawn Brink's tutorial, the install.wim file is 4.5 GB (UK English Windows 11).
There’s nothing in the UEFI specifications that prevents booting a computer from an NTFS formatted USB flash drive. In fact, this so-called limitation is entirely artificial, caused by the single fact that manufacturer has not included correct drivers in UEFI. Luckily, most modern computers can boot from a single-partition NTFS formatted USB flash drive, and install Windows 11 from a single partition USB media containing WIM image larger than 4 GB (maximum file size on FAT32 media).
But, what to do if the WIM file is over 4 GB, and your computer cannot boot from an NTFS formatted media?
This tutorial will show how to create a USB flash drive containing a FAT32 formatted WinPE partition, and a bigger NTFS formatted Windows Setup partition. When computer is booted from this USB flash drive, the WinPE partition takes care of boot, then runs Windows Setup from bigger setup partition on same USB.
The whole process takes 10 to 20 minutes, but only needs to be done once. In the future, the Windows Setup files on USB can be replaced with newer version of Windows 11.
Use links to jump to any part, browser back button to return to this table
Part One: | Create WinPE |
Part Two: | Edit WinPE boot.wim |
Part Three: | Make WinPE ISO |
Part Four: | Partition USB flash drive |
Part Five: | Create bootable USB install media |
Please notice: I have prepared a custom WinPE ISO image for you. You can download it from my OneDrive: WinPEx64.iso. File size is 474 MB.
Parts One, Two and Three in this tutorial will show how I edited and customized this WinPE image, and are intended to those users who want to learn how to do it by themselves.
Short: if you want to make this easy, download the provided WinPE ISO, and start from Part Four, and you are done in three minutes.
Create WinPE
1.1 Download and install both Windows 11 ADK (Assessment and Deployment Kit), and Windows PE add-on for the ADK, installing ADK first:
(Click screenshot thumbnails to open images enlarged.)
1.2 When installing ADK, for purpose of this tutorial, you will only need the Deployment Tools module. Unselecting everything else, download size is less than 100 MB:
1.3 When both ADK and WinPE add-on have been installed, open an elevated ADK Deployment and Imaging Tools Environment, a special mode of Command Prompt. You will find it in Start > All Apps > W > Windows Kits:
1.4 The prompt is quite long. Shorten it by jumping to root of the drive where ADK was installed with command
cd \
(#1 in next screenshot)1.5 Create 64-bit WinPE files with following command (#2 in next screenshot), where folder D:\WPEx64 is the folder where WinPE files will be created. Folder will be created automatically, it does not need to exist:
copype amd64 D:\WPEx64
For 32-bit WinPE, the command is as follows:
copype x86 D:\WPEx86
Edit WinPE boot.wim
2.1 Depending on which bit architecture you selected, either folder D:\WPEx86 or D:\WPEx64 now contains all files and folders to create a WinPE ISO.
2.2 To edit it, we must mount WinPE boot.wim file for offline servicing. First, create a mount point folder. In this example, I made a folder C:\Mount. Open an elevated PowerShell, and enter following command to mount boot.wim:
Mount-WindowsImage -ImagePath D:\WPEx64\Media\Sources\boot.wim -Index 1 -Path C:\Mount
Change -ImagePath folder WPEx64 to WPEx32 if working with 32-bit WinPE.
2.3 Folder C:\Mount now contains WinPE image, and we can edit it. First thing I made when editing the provided custom WinPE image, I added PowerShell support. By default, WinPE does not support PowerShell.
To enable PowerShell in WinPE, copy and paste the following commands to elevated PowerShell:. Notice that you can copy all commands at once, and paste them all to elevated PowerShell, which will then run them one by one:
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-NetFX.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-NetFX_en-us.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-Scripting.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-Scripting_en-us.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-PowerShell.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-PowerShell_en-us.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-StorageWMI.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-StorageWMI_en-us.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-DismCmdlets.cab"
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-DismCmdlets_en-us.cab"
The above commands will add PowerShell to a 64-bit WinPE. If you are creating a 32-bit WinPE, change the folder amd64 at the end of long path, near end of each command to x86. An example using the first of above listed commands:
64-bit WinPE:
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab"
32-bit WinPE:
Dism /Add-Package /Image:"C:\Mount" /PackagePath:"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\x86\WinPE_OCs\WinPE-WMI.cab"
2.4 This custom WinPE requires two scripts, a PowerShell script to find out drive letter of the NTFS partition on USB containing setup files, and then run Windows Setup, and a batch file to run that PS script.
Opening mount point folder C:\Mount, I created a folder Scripts on its root to store these two scripts:
2.5 First the small PS script. To save to mount point folder requires elevated rights, so we need to open Notepad elevated (run as administrator). Copy and paste the following code to it:
$SetupVolume = (Get-Volume -FileSystemLabel Setup).DriveLetter
$SetupFile = $SetupVolume + ':\setup.exe'
cmd /c $SetupFile
First line will search the USB for volume (partition) labelled Setup, and set its drive letter in variable $SetupVolume. Second line then creates variable $SetupFile, adding the important :\setup.exe to drive letter found in first line. For instance, if $SetupVolume is F, $SetupFile is F:\setup.exe.
Last line then executes command setup.exe from bigger NTFS partition Setup, which starts Windows Setup.
Save the file in folder C:\Mount\Scripts as SetupW10.ps1. In Save As dialog, remember to select Save As Type as All files:
2.6 Next, short batch file. Copy and paste following code to an elevated Notepad:
@echo off
rem
rem Run PowerShell script to start Windows Setup
rem
cls
echo.
echo Starting windows Setup...
powershell -ExecutionPolicy bypass -file "X:\Scripts\SetupW11.ps1"
Only important line in this batch file is the last one. It executes the PS script made in step 2.5.
Save it to folder C:\Mount\Scripts as WinSetup.cmd. Again, as with the PS script, in Save As dialog, remember to select Save As Type as All files.
2.7 Last but not least, we need to edit file C:\Mount\Windows\System32\startnet.cmd. Startnet.cmd functions exactly like autoexec.bat did in Windows XP and older Windows versions, running every command in it automatically when WinPE boots.
By default, startnet.cmd only contains one command, wpeinit, which enables WinPE networking capabilities. We add two other commands to it.
Open startnet.cmd in an elevated Notepad. Copy and paste following code to it:
wpeinit
powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
X:\Scripts\WinSetup.cmd
The first line is the default command to initialize networking. In second line, we set a High Performance power plan to speed up Windows installation. In last line, we execute the batch file created in step 2.6.
When computer is booted from WinPE media, the contents of WinPE will be copied to RAM disk X. This is why we can use the path X:\Scripts on last command line, there being no need to find out the drive letter for volume containing the Scripts folder.
2.8 In an elevated PowerShell, enter following command to save changes to WinPE:
Dismount-WindowsImage -Path C:\Mount -Save
Make WinPE ISO
3.1 Open an elevated ADK Deployment and Imaging Tools Environment as told in step 1.3.
3.2 Enter following command to create WinPE ISO:
MakeWinPEMedia /ISO D:\WPEx64 F:\WinPEx64.iso
Change path D:\WPEx64 to D:\WPEx86 if creating a 32-bit WinPE ISO. Path F:\WinPEx64.iso is the path and name of the ISO file that will be created.
Partition USB flash drive
4.1 Plug in an at least 8 GB USB lash drive. Open an elevated PowerShell, start Windows Disk Partitioning utility with command DISKPART.
Enter command LIST DISK to show all attached disks, find out the disk ID for your USB Flash Drive. In my case now, the USB is DISK 3:
Be careful, absolutely sure that you find out correct Disk ID! In following step, the selected disk will be wiped clean, and new partitions will be created. Selecting wrong disk may cause Windows or data disks being formatted, all data lost.
4.2 Still in DISKPART, run following commands one by one. In first command, replace X (disk ID) with actual Disk ID for your USB flash drive:
select disk X
clean
create partition primary size=1024
format quick fs=fat32 label="Boot"
assign
create partition primary
format quick fs=ntfs label="Setup"
assign
4.3 Quit DISKPART with command EXIT. Your USB flash drive is now correctly partitioned, containing a 1 GB partition Boot, and partition Setup which occupies the rest of the USB:
Create bootable USB install media
5.1 Mount the WinPE ISO image created in Step 3.2 as a virtual CD / DVD drive (right click, select Mount). Copy its contents, all files and folders, to partition Boot on USB.
5.2 Mount a Windows 11 ISO image as a virtual CD / DVD drive (right click, select Mount). Copy its contents, all files and folders, to partition Setup on USB.
That's it! You have now a bootable USB flash drive to install Windows, even if the install.wim or install.esd file is bigger than FAT32 size limit 4 GB. In the future, when you need install media for a new Windows version, simply format the Setup partition on USB, and copy contents of new ISO to it.
Kari