Samples: Applying Windows, System, and Recovery Partitions by using a Deployment Script
Applies To: Windows 8, Windows 8.1, Windows Server 2012, Windows Server 2012 R2
This topic includes scripts that configure system and recovery partitions during deployment based on a single Windows image. You can use these scripts on Unified Extensible Firmware Interface (UEFI) and GUID Partition Table (GPT)-based computers or on BIOS and master boot record (MBR)-based computers. The Capture and Apply Windows, System, and Recovery Partitions topic describes this process. The following diagram illustrates this process:
UEFI and GPT-based computers
Copy the DiskPart script for "Windows RE Tools, System, MSR, Windows, and Recovery Image Partitions" in the Sample: Configure UEFI/GPT-Based Hard Drive Partitions by Using Windows PE and DiskPart topic into Notepad. Save the script as CreatePartitions.txt.
Copy the following script into Notepad, and then save the script as ApplyImage.bat:
rem These commands copy the selected image file to rem predefined hard disk partitions on a UEFI-based computer. rem Usage: ApplyImage WimFileName rem Example: ApplyImage E:\Images\ThinImage.wim rem === Copy the image to the recovery image partition ======================= copy %1 R:\install.wim rem === Apply the image to the Windows partition ============================= dism /Apply-Image /ImageFile:R:\install.wim /Index:1 /ApplyDir:W:\ rem === Copy the Windows RE Tools to the Windows RE Tools partition ========== md T:\Recovery\WindowsRE copy W:\windows\system32\recovery\winre.wim T:\Recovery\WindowsRE\winre.wim rem === Copy boot files from the Windows partition to the System partition === bcdboot W:\Windows rem === In the System partition, set the location of the Windows partition === W:\Windows\System32\reagentc /setosimage /path R: /target W:\Windows /index 1 rem === In the System partition, set the location of the WinRE tools ========= W:\Windows\System32\reagentc /setreimage /path T:\Recovery\WindowsRE /target W:\Windows
On the destination computer, run the Diskpart and ApplyImage scripts to apply the image to the computer and set up the WinRE tools, Windows, system, and recovery partitions. For example:
diskpart /s E:\CreatePartitions.txt ApplyImage E:\Images\ThinImage.wim
where E:\Images\ThinImage.wim is the name of your Windows image file.
To apply the recovery image, you might need to change the attributes of the winre.wim file because it is a hidden system file:
attrib WinRE.wim -h -s -r
BIOS and MBR-based computers
Copy the DiskPart script for "System, Windows, and Recovery Image Partitions" in the Sample: Configure BIOS/MBR-Based Hard Disk Partitions by Using Windows PE and DiskPart topic into Notepad. Save the file as CreatePartitions.txt.
Copy the following script into Notepad, and then save the file as ApplyImage.bat:
rem These commands copy the selected image file to rem predefined hard disk partitions on a BIOS-based computer. rem Usage: ApplyImage WimFileName rem Example: ApplyImage E:\Images\ThinImage.wim rem === Copy the image to the recovery image partition ======================= copy %1 R:\install.wim rem === Apply the image to the Windows partition ============================= dism /Apply-Image /ImageFile:R:\install.wim /Index:1 /ApplyDir:W:\ rem === Copy the Windows RE Tools to the system partition ==================== md S:\Recovery\WindowsRE copy W:\windows\system32\recovery\winre.wim S:\Recovery\WindowsRE\winre.wim rem === Copy boot files from the Windows partition to the System partition === bcdboot W:\Windows rem === In the System partition, set the location of the Windows partition === W:\Windows\System32\reagentc /setosimage /path R: /target W:\Windows /index 1 rem === In the System partition, set the location of the WinRE tools ========= W:\Windows\System32\reagentc /setreimage /path S:\Recovery\WindowsRE /target W:\Windows
On the destination computer, run the Diskpart and ApplyImage scripts to apply the image to the computer and set up the system, Windows, and recovery partitions. For example:
diskpart /s E:\CreatePartitions.txt ApplyImage E:\Images\ThinImage.wim
where E:\Images\ThinImage.wim is the name of your Windows image file.
To apply the recovery image, you might need to change the attributes of the winre.wim file because it is a hidden system file:
attrib WinRE.wim -h -s -r
See Also
Tasks
Sample: Configure UEFI/GPT-Based Hard Drive Partitions by Using Windows PE and DiskPart
Sample: Configure BIOS/MBR-Based Hard Disk Partitions by Using Windows PE and DiskPart
Capture and Apply Windows, System, and Recovery Partitions
Concepts
Configure UEFI/GPT-Based Hard Drive Partitions
Configure BIOS/MBR-Based Hard Drive Partitions