Windows PE 2.0 Tutorial

Do you want to create a custom boot CD, or run your Windows application in such an environment such as Vista installation, or build a image running like a Vista installation, or re-pack the Vista installation? If so, Windows PE is a good choice.

If you have no idea about Windows PE, please see Windows PE 2.0 for Windows Vista Overview and Windows Preinstallation Environment for more information. Please pay attention on the "Windows PE Limitations" section of Windows PE 2.0 for Windows Vista Overview.

Now, let me build a PE image and set up iSCSI network on PE step by step.

Create a Simple Boot Image

First, install AIK. You can download from the Microsoft official web site: Windows Automated Installation Kit (AIK). AIK is released as an image file, you will need a tool such as a daemon to mount it as a CD. Here, I installed AIK under c:\Program Files\Windows AIK.

Second, you can create a PE image by the steps said on Walkthrough: Create a Custom Windows PE Image if you never have done it. Here, I create a batch file as below, so that I don't need to keyin the same commands every time.

title Win PE 2.0 Auto-building
@echo off
::------------------------------------------------
:: Variables
::------------------------------------------------
Set PE_FOLDER=c:\vistape
Set VMNETWORK_DRIVERS=c:\VMTools_Driver\vmxnet\*.inf
Set PE_BASIC_FILES=c:\vista_wim_initial
Set AIKTOOL_PATH="c:\Program Files\Windows AIK\Tools\PETools"
  • PE_FOLDER is the path where the PE image will be stored. You don't need to create this folder; this batch will create it.
  • VMNETWORK_DRIVERS is the path where VMWare network drivers are stored. Because I will run the PE image on a VMWare virtual machine, I have to insert required network drivers of VMWare. To get drivers from VMWare Tools, select [VM/Install VMWare Tools] on the toolbar of VMWare Server Console, and then open the CD-ROM in your guest virtual machine. You will see the drivers on CD-ROM:\program files\VMware\VMware Tools\Drivers. In this case, copy the drivers to c:\VMTools_Driver.
  • PE_BASIC_FILES is the path that stores some windows applications that will run on a PE boot; some others required configurations. It includes two folders: "ISO" and "mount".
    In the ISO folder: Including peimage.exe that was copied manually; in this case, from c:\Program Files\Windows AIK\Tools\PETools.
    In the mount folder: Nothing is included.
  • AIKTOOL_PATH is the path where AIK was installed.
::------------------------
::Create PE directory
::------------------------

rd /s/q %PE_FOLDER%
c:
cd \
cd %AIKTOOL_PATH%
call copype.cmd x86 %PE_FOLDER%
cd %AIKTOOL_PATH%

::------------------------------------------------
:: Install all required packages and drivers in WIM
::------------------------------------------------

imagex /mountrw %PE_FOLDER%\winpe.wim 1 %PE_FOLDER%\mount

peimg /inf=%VMNETWORK_DRIVERS% %PE_FOLDER%\mount\windows

imagex /unmount %PE_FOLDER%\mount /commit

::------------------------------------------------
:: Create PE bootable image
::------------------------------------------------

del %PE_FOLDER%\ISO\sources\boot.wim
copy %PE_FOLDER%\winpe.wim %PE_FOLDER%\ISO\sources\boot.wim
oscdimg -n -b%PE_FOLDER%\etfsboot.com %PE_FOLDER%\
   iso %PE_FOLDER%\vistape.iso
pause

The above is the required command as said in Walkthrough: Create a Custom Windows PE Image. Where peimg /inf=%VMNETWORK_DRIVERS% %PE_FOLDER%\mount\windows is to import and install VMWare network drivers to the PE image.

Right-clicking the batch file and clicking Run As Administrator, the PE boot image will be created under C:\vistape named vistape.iso. Mount vistape.iso to the CD-ROM of a empty virtual machine; then, start up the virtual machine. You will see that it boots like Vista Installation at the beginning; it then displays a command promty and brings up the network; it needs several minutes. You can type "ipconfig" to find the IP:

You can read How Windows PE Works if you are interested.

Windows PE 2.0 Tutorial

Insert the Windows Application

I suggest that you read Windows PE Customization How-To Topics before continuing, especially the Add an Application to a Windows PE Image topic.

I created a MFC application, named it HelloPE, using Visual Studio 2005 with SP1 installed. Then, select [Project -> HelloPE Properties] on the toolbar and do the following configurations:

  1. [Configuration properties]/[General], set [Use of MFC] as "Use MFC in a Static Library".
  2. [Configuration properties]/[C/C++]/[Code Generation], set [Runtime Library] as "Multi-threaded (/MT)".

Then, build in Release mode to generate HelloPE.exe.

Go back to the C:\vista_wim_initial\mount folder, and create two folders named "Program Files" and "windows". In Program Files/MyApp, you can input any Windows application you want to run. Here, I insert the HelloPE.exe.

Note: Sometimes, you have to input Microsoft.VC80.ATL, Microsoft.VC80.CRT and Microsoft.VC80.MFC folders under the same folder with your application to guarantee your application will work well on the PE environment. You can find those folders in the directory where Visual Studio 2005 installed.

In windows/system32, these three files should be inserted : MFC42D.DLL, MSVCRTD.DLL, and oledlg.dll. You can find them in the directory where Visual Studio 2005 installed.

Re-run the batch file to create the PE image. When PE boots up, go to X:\Program Files\MyApp, run HelloPE, and you will get like this:

[hello.JPG]

If you want, PE can auto-runup HelloPE when it boots up, create a winpeshl.ini under windows/system32, (See Include a Custom Script in a Windows PE Image for more information) which the content is:

[LaunchApps]
"%SYSTEMDRIVE%/Program Files/MyApp/HelloPE.exe"

When PE boots up, you will get something like this:

[auto_hello.JPG]

Windows PE 2.0 Tutorial

(Optional) Setup iSCSI Initiator of PE

This is a hot topic on many discussion forum; however, there has been no solution until now. Here, let me show you how to start up the iSCSI initiator if you need. iSCSI initiator is installed by default in Vista, so I prepare a virtual Windows XP machine to find the difference after iSCSI initiator been installed.

Then, I export the Registry and install Microsoft iSCSI Software Initiator that was downloaded from Microsoft Download Center. After iSCSI initiator is installed, I exported the Registry and compared with the original ones. Then, save the difference as a new file, named winpe_iscsi.reg. You can download it.

It took me a lot of time to figure out all the needed driver files needed to start up iSCSI on PE environment. Here is the required drivers list; please copy them to as the following destination, and download from Microsoft if the file is not found on your system:

[iscsi.jpg]

Modify the batch file to add the Registry to PE:

::------------------------------------------------
:: Install all required packages and drivers in WIM
::------------------------------------------------
imagex /mountrw %PE_FOLDER%\winpe.wim 1 %PE_FOLDER%\mount

xcopy %PE_BASIC_FILES%\mount\windows %PE_FOLDER%\mount\windows\
   /a /e /k
md "%PE_FOLDER%\mount\Program Files\MyApp"
xcopy "%PE_BASIC_FILES%\mount\Program Files\MyApp" "%PE_FOLDER%\
  mount\Program Files\MyApp"  /a /e /k
peimg /inf=%VMNETWORK_DRIVERS% %PE_FOLDER%\mount\windows

reg load HKLM\winpe-system %PE_FOLDER%\mount\windows\system32\
  config\system
reg import %PE_BASIC_FILES%\winpe_iscsi.reg
reg unload HKLM\winpe-system

imagex /unmount %PE_FOLDER%\mount /commit

Don't forget to remove winpeshl.ini form windows/system32 before you run the batch. When PE boots up, start iSCSI initiator by using the command:

net start msiscsi

Then, you will get something like this:

[iscsipe.JPG]

More Information

Re-pack Vista Installation

This is a big topic; please refer to Windows Vista Deployment Step by Step Guide for more detail. Windows System Image Manager (Windows SIM) allows you to add/remove language packages, drivers, or other things for you to/from *.wim. The following figure is components and packages list shown on SIM after I load install.wim from Vista Installation CD.

[SIM.jpg]



About the Author

Reta Pan

A R&D Software Engineer in Taiwan.
International High IQ Society Member, New York.
MCSD(Microsoft Certified Solution Developer (for Microsoft .NET))
Web Site: Anpino's Circle
English is not my primary language, I will be glad to receive your response, especially the advises that you can provide regarding my poor English.

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • The proliferation of cloud computing options has begun to change the way storage is thought about, procured, and used. IT managers and departments need to think through how cloud options might fit into and complement their onsite data infrastructures. This white paper explains cloud storage and backup, providing advice about the tools and best practices for its implementation and use. Read this white paper for some useful takeaways about how to take advantage of cloud storage for high availability, backup and …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds