Jump to content

Configure UEFI/GPT-Based Hard Drive Partitions by Using Windows PE and DiskPart and Applying Windows, System, and Recovery Partitions by using a Deployment Script


m!r@cle

Recommended Posts

Updated: October 20, 2013

Applies To: Windows 8, Windows 8.1, Windows Server 2012, Windows Server 2012 R2

To prepare to deploy a Windows® image to a new PC, you can create partitions by using a DiskPart script. This topic provides examples of how to configure disk partitions for a PC that is based on Unified Extensible Firmware Interface (UEFI) firmware and whose disks use a GUID partition table (GPT). This topic covers the following partition configurations:

  • Default configuration. Includes a Windows Recovery Environment (Windows RE) Tools partition, a system partition, a Microsoft® Reserved Partition (MSR) partition, and a Windows partition. The following diagram shows this configuration.

    Diagram of default EFI partitions
  • Recommended configuration. Includes a Windows RE Tools partition, a system partition, an MSR partition, a Windows partition, and a recovery image partition. The following diagram shows this configuration.

    Diagram of EFI partitions with recovery

After you create the partitions, you can apply the Windows images on the newly created partitions.

 

For image-based deployment, use Windows Preinstallation Environment (Windows PE) to boot the PC. Then, use the DiskPart tool to create the partition structures on your destination PCs. For more information, see WinPE for Windows 8: Windows PE 5.0.

noteNote
Windows PE reassigns disk letters alphabetically, starting with the letter C, without regard to the configuration in Windows Setup. This configuration can change based on the presence of different drives, including USB flash drives.

 

In these DiskPart examples, the partitions are assigned the letters T, S, W, and R to avoid drive-letter conflicts. After the PC reboots, Windows PE automatically assigns the letter C to the Windows partition. The system partition, the Windows RE tools partition, and the recovery image partition do not receive drive letters.

 

 

The following steps describe how to partition your hard drives and prepare to apply images. You can use the code in the sections that follow to complete these steps.

 

  1. Save the code in the following sections as a text file (CreatePartitions.txt) on a USB flash drive.

  2. Use Windows PE to boot the destination PC.

  3. Use the DiskPart /s F:\CreatePartitions.txt command, where F is the letter of the USB flash drive, to partition the drives.

 

Save the following code as CreatePartitions.txt, and then use the DiskPart tool to run the script that automates the configuration of the System, MSR, and Windows partitions.

 
 
select disk 0
clean
convert gpt
create partition primary size=300
format quick fs=ntfs label="Windows RE tools"
assign letter="T"
create partition efi size=100
rem == Note: for Advanced Format Generation One drives, change to size=260.

format quick fs=fat32 label="System"
assign letter="S"
create partition msr size=128
create partition primary
format quick fs=ntfs label="Windows"
assign letter="W"

 

Save the following code as CreatePartitions.txt, and then use the DiskPart tool to run the script that automates the configuration of the Windows RE Tools partition, the System, MSR, Windows, and recovery image partitions.

 
 
rem == CreatePartitions-UEFI.txt ==
rem == These commands are used with DiskPart to
rem    create five partitions
rem    for a UEFI/GPT-based PC.
rem    Adjust the partition sizes to fill the drive
rem    as necessary. ==
select disk 0
clean
convert gpt
rem == 1. Windows RE tools partition ===============
create partition primary size=300
format quick fs=ntfs label="Windows RE tools"
assign letter="T"
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
gpt attributes=0x8000000000000001
rem == 2. System partition =========================
create partition efi size=100
rem    ** NOTE: For Advanced Format 4Kn drives,
rem               change this value to size = 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       ** NOTE: Update this size to match the size
rem                of the recovery image           **
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"
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
gpt attributes=0x8000000000000001
list volume
exit

 

If you use the recommended DiskPart script, end users do not see the Windows RE Tools partition and the recovery image partition in File Explorer. However, they can see and remove the recovery image partition by using disk management tools.

If you want to prevent end users from removing partitions by using disk management tools, you can add the following DiskPart command to the script when you create a partition.

 
 
gpt attributes=0x8000000000000001

This DiskPart command combines the GPT_ATTRIBUTE_PLATFORM_REQUIRED (0x0000000000000001) and GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER (0x8000000000000000) attributes. For more information, see DiskPart: GPT.

 

Next Steps
 
 

After you create the partitions, you can use a deployment script to apply the Windows images on the newly created partitions.

 

Applying Windows, System, and Recovery Partitions by using a Deployment Script

Updated: October 20, 2013

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:

Diagram showing capturing the Windows partition

 

  1. 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.

  2. 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
    
    
  3. 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
    
    

 

  1. 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.

  2. 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
    
    
  3. 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
    
    1. 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
      

    Sources :

1. Microsoft Technet

2. Microsoft Technet

 

Link to comment
Share on other sites


  • Replies 1
  • Views 1.9k
  • Created
  • Last Reply

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...