Windows 8 – Create and Apply Windows Image

First of all i save all files to a network share. It makes all a bit easier. Create following two files on the root of the network share.

CreatePartitionsUEFI.txt

rem == CreatePartitions-UEFI.txt ==
rem == These commands are used with DiskPart to
rem create five partitions
rem for a UEFI/GPT-based computer.
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

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

Now we want to save our Image from the Master PC. We must start Sysprep first.

C:\windows\system32\sysprep\sysprep /generalize /shutdown /oobe

Then start your PC with the Windows PE USB Stick or CD.

Now you can connect your network share like this:

net use n: \\your_server\your_share

Then we create the windows image file:

dism /capture-image /imagefile:N:\install.wim /capturedir:D:\ /Name:Windows

Please note: If your /capturedir is not automatically mounted you can do this with diskpart.

diskpart
select disk 0
list partition
select partition 2
assign letter D
exit

Please note: You can change the drive letter what you like. Don’t forget to change afterwards in your dism command.
Now your Image should be saved on your network share. Now it’s time to apply the image to another computer.

Start the other computer also with Windows PE. Mount your network share:

net use n: \\your_server\your_share

Now run following two commands:

diskpart /s n:\CreatePartitionsUEFI.txt
n:\ApplyImageUEFI.bat n:\install.wim

It’s possible that you get at the end some error. No matter i don’t know why they came up but it works! 😉

Leave a Reply

Your email address will not be published. Required fields are marked *