Partager via


Deploy WIMBoot Images: If you don't know the size of the images upfront

Applies To: Windows 8.1

Use this procedure to deploy Windows image file boot (WIMBoot) PCs when you're not sure how much room you'll need for your final factory floor customizations. This process is similar to the procedure in Deploy WIMBoot Images: If you know the size of the images upfront.

WIMBoot helps you save hard drive space by booting to a WIM file rather than a set of uncompressed Windows files.

To deploy WIMBoot PCs using this method, you'll deploy Windows to a single large Windows partition. You'll temporarily put the Windows image file, the Windows RE image file here. Next, you'll add your factory floor customizations, and capture them into a custom.wim file. Finally, you'll use a script to set up a new Images partition, and set up the files in their new location. This diagram shows this process:

The final customizations in the custom.wim file may include Windows updates, build-to-order apps and drivers, or other changes that typically happen on the factory floor. This means you don't have to recapture these updates into the fully-loaded install.wim. This change can potentially save time during the manufacturing process.

If you don't plan on making large changes with the custom.wim file, or if you don't use this file, you may be able to save manufacturing time by using a fixed size for the Images partition. For more info, see Deploy WIMBoot Images: If you know the size of the images upfront.

With this procedure, you'll deploy Windows to a single large Windows partition. Then you'll add factory floor customizations. Finally, you'll use a script to calculate the right size for the Images partition and set it up.

Prerequistes

  • Prepare a WIMBoot image (install_wimboot.wim) and separate out the Windows RE image (winre_wimboot.wim). For more info, see Create WIMBoot Images.

  • Create a Windows PE 5.1 bootable drive by adding the Windows 8.1 Update package to Windows PE 5.0 and cleaning up the image. For more info, see Update WinPE 5.0 to WinPE 5.1.

Format the drive with the WIMBoot partition layout, leaving out the Images partition

  1. Boot the reference PC into Windows PE 5.1.

  2. Format the drive using this partition layout:

    1. System (EFI System Partition): Size: 100 MB.

      If the primary drive is less than 16 GB, you can use a minimum size of 32 MB.

      If the primary drive is an Advanced Format 4K Native drive (4-KB-per-sector), the minimum size is 260 MB.

    2. MSR (x86 and x64 only, not needed for ARM)

    3. Windows

    4. Do not set up the Images partition yet. The sample script below will set this up later.

Sample Diskpart script

This script temporarily assigns the drive letter Windows=C. If you’re deploying to PCs with unformatted hard drives, you might want to modify the script to use drive letter that’s near the end of the alphabet, such as W, to avoid drive letter conflicts. Do not use X, because this drive letter is reserved for Windows PE. After the PC reboots, the Windows partition is assigned the letter C, and the other partitions don’t receive drive letters. We've added volume names to the partitions, but they aren’t required.

Diskpart /s CreatePartitions-WIMBoot-NoImagesPartition.txt

rem == Diskpart /s CreatePartitions-WIMBoot-NoImagesPartition.txt ==
rem == These commands set up the hard drive partitions
rem    for WIMBoot, without the Images partition.
rem    You’ll add the Images partition later.
rem
rem    Adjust the partition sizes to fill the drive
rem    as necessary. ==
select disk 0
clean
convert gpt
rem == 1. System partition (ESP) ===================
create partition efi size=100
format quick fs=fat32 label="System"
rem == 2. Microsoft Reserved (MSR) partition =======
create partition msr size=128
rem == 3. Windows partition ========================
create partition primary
format quick fs=ntfs label="Windows"
assign letter=c
list volume
exit

Add the Windows and recovery files

  1. Create a temporary folder in the Windows partition. Use a location that’s in the DISM Exclusion list so that the Windows image file isn’t accidentally captured.

    md C:\Recycler\WIMs\
    
  2. Copy the Windows image file from the USB or network drive (example: N) to the temporary folder.

    Rename the image file install.wim (if necessary). This filename is required.

    copy N:\Images\install_wimboot.wim "C:\Recycler\WIMs\install.wim"
    
  3. Apply the Windows image to the Windows partition (drive C), using the /WIMBoot option.

    Recommended: Create a temporary scratch folder for DISM to avoid issues related to short file names. To prevent capturing the DISM logs in your image, choose a location that’s in your DISM Exclusion list. For more info, see DISM Configuration List and WimScript.ini Files.

    When you use the DISM /Apply-Image command with the /WIMBoot option, the ImageFile location and ApplyDir partition must be on the same hard drive.

    md C:\Recycler\Scratch
    
    DISM /Apply-Image /ImageFile:"C:\Recycler\WIMs\install.wim" /ApplyDir:C: /Index:1 /WIMBoot /ScratchDir:C:\Recycler\Scratch
    
  4. Create boot files and set them to boot to the Windows partition.

    C:\Windows\System32\bcdboot C:\Windows
    
  5. Copy the Windows RE image file from the USB or network drive (example: N) to the temporary folder.

    Winre.wim may be a hidden file. Use robocopy or xcopy to copy the file. In this example, the "echo f" command suppresses the xcopy "File or Directory" prompt:

    echo f| xcopy N:\Images\winre_update1.wim C:\Recycler\WIMs\winre.wim /h
    

Note

Don’t register the Windows RE partition – the sample script will take care of this later.

Sample command-line script:

ApplyWIMBoot-NoImagesPartition N:\Images\Install-WIMBoot.wim N:\Images\WinRE-WIMBoot.wim

@echo off 
echo == ApplyWIMBoot-NoImagesPartition.cmd ==

echo == These commands deploy a specified Windows image
echo    and Windows RE image to a PC.
echo    This method begins with no Images partition. It will be created later.

if "%2" equ "" (
echo == Error: Specify a Windows image and a Windows RE image file.
echo    Example: ApplyWIMBoot-NoImagesPartition N:\Images\Install-WIMBoot.wim N:\Images\WinRE-WIMBoot.wim
exit /b 0
)
@echo on

rem == Add the Windows image to the Images partition ==
md "C:\Recycler\WIMs\"
copy %1 "C:\Recycler\WIMs\install.wim"

rem == Create a scratch folder for DISM operations
md "C:\Recycler\Scratch"

rem == Apply the Windows image to the Windows partition ==
dism /Apply-Image /ImageFile:"C:\Recycler\WIMs\install.wim" /ApplyDir:C: /Index:1 /WIMBoot /ScratchDir:C:\Recycler\Scratch

rem == Create boot files on the System partition ==
C:\Windows\System32\bcdboot C:\Windows

:rem == Add the Windows RE image to the Images partition ==
md C:\Recycler\WIMs
echo f| xcopy %2 C:\Recycler\WIMs\winre.wim /h

:rem == Don’t register the location of the recovery tools ==

Perform factory floor customizations and capture the changes

  1. Press CTRL+SHIFT+F3 at the OOBE screens to enter audit mode.

  2. Add final customizations, such as build-to-order apps, drivers, or Windows updates.

  3. Recommended: clean the Windows image to gain free drive space.

    Dism /Online /Cleanup-Image /StartComponentCleanup
    
  4. Prepare the PC to boot into OOBE mode, and shut down the PC.

    Recommended: Generalize the image to optimize the push-button reset features. If you do this, we recommend that you boot the PC once after the Images partition is created in order to speed up the OOBE process. For more info, see Perform final reboot and cleanup.

    Recommended: Add an Unattend file that includes a setting that will perform final cleanup tasks. For more info, see Perform final reboot and cleanup.

    C:\Windows\System32\Sysprep\Sysprep /OOBE /shutdown /generalize /unattend:"N:\Unattend\RemoveRecycler.xml"
    
  5. Reboot the PC into Windows PE 5.1.

  6. Capture factory floor customizations into custom.wim.

    DISM /Capture-CustomImage /CaptureDir:C: /ScratchDir:C:\Recycler\Scratch
    

Note

When you capture the custom image, DISM captures the incremental file changes (based on the specific install.wim file) to a new file, custom.wim, and converts these files to pointer files. The custom.wim is placed in the same folder as install.wim.

  • Don’t copy custom.wim to other PCs. Custom.wim is not intended as a replacement for modifying the primary install.wim file.

  • Don’t switch out the install.wim file after creating custom.wim.

  • Don't remove or re-capture custom.wim after capturing the incremental file changes. If you do need to modify the factory floor customizations, restart the process from the beginning of this page, including reformatting the entire drive.

Run a script to calculate and set up the Images partition

  1. Copy this script into Notepad, and save it with the file name CalculateAndCreateWIMBootPartition.cmd.

    CalculateAndCreateWIMBootPartition C: C:\Recycler\WIMs\ C:\Recycler\WIMs 0
    
    goto __start
    /*************************************************************
              Sample Script: CalculateAndCreateWIMBootPartition.cmd
    
    Use this script to calculate the size needed for the WIMBoot
    Images partition after applying your final factory settings.
    
    Prerequisites:
    - Boot the PC into Windows PE 5.1
     - The primary hard drive (disk 0) has three partitions:
         1. System partition (ESP)
         2. MSR
         3. Windows partition - the rest of disk 0
            - install.wim is in this partition
            - install.wim has been applied to this same partition
     - Complete the final factory floor customization
     - Capture custom.wim, and store it in the Windows partition, in the same folder as install.wim
     - Customize winre.wim, and store it in the Windows partition
    
    After this script is run:
    - The primary hard drive (disk 0) has four partitions:
         1. System partition (ESP)
         2. MSR
         3. Windows partition (calculated)
         4. Images partition (calculated)
    The Images partition will include:
     - install.wim, custom.wim, winre.wim
     - Any other OEM tools/scripts
     - 50 MB of additional free space
    **************************************************************/
    
    REM The script starts here
    :__start
    @echo off
    echo %date%-%time%:: Start of script %0 ,,,
    
    if "%1" equ "" (
     echo This script calculates the size needed for the Images partition and sets it up.
     echo Usage:
     echo CalculateAndCreateWIMBootPartition.cmd ^<letter of Windows volume^> ^<path to install.wim and custom.wim^> ^<path to winre.wim^> ^<additional free space to be added to Images partition in megabytes. If no additional space is needed, use 0.^>
     echo Example:
     echo CalculateAndCreateWIMBootPartition C: C:\Recycler\WIMs\ C:\Recycler\WIMs 300
     exit /b 0
    )
    
    
    
    REM --- Constants used to calculate free space ---
    REM Overhead Ratio: assume 6 MB overhead per 1000 MB size
    set /a NTFS_OVERHEAD_RATIO=500/497
    REM Per-Partition Overhead: 5 MB per partition
    set /a NTFS_OVERHEAD_BASE=5
    
    REM Megabytes-to-Millions Ratio:
    REM This ratio converts values from megabytes to millions of bytes, approximately. 
    set /a mega_million_ratio=205/215
    REM --------- Constants -------------
    
    
    REM Drive letter of the Windows partition. Example: C:
    set user_volume=%1
    
    REM Path that contains install.wim and custom.wim. Example: C:\Recycler\WIMs\
    set wimfile_path=%2
    
    REM Path that contains winre.wim. Example: C:\Recycler\WIMs
    set winre_wim_path=%3
    
    REM Additional size to be added to Images partition in megabytes. Example: 300
    set more_size=%4
    
    
    echo Check input Windows volume {%user_volume%} is accessible:
    echo dir %user_volume%\ /a
         dir %user_volume%\ /a
    if not exist %user_volume%\ (
     echo %user_volume%\ not found. Exiting script.
    pause
     exit /b 3
    )
    
    
    echo Check if the install.wim and custom.wim files {%wimfile_path%} are accessible:
    echo dir %wimfile_path%\ /a
         dir %wimfile_path%\ /a
    
    if not exist %wimfile_path%\install.wim (
     echo %wimfile_path%\install.wim not found. Exiting script.
    pause
     exit /b 3
    )
    if not exist %wimfile_path%\custom.wim (
     echo %wimfile_path%\Custom.wim not found. Exiting script.
    pause
     exit /b 3
    )
    
    echo Check if the winre.wim file {%winre_wim_path%}  is accessible:
    echo dir %winre_wim_path%\ /a
         dir %winre_wim_path%\ /a
    if not exist %winre_wim_path%\winre.wim  (
    echo %winre_wim_path%\winre.wim not found. Exiting script.
     exit /b 3
    )
    
    
    echo --------- Calculate install.wim size ,,,
    for %%A in (%wimfile_path%\install.wim) do ( 
    set install_wim_file_bytes=%%~zA
    echo install.wim is [%install_wim_file_bytes%] bytes.
    )
    set /a install_wim_file_MB=%install_wim_file_bytes:~0,-6%+0
    echo After cutting off last 6 digits = [%install_wim_file_MB%]
    set /a install_wim_file_MB=%install_wim_file_MB%*205/215
    echo Final approximate size: [%install_wim_file_MB%] MB
    
    echo --------- Calculate custom.wim size ,,,
    for %%A in (%wimfile_path%\custom.wim) do ( 
    set custom_wim_file_bytes=%%~zA
    echo custom.wim is [%custom_wim_file_bytes%] bytes.
    )
    set /a custom_wim_file_MB=%custom_wim_file_bytes:~0,-6%
    echo After cutting off last 6 digits = [%custom_wim_file_MB%]
    set /a custom_wim_file_MB=%custom_wim_file_MB%*205/215
    echo Final approximate size: [%custom_wim_file_MB%] MB
    
    echo --------- Calculate {%winre_wim_path%\winre.wim} size ,,,
    for %%A in (%winre_wim_path%\winre.wim) do ( 
    set winre_wim_file_bytes=%%~zA
    echo winre.wim is [%winre_wim_file_bytes%] bytes.
    )
    set /a winre_wim_file_MB=%winre_wim_file_bytes:~0,-6%
    echo After cutting off last 6 digits = [%winre_wim_file_MB%]
    set /a winre_wim_file_MB=%winre_wim_file_MB%*205/215
    echo Final approximate size: [%winre_wim_file_MB%] MB
    
    
    echo Calculate Images partition size ,,,
    echo Adding 50MB free space to input size {%more_size%}. This ensures Images partition have 50MB free space.
    set /a more_size=%more_size%+50
    set /a wim_partition_size_MB=%install_wim_file_MB%+%custom_wim_file_MB%
    echo Size sum of install.wim and custom.wim = {%wim_partition_size_MB%} MB
    set /a wim_partition_size_MB=%wim_partition_size_MB%+%winre_wim_file_MB%
    echo Total size of the 3 .WIM files = {%wim_partition_size_MB%} MB
    
    set /a wim_partition_size_MB=%wim_partition_size_MB%+%more_size%
    echo Size after adding specified space and 50MB = {%wim_partition_size_MB%} MB
    set /a wim_partition_size_MB=%wim_partition_size_MB%+%NTFS_OVERHEAD_BASE%
    set /a wim_partition_size_MB=%wim_partition_size_MB%*500/497
    echo Final Images partition size = {%wim_partition_size_MB%} MB
    
    echo Remove the hibernation file, if it exists.
    icacls C:\hiberfil.sys /grant everyone:f
    del C:\hiberfil.sys /ah
    
    echo Find out if we are in BIOS mode, or UEFI mode,,,
    echo reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType
         reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType
    for /f "tokens=2*" %%X in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO (SET _Firmware=%%Y)
    
    if %_Firmware%==0x1 (
      echo The PC is booted in BIOS mode. Note: BIOS is not supported for WIMBoot.  Exiting script.
    pause
     exit /b 3
    )
    
    if %_Firmware%==0x2 echo The PC is booted in UEFI mode.
    
    echo Create a diskpart script to shrink Windows partition {%user_volume%} by desired size of {%wim_partition_size_MB%} ,,
    set wim_partition_letter=M:
    echo. > %~dp0dps.txt
    echo list disk >> %~dp0dps.txt
    echo list volume >> %~dp0dps.txt
    echo select disk 0 >> %~dp0dps.txt
    echo list partition >> %~dp0dps.txt
    echo select volume %user_volume% >> %~dp0dps.txt
    echo list partition >> %~dp0dps.txt
    echo list volume >> %~dp0dps.txt
    echo shrink minimum=%wim_partition_size_MB% >> %~dp0dps.txt
    echo list partition >> %~dp0dps.txt
    echo list volume >> %~dp0dps.txt
    echo create partition primary size=%wim_partition_size_MB% >> %~dp0dps.txt
    rem  BIOS ONLY (Does not apply to WIMBoot): echo set id=27 OVERRIDE NOERR >> %~dp0dps.txt
    echo set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac OVERRIDE NOERR >> %~dp0dps.txt
    if %_Firmware%==0x2 (
    echo gpt attributes=0x8000000000000001 >> %~dp0dps.txt
    )
    echo list volume >> %~dp0dps.txt
    echo list partition >> %~dp0dps.txt
    echo format quick fs=ntfs label=images >> %~dp0dps.txt
    echo assign letter=%wim_partition_letter% >> %~dp0dps.txt
    echo list volume >> %~dp0dps.txt
    echo list partition >> %~dp0dps.txt
    echo exit >> %~dp0dps.txt
    
    echo =================== the script has:
    type  %~dp0dps.txt
    echo ==================================
    
    echo %date%-%time%:: Running diskpart /s %~dp0dps.txt ,,,
    diskpart /s %~dp0dps.txt 
    
    echo dir %wim_partition_letter%\
    dir %wim_partition_letter%\
    
    md "%wim_partition_letter%\Windows Images"
    md "%wim_partition_letter%\Recovery\WindowsRE"
    
    robocopy %wimfile_path%\ "%wim_partition_letter%\Windows Images"\ *wim /z
    echo dir %wim_partition_letter%\
    dir %wim_partition_letter%\
    echo dir "%wim_partition_letter%\Windows Images"
    dir "%wim_partition_letter%\Windows Images"
    
    echo dir %winre_wim_path%\winre.wim
         dir %winre_wim_path%\winre.wim
    echo robocopy %winre_wim_path%\ %wim_partition_letter%\Recovery\WindowsRE\ winre.wim 
         robocopy %winre_wim_path%\ %wim_partition_letter%\Recovery\WindowsRE\ winre.wim 
    )
    
    rem Register Windows RE
    echo %date%-%time%:: %user_volume%\Windows\System32\reagentc.exe /setreimage /path %wim_partition_letter%\Recovery\WindowsRE /target %user_volume%\Windows
          %user_volume%\Windows\System32\reagentc.exe /setreimage /path %wim_partition_letter%\Recovery\WindowsRE /target %user_volume%\Windows
    
    echo %date%-%time%:: Running Dism /english /logpath=%wimfile_path%\dism.log /scratchdir=%wimfile_path%\ /get-wimbootentry /path=%user_volume%\  piping into %~dp0temp.txt ,,,
          dism /english /logpath=%wimfile_path%\dism.log /scratchdir=%wimfile_path%\ /get-wimbootentry /path=%user_volume%\ 1> %~dp0temp.txt 2>&1
    type %~dp0temp.txt
    
    set output_text=%~dp0temp.txt
    
    find /i "install.wim" %output_text%
    if %errorlevel% neq 0 (
     echo The file: install.wim not found. Script failed, exiting.
    pause
     exit /b %errorlevel%
    )
    
    echo Found install.wim, good.
    
    for /f "skip=4 tokens=1,2,3,4,5" %%a in (%output_text%) do (
     if /i "%%a %%b %%c %%d" equ "Data Source ID :" ( set ds_id_install_wim=%%e )
     if /i "%%~nxd" equ "install.wim" ( set wimfile_install_wim=%%~nxd & goto _end_for1 )
    )
    :_end_for1
    
    echo dsid=%ds_id_install_wim%
    echo wim=%wimfile_install_wim%
    
    
    find /i "custom.wim" %output_text%
    if %errorlevel% neq 0 (
     echo The file: custom.wim is not found. Script failed, exiting.
    pause
     exit /b 2
    )
    
    
    echo Found custom.wim,
    for /f "skip=4 tokens=1,2,3,4,5" %%a in (%output_text%) do (
     if /i "%%a %%b %%c %%d" equ "Data Source ID :" ( set ds_id_custom_wim=%%e )
     if /i "%%~nxd" equ "custom.wim" ( set wimfile_custom_wim=%%~nxd & goto _end_for2 )
    )
    :_end_for2
    
    echo dsid=%ds_id_custom_wim%
    echo wim=%wimfile_custom_wim%
    
    
    echo %date%-%time%:: Running Dism /logpath=%wimfile_path%\dism.log /scratchdir=%wimfile_path%\ /update-wimbootentry /path=%user_volume%\ /imagefile="%wim_partition_letter%\Windows Images\install.wim" /datasourceID=%ds_id_install_wim% ,,,
    dism /logpath=%wimfile_path%\dism.log /scratchdir=%wimfile_path%\ /update-wimbootentry /path=%user_volume%\ /imagefile="%wim_partition_letter%\Windows Images\install.wim" /datasourceID=%ds_id_install_wim%
    
    echo %date%-%time%:: Running Dism /logpath=%wimfile_path%\dism.log /scratchdir=%wimfile_path%\ /update-wimbootentry /path=%user_volume%\ /imagefile="%wim_partition_letter%\windows images\custom.wim" /datasourceID=%ds_id_custom_wim% ,,,
    dism /logpath=%wimfile_path%\dism.log /scratchdir=%wimfile_path%\ /update-wimbootentry /path=%user_volume%\ /imagefile="%wim_partition_letter%\Windows Images\custom.wim" /datasourceID=%ds_id_custom_wim%
    
    
    if %errorlevel% neq 0 (
     echo ERROR: Dism failed. Exiting script.
    pause
     exit /b %errorlevel%
    )
    
    echo Setting permissions (ACLS) on "%wim_partition_letter%\Windows Images" ,,, 
    icacls "%wim_partition_letter%\Windows Images" /grant:r SYSTEM:(F) /T 
    icacls "%wim_partition_letter%\Windows Images" /inheritance:r /T 
    icacls "%wim_partition_letter%\Windows Images" /grant:r *S-1-5-32-544:(R) /T
    icacls "%wim_partition_letter%\Windows Images" /grant:r SYSTEM:(R) /T 
    
    
    echo %date%-%time%:: All done.  Errorlevel={%errorlevel%}
    dir %wim_partition_letter%\ /s /a
    echo *************** PLEASE MAKE SURE TO BOOT THE OS 
    echo  IN ORDER TO LET NEW WIMBOOT ENTRIES TAKE EFFECT *****************
    echo ------- After booted to the OS, you can delete the .wim files under 
    echo  {%wimfile_path%} to regain space on Windows partition {%user_volume%} 
    echo ----------------
    
  2. Run the script from Windows PE 5.1 to set up the Images partition.

    Script format: CalculateAndCreateWIMBootPartition*<Drive letter of Windows volume> <Path to install.wim and custom.wim> <Path to winre.wim> <Additional free space to be added to Images partition, in megabytes. If no additional space is needed, use 0.>*

    CalculateAndCreateWIMBootPartition C: C:\Recycler\WIMs C:\Recycler\WIMs 0
    

    The script creates an Images partition, moves in the .wim files, and updates the pointer files. When the script is complete, the Images partition should contain 50 MB of free space.

Note

After the script is run, you'll still have the temporary Windows, Windows RE, and scratch folders with the original WIM files on the disk. You won't be able to remove them until you reboot the PC.

Perform final reboot and cleanup

  1. To remove the temporary files, you can do either of the following:

    • Reboot the PC to Windows PE to allow the changes to take effect, and then delete the temporary files.

      rd C:\Recycler /s /q
      
    • Use an Unattend file with the setting Microsoft-Windows-Shell-Setup\FirstLogonCommands to run a script that includes this command:

      rd C:\Recycler /s /q
      
  2. Recommended: If you generalized the image when performing the factory floor customizations, allow the PC to boot up once to Windows in order to speed up the first boot experience for the end user. After the PC reaches the OOBE screen, you can safely turn off the PC without shutting it down.

Optional: Validate your WIMBoot deployment

See Also

Tasks

Deploy WIMBoot Images: If you know the size of the images upfront
Create WIMBoot Images

Concepts

Windows Image File Boot (WIMBoot) Overview