Dela via


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

Note

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 BIOS and master boot record (MBR)-based computer, for the primary hard disk or other drive.

Default Configuration

For new installations, by default, Windows Setup will create a system partition and a Windows partition.

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
rem == 1. System partition ======================
create partition primary size=300
format quick fs=ntfs label="System"
assign letter=S
active
rem == 2. Windows partition =====================
create partition primary
format quick fs=ntfs label="Windows"
assign letter=W
list volume
exit

Note

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, 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 BIOS-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.

The recommended configuration includes a system partition, a Windows partition, and a recovery image partition.

For 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
rem == 1. System partition ======================
create partition primary size=350
format quick fs=ntfs label="System"
assign letter=S
active
rem == 2. 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 == 3. Recovery image partition ==============
create partition primary
format quick fs=ntfs label="Recovery image"
assign letter=R

list volume
exit

Note

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 BIOS-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 Windows RE to the system partition =========
md S:\Recovery\WindowsRE
copy W:\windows\system32\recovery\winre.wim S:\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 S:\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.

Single Partition

In the following example, the configuration includes a single partition.

For 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
create partition primary
format quick fs=ntfs label="Windows"
assign letter=W
exit

Note

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

To apply the image to the Windows partition, use the following command.

imagex /apply N:\Images\my-windows-partition.wim 1 W:\

See Also

Concepts

Capture Images of Hard Disk Partitions by Using ImageX
Apply Images by Using ImageX
Recommended BIOS-Based Disk-Partition Configurations
Create BIOS-based Hard-Disk Partitions by Using Windows SIM
Deploy a System Recovery Image