Export (0) Print
Expand All

Sample: Apply Images on a UEFI-based Computer by Using ImageX

Updated: June 28, 2011

noteNote
This content applies to Windows 7. For Windows 8 content, see Windows Deployment with the Windows ADK.

To prepare to deploy a Windows® image to a new computer, you can create partitions by using a DiskPart script and a script to apply images. This topic shows how to configure drive partitions for a Unified Extensible Firmware Interface (UEFI) and GUID Partition Table (GPT)-based computer, for the primary hard disk or other drive.

Default Configuration

For new installations, by default, Windows Setup will create an Extensible Firmware Interface System partition (EFI System partition, or ESP), a Microsoft® Reserved partition (MSR), and a primary Windows partition.

Partitions: ESP, MSR, Windows

The following code shows a script for the DiskPart tool that will create the default partition structure, for use in image-based deployments:

select disk 0
clean
convert gpt
rem == 1. System partition =========================
create partition efi size=100
rem ** NOTE: For 4KB-per-sector drives, change this 
rem          value to 260 **
format quick fs=fat32 label="System"
assign letter=S
rem == 2. Microsoft Reserved (MSR) partition =======
create partition msr size=128
create partition primary
rem == 3. Windows partition ========================
format quick fs=ntfs label="Windows"
assign letter=W
list volume
exit
noteNote
In this example, the Windows partition is assigned the letter "W" to avoid drive-letter conflicts. After the computer reboots, the primary hard drive is automatically reassigned to the letter "C".

Save this script as CreatePartitions.txt. To use this script to create the partitions, start the computer by using Windows Preinstallation Environment (Windows PE). At the Windows PE command prompt type diskpart /s CreatePartitions.txt.

The following code shows a script that can be used to deploy Windows by using a single Windows image located at N:\Images\my-windows-partition.wim.

rem These commands copy the selected image file to
rem predefined drive partitions on a UEFI-based computer.

rem Usage:   ApplyImage WimFileName 
rem Example: ApplyImage N:\Images\my-windows-partition.wim

rem === Apply the image to the Windows partition ========
imagex /apply %1 1 W:\

rem === Copy boot files to the System partition =========
W:\Windows\System32\bcdboot W:\Windows /s S:

Save this script as ApplyImage.bat. To run this script, at the Windows PE command prompt, type ApplyImage N:\Images\my-windows-partition.wim.

Recommended Configuration: System Recovery

In the example below, the configuration includes a Windows RE tools partition, a system partition, an MSR, a primary Windows partition, and a recovery image partition.

Partitions: WinRE, ESP, MSR, Windows, Recovery

For an image-based deployment, create an identical partition structure on the destination computer. The following code shows a script for the DiskPart tool that will create the example partition structure.

select disk 0
clean
convert gpt
rem == 1. Windows RE tools partition ===============
create partition primary size=300
format quick fs=ntfs label="WinRE tools"
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
assign letter=T
rem == 2. System partition =========================
create partition efi size=100
rem ** NOTE: For 4KB-per-sector drives, change this 
rem          value to 260 **
format quick fs=fat32 label="System"
assign letter=S
rem == 3. Microsoft Reserved (MSR) partition =======
create partition msr size=128
rem == 4. Windows partition ========================
rem ==    a. Create the Windows partition. ==========
create partition primary
rem ==    b. Create space for the recovery image. ===
shrink minimum=15000
rem ==    c. Prepare the Windows partition. =========
format quick fs=ntfs label="Windows"
assign letter=W
rem === 5. Recovery image partition ================
create partition primary
format quick fs=ntfs label="Recovery image"

assign letter=R
list volume
exit
noteNote
In this example, the Windows partition is assigned the letter "W" to avoid drive-letter conflicts. After the computer reboots, the primary drive is automatically reassigned to the letter "C".

Save this script as CreatePartitions.txt. To use this script to create the partitions, type diskpart /s CreatePartitions.txt.

The following code shows a script that can be used to deploy Windows and configure a recovery by using a single Windows image located at N:\Images\my-windows-partition.wim.

rem These commands copy the selected image file to
rem predefined drive partitions on a UEFI-based computer.

rem Usage:   ApplyImage WimFileName 
rem Example: ApplyImage N:\Images\my-windows-partition.wim

rem === Copy the image to the recovery image partition ==
copy %1 R:\install.wim

rem === Apply the image to the Windows partition ========
imagex /apply R:\install.wim 1 W:\

rem === Copy tools to the recovery tools partition ======
md T:\Recovery\WindowsRE
copy W:\windows\system32\recovery\winre.wim T:\Recovery\WindowsRE\winre.wim

rem === Copy boot files to the System partition =========
bcdboot W:\Windows /s S:

rem === Set the location of the Windows partition =======
W:\Windows\System32\reagentc /setosimage /path R: /target W:\Windows

rem === Set the location of the Windows RE tools ========
W:\Windows\System32\reagentc /setreimage /path T:\Recovery\WindowsRE /target W:\Windows

Save this script as ApplyImage.bat. To run this script, at the Windows PE command prompt, type ApplyImage N:\Images\my-windows-partition.wim.

For more information about configuring a recovery partition, see Deploy a System Recovery Image.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft