Wednesday, July 17, 2013

Deploying Windows 8 using the Windows ADK and WinPE

After spending a chunk of today trying to get imaging and deployment of Windows 8 figured out I decided it was worth a post since the scripts Microsoft provides are either slightly incorrect or missing information. I started out with this TechNet article and this other, then built the final solution from there.

First, use the article to get the Windows ADK, which will allow you to create bootable WinPE media. You can either create a bootable USB device like the article states, or create an iso image file that can be burned to a CD. Personally I prefer CD because it seems to be the most compatible since everything can boot from CD, but not everything likes booting from USB. To create the iso file instead of the USB in their step 1.3, use the command MakeWinPEMedia /ISO /C:\winpe_amd64 C:\winpe.iso. That will create the ISO file named winpe.iso in the root of the C drive using the directory located at C:\winpe_amd64. If you want to change those paths, feel free, especially for the location of the iso file.

From this point on I was able to capture the system image using the directions outlined in the TechNet article, so refer to that for image capture.

Deployment is where I started running into problems. I have a pile of cheap Dell Inspirons, and they were using UEFI booting. I'm not going to get into MBR/BIOS since I didn't deal with that and don't know if the article is correct, but the scripts provided for the UEFI option need some tweaking.

For the create partition script, use the script below instead of what Microsoft provided. I have bolded the changes I made. For the line with shrink minimum, adjust this so it's big enough to hold your system image. 14GB is what they have it set to, and my image came out to just over 7 so if I didn't adjust it I would've wasted 7GB of hard drive space.

rem These commands are used with DiskPart to
rem erase the drive and create five partitions
rem for a UEFI/GPT-based computer.
rem Adjust the partition sizes to fill the drive as necessary.
select disk 0
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
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 Windows partition =========== 
create partition primary 
rem ==    b. Create space for recovery image ====  
shrink minimum=10000
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

You can name that CreatePartitions.txt as suggested, or use your own file name. Make sure you copy it onto a USB drive or something that is accessible to the machine you will be deploying the image to. You can use the instructions in the TechNet article to run this script (e.g. diskpart /s E:\CreatePartitions.txt if the script file is saved on something mapped to the letter E).

Now, for the batch file that actually deploys the image you need to make a few tweaks to this as well to get it to work. Use the below

rem These commands use the specified Windows image file 
rem to deploy Windows, system, and recovery tools 
rem to a UEFI-based computer.

rem Usage:   ApplyImage WimFileName 
rem Example: ApplyImage E:\Images\ThinImage.wim

rem === Apply the image to the Windows partition ========
dism /Apply-Image /ImageFile:%1 /Index:1 /ApplyDir:W:\

rem === Copy 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 to the System partition =========
W:\Windows\System32\bcdboot W:\Windows /s S: /f ALL

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

rem === Create the recovery image =======================
Mkdir R:\RecoveryImage
Copy %1 R:\RecoveryImage
W:\Windows\System32\reagentc /setosimage /path R:\RecoveryImage /target W:\Windows /index 1

To actually have the system partition recognizable as UEFI you need to add the /f ALL to the bcdboot command. Also, they made a bad typo in the very last line by getting the drive letters mixed up. They have it as T in their script, but it needs to be R.

With those few changes I was able to successfully deploy Windows 8 just like I had been doing for Windows 7 machines using WinPE and imagex.exe. Hopefully this will save you from trying to figure out what is wrong with the scripts Microsoft provides. I did send them feedback outlining the mistakes, but whether or not they'll actually update it is yet to be seen. Good luck with your deployment!