How to create a Windows PE Disk (part 2)


It is time for part 2 of this guide to making yourself a Windows PE disk. You can read more about the first part here. This post we will cover following: how to integrate drivers, add 3rd party/applications/files to your image, unmount the image and burn it to an ISO file. I also want to say that this is a scripted approach, and all data and scripts are in the E:\PE path in this guide. The scripted approach will come in handy when you are doing tens of rebuilds of the image because a certain driver will not integrate, or a registry file modification does not work.

Integrate Drivers into WinPE Image

First thing on the agenda here is to get the actual drivers you want to integrate into the Image. For most use cases it is enough to integrate Storage and Network drivers, and perhaps Chipset drivers. You also need to take into account the WinPE version you are building, in this guide, we build a x86 WinPE Image so my focus was on x86 drivers for Windows 7/ 2008 /2008 R2. Now go out and grab those CD’s or vendor provided tools (Hyper-V Integration components or VMware Tools).

Some vendors ship other applications along with drivers, you don’t need the extra files most of the time, because WinPE doesn’t know how to use them most of the time. From the drivers in the list WinPE needs *.inf, *.cat and *.sys files corresponding to each driver you want to integrate and ANY other file specified in the *.inf file. Be patient with this process, as it can be sometimes painstaking and will cause you to rebuild your image until you get it right, until you find all the drivers and files you need 🙂

Let’s take the example of VMware Tools for vSphere. If you want your WinPE to boot into vSphere and be able to see your storage adapters and network cards you need to integrate the drivers from VMware Tools.

Step1: On a VM running Windows 2008/ Windows 7 on vSphere start an interactive VMwareTools Install.

Step2: Install your VMware Tools and reboot VM. Now take a look in %programfiles%\vmware\vmware tools\drivers\ – driver heaven! Copy the needed folders from here into a folder called “E:\PE\Drivers\ESX_40” (e:\PE is the location where we run our WinPE imaging process).

For other drivers you may need to take a different approach. I will just share from my experience. Drivers can be in *.cab cabinet files, in *.zip files, inside MSI files, which you kinda have to install to get to (see vmware tools case), even install a driver and then look in device manager where the device driver exists and search for a similarly named *.inf, sys and *.cat file and all the other files referenced in the *.inf file.

When you have all your drivers run this as administrator from a command prompt:

c:
cd \
cd "%PROGRAMFILES%\windows aik\Tools\x86\Servicing"
DISM /image:e:\pe\winpe_x86\mount /Add-Driver /driver:e:\PE\Drivers\ /recurse

Here you run the DISM tool using /add-driver switch, /driver specifying where the drivers are located, and /recurse to make it look in all subfolders in e:\PE\Drivers. This is one of the sweetest things about the DISM, is that it can recursively search for drivers (in WinPE 2.0 you had to have 1 command per folder containing drivers).

The output of the command should look like this:

As you can see DISM searched the folder and found 84 drivers (inf files that he can integrate). I had 85 inf files inside that folder, one failed, and you see DISM threw and error. This is however just a “pre-flight” check, as there can still be errors during the actual integration:

As you can see in this screenshot, DISM could not integrate some of the drivers and pointed to the DISM log file. This file can be found in %WINDIR%\Logs\DISM\dism.log.

For those that just want to test their driver integration skip the next step.

Adding Custom Scripts/Applications to the Image

In an earlier post, I showed how to mount the WinPE Image. The Image was mounted under “E:\PE\winpe_x86\mount”. If you take a look in this folder you will notice a folder structure resembling a windows install…well that is exactly what it is – all Windows PE files unpacked, as they would look like if booted with the image. This means you can add files under %windir%\system32 of the image (in our case Windows\e:\pe\winpe_x86\mount\windows\System32) and you would be able to execute them as %windir%\system32 is in the %path% environment variable of the Windows OS. Note that not all apps run under Windows PE, sometimes it is a matter of trial and error.

So it is just a matter of copying the files you need from a path, let’s say “e:\PE\CustomApps\” to wherever you want in the folder structure “e:\PE\winpe_x86\mount\”. Use a manual copy or do an xcopy like this for example:

xcopy /y /r /F E:\PE\CustomApps E:\PE\winpe_x86\mount\Windows\System32

It is a little known fact about Windows PE that it has a batch file called “startnet.cmd”. This file includes a command “wpeinit”. wpeinit is an executable that is run when WindowsPE boots on your system (more info here). While I don’t care much about wpeinit itself, I do care about startnet.cmd. This file you can modify/overwrite at this point with a custom made startnet.cmd that can start other scripts, check IP connectivity anything you need to do with your WinPE boot disk. Similar to putting custom apps on WinPE you can do this:

xcopy /h /Y /R /F "E:\PE\CustomScripts\startnet.cmd" "E:\PE\winpe_x86\mount\Windows\System32\startnet.cmd"

I am stressing the importance of this file because, you can access it only at boot time and it is “hard-coded” into the WIM file (you cannot change it after you unmount the WIM and build the ISO afterwards). Therefore, since startnet.cmd cannot be altered after building the image, it could make sense to have startnet.cmd point to a file say, autorun.cmd, that you can put on the root of the ISO file for example. And there are many ISO editing tools,so changes to autorun.cmd are easier to make, for editing a WIM things are not so straightforward.

Still following this? Good, because the worst part is over 🙂

Unmount Image and burn to ISO

This last step is fairly easy. DISM has a parameter to unmount the image and commit the changes to the Image. If you remember in the beginning we copied boot.wim to winpe.wim. now we overwrite the existing boot.wim image with our serviced image. The commands below do just that:

c:
cd "%PROGRAMFILES%\windows aik\Tools\x86\Servicing"
::commit changes to image and unmount
Dism.exe /Unmount-Wim /mountdir:E:\PE\winpe_x86\mount /commit
copy E:\PE\winpe_x86\winpe.wim e:\pe\winpe_x86\ISO\sources\boot.wim /Y

In the current state you have 2 options:

1. Copy the contents of the E:\pe\winpe_x86\iso folder to a bootable USB stick or make an iso file out of it. For now let’s focus on making a ISO file.

Microsoft delivered OSCDIMG with the WAIK, a utility that can create the bootable ISO for us.

cd \
C:
cd "%PROGRAMFILES%\windows aik\Tools\x86"
::"-b" MUST BE next to path for etfsboot.com
OSCDIMG -bE:\PE\winpe_x86\etfsboot.com -n -o E:\PE\winpe_x86\iso E:\PE\Current_ISO.iso

Please note the comment in the script, “feature” or bug you don’t need a space between -b and the etfsboot,com file.

This should have successfully built the image and you can burn it to a CD/mount it in a VM and enjoy a Microsoft Supported Windows 7 live CD :). Before you go take a mental break from all this reading I just want to point out that Windows PE will crash if you run it on a system with insufficient memory.

Why? The boot disk creates a Ramdisk where he loads Windows PE. If there is not enough RAM memory (typically you have this issue on old hardware or VM’s) it will crash and simply not load. As a rule of thumb the machine using it should have at least 1.8 -2.0 the size of the ISO file as RAM available on the machine.

I hope this was helpful for others looking to use WinPE as boot disk and I appreciate any feedback you may have.

How to create a Windows PE boot disk

Some time ago I worked a lot on this topic, and had a good system for creating Windows PE disk, but recently I had to adapt the workflow to changes in the WAIK (Windows Automated Installation Kit) introduced with Windows 7/2008 R2. I won’t go into details on what’s new, but as far as I am concerned it made the whole process quite a bit easier.

Maybe I should explain also what the rest of the Internet will probably tell you: “What is Windows PE?”

Answer: Windows PE is a lightweight version of the Windows operating system.

Why should you care about Win PE?

Answer: Well because you can…

-Access the NTFS shares, map drives and copy data over the network

-Format and partition disks and make bootable USB sticks

-Run admin tools like PsTools, NTPWEdit (password recovery)

-Run WMI and batch scripts to automate Windows 2003 Server / Xp installations

-Edit offline registry of a PC (e.g. change it’s IP address, start/stop services) when you can’t login to the OS for some reason.

It’s been around since Windows Xp (versions 1.x), but only since version 2.0 and now version 3.0 do have some real punch to them. In a way I think it is better than other Windows boot CD’s like Bart and the likes, because you can get MS support and it provides a “clean”,”supported” way to customize it over time with drivers and apps.

Here’s what we will do to get a working WinPE 3.0 boot image:

  1. Download WAIK and install it
  2. Copy files from the WAIK source folder.
  3. Mount the WIM image
  4. Add additional components to the WIM
  5. Integrate drivers into the image
  6. Add applications/other scripts/files to the image
  7. Unmount WIM Image
  8. Burn the image into an ISO file

WAIK Installation

In order to create this WinPE disk you need the WAIK (Windows Automated Installation Kit). This is for WinPE version 3, there are more versions of this WAIK out there, and this tutorial only works for WinPE 3.0.After you’ve downloaded it simply mount and install it. Should you have any issues with the installation (i have some trouble in the days of 2.x) check the contents of the ISO image there should be some file called “wAIKX86.msi” that you can use to launch the installation on a 32b OS, same goes for 64b OS. Installation is pretty simple, next next next.

Copy Required files

I should get this out of the way from the start. These steps are a scripted approach to make a boot disk. While I’m sure there is a GUI somewhere, while I was building my workflow using it was impractical, as I needed a way to reduce user errors and test quickly different approaches in an automated way.

To make this whole process easier make sure you add following paths to your %PATH% environment variable: %PROGRAMFILES%Windows AIK\Tools\PETools

Also create a folder where you have full administrator rights (in this post i use “e:\PE”). Save yourself some headache and use a shortname with no spaces. Needless to say you need to be an administrator on the computer you are using for this task and all of the commands need to be run from an elevated command prompt.

First step is to get ourselves all the files that we will need to make the image. These files are installed by the WAIK installer, and MS also conveniently provides a batch script that copies everything. From the elevated prompt run this:

start /wait cmd /c copype.cmd x86 e:\PE\winpe_x86

We use copype.cmd located under %PROGRAMFILES%Windows AIK\Tools\PETools. The script copies the x86 WinPE files to a customization directory.

Mount the WIM Image

Next we use DISM to mount the boot.wim image and begin servicing it. MS introduced this tool called DISM (Deployment Image Servicing and Management) as a single point of servicing the WinPE image.

c:
cd "%PROGRAMFILES%\windows aik\Tools\x86\Servicing"
Dism.exe /mount-wim /wimfile:"E:\PE\winpe_x86\winpe.wim" /index:1 /mountdir:"E:\PE\winpe_x86\mount"
::list packages installed - do not use quotes in image name
dism /image:E:\PE\winpe_x86\mount /Get-Packages

We mount the image (a .WIM file) to the “e:\PE\winpe_x86\mount” directory. Once we mount the image we can do anything with the files inside the mounted image. I also did a listing of the packages inside the image so you can see what’s inside it. We just have the basics, a language pack, and the foundation. When using dism with /image be careful to not use quotes in the image name.

Add WIM components

Now we can add so called packages to the WIM image. These packages are extra features you may want your image to have, like WMI support, MDAC support, Windows 7/Windows 2008 server setup screens, support for other languages, etc. For a list of the available package for the WinPE x86 version look in %PROGRAMFILES%Windows AIK\Tools\PETools\x86\WinPE_FPs.

c:
cd\
cd "%PROGRAMFILES%\windows aik\Tools\x86\Servicing"
::adding packages
Dism /image:e:\PE\winpe_x86\mount /Add-Package /PackagePath:"%programfiles%\Windows AIK\Tools\PETools\x86\<add-your-package-filename-here>"
::add here any other packages you need

For enabling vbs and WMI support add these packages: winpe-scripting.cab, winpe-wmi.cab, winpe-mdac.cab, winpe-hta.cab. I’ve added MDAC and HTA packages to the list in case your vbs scripting requires them, There are corresponding packages in the en-us folder, add them aswell, with the syntax above. This is how the output should look like once you run all commands for adding the packages:

In the end run dism /image:E:\PE\winpe_x86\mount /Get-Packages to list the packages you installed.

This covers half the process I described at the start of this post. in the coming days the second part of this tutorial will be finished. I hope you found it useful, have a great week!