Creating a Windows PE V2 boot environment
(See https://www-secure.symantec.com/connect/articles/adventures-winpe-31 for instructions to build a WinPE V3 environment. The two documents should be reviewed together)
The objective of this article is to outline the steps required to create and maintain the following windows PE boot environments:
- A Windows PE iso image, which can be used to create a PE bootable CD, or used with VMWare as a bootable iso image to facilitate creating VMWare operating system images.
- A bootable USB device, such as a flash memory or USB hard disk.
In addition, a method for creating a dual boot system, running either Windows XP or Windows PE will be described.
Creating the Windows PE ISO image - 32 bit
The Windows Automated Installation Kit (WAIK) first needs to be downloaded. The version used in this example was 6001.18000.080118-1840-kb3aikl_en.iso
This is currently downloadable from: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=94BB6E34-D890-4932-81A5-5B50C657DE08
This img file which is basically an iso file can be burned to a DVD or mounted on the test workstation using a virtual CD/DVD emulator such as Daemon Tools or Slysoft's Virtual CloneDrive.
Once this has been done, install the WAIK on your test workstation. This will install some help files accessible through the Start Menu, and the Windows PE Users Guide is helpful as a reference when creating your customised WinPE iso image. The following steps are recommended:
- Start the Windows PE Tools command prompt from the Start Menu.
- At the command prompt type: copype.cmd x86 c:\winpe_x86 The cmd script creates c:\winpe_x86 folder and two subfolders: ISO and mount, and copies over all required files for the specified architecture (x86 in this example).
- The next step mounts the base image to a folder on your test machine so that it can be edited to add or remove packages. At the command prompt type:
imagex /mountrw c:\winpe_x86\winpe.wim 1 c:\winpe_x86\mount
You should receive a completion message:
"Successfully mounted image (RW)"
- By using the Peimg tool, you install Windows features by using the /install option. Windows features are included with the base image (Winpe.wim) but are not installed. You can also import packages and add drivers and language packs. For more information, see Windows PE Customization How-To Topics. The following four options are included as examples:
peimg /install=WinPE-HTA-Package c:\winpe_x86\mount\Windows
peimg /install=WinPE-Scripting-Package c:\winpe_x86\mount\Windows
peimg /install=WinPE-WMI-Package c:\winpe_x86\mount\Windows
peimg /install=WinPE-XML-Package c:\winpe_x86\mount\Windows
Installing these in turn at the Windows PE Tools command prompt will ensure that they are added to the mounted winpe.wim file.
- Verify that the packages were installed by using the peimg /list command to view all packages in the current image. For example,
peimg /list c:\winpe_x86\mount\Windows
In the INS column, (+) denotes installed packages and (-) denotes not installed.
- At this point you can add any additional software you may wish to have on your PE image. Typical additions could include utility files such as Ghost32.exe and Bootsect.exe. If you want the files to be part of the booted image (which loads to the X: drive) then add them to the C:\winpe_X86\mount folder - but bear in mind that this will increase the amount of system RAM required to load the PE image. Alternatively, add the files to the ISO folder where they will be available from the boot media once PE is loaded into RAM.
Note: This version of WinPE displays a monochrome background when booting. If a colour background (Vista colours) is preferred, replace the winpe.bmp file in the C:\winpe_X86\mount\Windows\System32 folder with a version from an older release of WinPE, that has a size of 3Mb instead of 2Mb.
Adding imagex.exe from the installed WinPE toolset to the system32 folder is also a recommended step for later convenience.
- Next, you prepare the image by using the peimg /prep command. This operation removes any non-installed packages from the final image and reduces the overall image size. For example,
peimg /prep c:\winpe_x86\mount\Windows
The /prep option cannot be reverted, and after the /prep option is run, the /install, /uninstall, /import, and /list options will not function, while the /lang and /inf options will continue to function. The Peimg tool prompts you to confirm the command. To suppress this prompt for scripting, add the /f option. The prompt requires 'yes' to be entered - any other input, eg 'y' will exit the command.
- Next, you commit the changes to the original image file (Winpe.wim) by using the ImageX /unmount option with the /commit option. For example,
imagex /unmount c:\winpe_x86\mount /commit
- Having created a new winpe.wim file in the C:\winpe_X86 folder, you must now replace the default Boot.wim in the \ISO directory with your new customized image. The image must be called Boot.wim. For example,
copy c:\winpe_x86\winpe.wim c:\winpe_x86\ISO\sources\boot.wim
You now have a customized Windows PE RAM disk image that you can place on bootable media, like a CD-ROM, a USB flash memory, or a portable USB hard disk. The steps for creating each will be described later in this article.
Creating the Windows PE ISO image - 64 bit
A 64 bit WinPE environment is required when working with the installation of 64 bit operating systems. (Once a wim image is created, deployment to a 64 bit system works fine using 32 bit WinPE)
The following paragraphs repeat much of the content from the 32 bit PE ISO image creation section, but are included here for completeness.
The Windows Automated Installation Kit (WAIK) first needs to be downloaded. The version used in this example was 6001.18000.080118-1840-kb3aikl_en.iso
This iso can be burned to a DVD or mounted on the test workstation using a virtual CD/DVD emulator such as Daemon Tools.
Once this has been done, install the WAIK on your test workstation. This will install some help files accessible through the Start Menu, and the Windows PE Users Guide is helpful as a reference when creating your customised WinPE iso image.
The following steps are recommended:
- Start the Windows PE Tools command prompt from the Start Menu.
- At the command prompt type: copype.cmd amd64 c:\winpe_x64 The cmd script creates c:\winpe_x64 folder and two subfolders: ISO and mount, and copies over all required files for the specified architecture (x64 in this example).
- The next step mounts the base image to a folder on your test machine so that it can be edited to add or remove packages. At the command prompt type:
imagex /mountrw c:\winpe_x64\winpe.wim 1 c:\winpe_x64\mount
You should receive a completion message:
"Successfully mounted image (RW)"
- By using the Peimg tool, you install Windows features by using the /install option. Windows features are included with the base image (Winpe.wim) but are not installed. You can also import packages and add drivers and language packs. For more information, see Windows PE Customization How-To Topics. The following four options are included as examples:
peimg /install=WinPE-HTA-Package c:\winpe_x64\mount\Windows
peimg /install=WinPE-Scripting-Package c:\winpe_x64\mount\Windows
peimg /install=WinPE-WMI-Package c:\winpe_x64\mount\Windows
peimg /install=WinPE-XML-Package c:\winpe_x64\mount\Windows
Installing these in turn at the Windows PE Tools command prompt will ensure that they are added to the mounted winpe.wim file.
- Verify that the packages were installed by using the peimg /list command to view all packages in the current image. For example,
peimg /list c:\winpe_x64\mount\Windows
In the INS column, (+) denotes installed packages and (-) denotes not installed.
- At this point you can add any additional software you may wish to have on your PE image. Typical additions could include utility files such as Ghost32.exe and Bootsect.exe. If you want the files to be part of the booted image (which loads to the X: drive) then add them to the C:\winpe_X64\mount folder - but bear in mind that this will increase the amount of system RAM required to load the PE image. Alternatively, add the files to the ISO folder where they will be available from the boot media once PE is loaded into RAM.
Note: This version of WinPE displays a monochrome background when booting. If a colour background (Vista colours) is preferred, replace the winpe.bmp file in the C:\winpe_X86\mount\Windows\System32 folder with a version from an older release of WinPE, that has a size of 3Mb instead of 2Mb.
Adding imagex.exe from the installed WinPE toolset to the system32 folder is also a good idea.
- Next, you prepare the image by using the peimg /prep command. This operation removes any non-installed packages from the final image and reduces the overall image size. For example,
peimg /prep c:\winpe_x64\mount\Windows
The /prep option cannot be reverted, and after the /prep option is run, the /install, /uninstall, /import, and /list options will not function, while the /lang and /inf options will continue to function. The Peimg tool prompts you to confirm the command. To suppress this prompt for scripting, add the /f option. The prompt requires 'yes' to be entered - any other input, eg 'y' will exit the command.
- Next, you commit the changes to the original image file (Winpe.wim) by using the ImageX /unmount option with the /commit option. For example,
imagex /unmount c:\winpe_x64\mount /commit
- Having created a new winpe.wim file in the C:\winpe_X86 folder, you must now replace the default Boot.wim in the \ISO directory with your new customized image. The image must be called Boot.wim. For example,
copy c:\winpe_x64\winpe.wim c:\winpe_x64\ISO\sources\boot.wim
You now have a customized Windows PE RAM disk image that you can place on bootable media, like a CD-ROM, a USB flash memory, or a portable USB hard disk. The steps for creating each will be described in the following paragraphs.
Adding Device Drivers to an Offline Windows PE Image
Windows PE contains native support for many different types of hardware, but with the passage of time it is inevitable that new chipsets will emerge, for which there is no native driver support. Typical of this are new hard disk array chipsets.
In order for WinPE to be able to access these drive arrays, the required drivers will need to be added to the WinPE.wim file. This can be achieved by implementing the following steps:
- Mount the WinPE.wim file:
imagex /mountrw WinPE.wim 1 c:\winpe_x86\mount\
- Add the driver .inf file to the base image:
peimg /inf=<path to inf file> C:\winpe_x86\mount\Windows
Repeat the above step for each additional driver.
- Unmount the WinPE.wim file:
imagex /unmount /commit c:\winpe_x86\mount\
Notes:
- Imagex.exe is normally located in the folder: C:\Program Files\windows aik\tools\x86
- If both 32 bit and 64 bit WinPE boot wims exist, then it may be necessary to add the drivers to each of these wims, depending on the application. Ensure that the correct 32 bit or 64 bit drivers are used when customising your wim files.
- The wim file mount point is shown as c:\winpe_x86\mount\ in the examples above. This 'default' mount point can be set to any empty folder.
Creating a bootable CDROM (32 bit)
At the Windows PE Tools command prompt, type:
oscdimg -n -bc:\winpe_x86\etfsboot.com c:\winpe_x86\ISO c:\winpe_x86\winpe_x86.iso
This will create a file called WinPE_X86.iso in the C:\WinPE_X86 folder. This file can now be burned to a CDROM using any CD writer software such as Nero, or a freeware utility such as IsoRecorder from: http://isorecorder.alexfeinman.com/isorecorder.htm
Creating a bootable CDROM (64 bit)
At the Windows PE Tools command prompt, type:
oscdimg -n -bc:\winpe_x64\etfsboot.com c:\winpe_x64\ISO c:\winpe_x64\winpe_x64.iso
This will create a file called WinPE_X64.iso in the C:\WinPE_X64 folder. This file can now be burned to a CDROM using any CD writer software such as Nero, or a freeware utility such as IsoRecorder from: http://isorecorder.alexfeinman.com/isorecorder.htm
Creating a bootable USB device
32 bit boot
The following procedure applies, with minor differences, to both USB flash memory devices, and USB hard disks. Some command can be abbreviated and where this is possible, the abbreviations are shown in brackets.
- Boot your test machine where the WinPE iso image was created, using the Win PE CDROM created as detailed above. Wait until wpeinit has completed and you have a command prompt of: X:\Windows\System32>
- Type: DISKPART
- Type: LIST DISK (lis dis) and identify the disk number for your USB device. It will typically be Disk 1, so we will continue on that basis
- Type: select disk 1 (sel dis 1)
- Type: clean
- Type: create partition primary (create part pri). If no size is specified, the full device capacity will be used. Otherwise, append: size=(size in Kb)
- Type: select partition 1 (sel part 1)
- Type: active
- For USB hard disks type: format fs=ntfs LABEL="BOOT" QUICK. For USB flash memory devices type: format fs=fat32 LABEL="BOOT" QUICK
- Type: assign
- Type: exit
At this point the USB device is ready to receive the Windows PE bootable file image. Verify the drive letter of the USB device, typically F:
At the WinPE command prompt, type:
Xcopy c:\winpe_x86\iso\*.* /s /e /f f:\
(f: is the drive letter which directly references the USB device and should be amended if your USB device mounts on a different drive letter.)
The USB device is now ready to be tested.
Type EXIT at the WinPE command prompt and wait for the system bios message to appear on the test workstation as it reboots. Press the appropriate function key to allow selection of the boot device, and when the boot list is displayed, select the USB device and boot from it. If all went well, the standard WinPE boot should commence. Wait until the X:\Windows\System32> prompt is displayed, and then type EXIT to reboot your system, as the boot test is now complete.
64 bit boot
The procedure is identical to that for the 32 bit boot device, (steps 1 to 11) but the Xcopy command is different, and is shown below:
At the WinPE command prompt, type:
Xcopy c:\winpe_x64\iso\*.* /s /e /f f:\
The USB device is now ready to be tested.
Creating a dual boot XP/WinPE workstation
The following steps outline a method for creating a dual boot workstation which can boot both XP and Windows PE based on a boot menu presented during startup. A default timeout is set, so that the workstation boots to XP by default after a predetermined number of seconds.
The starting point is the USB bootable WinPE device created earlier. Plug this into a workstation running XP and perform the following operations:
- Create a folder named "DualBoot" on your USB device
- Copy the BOOTMGR file from the root of the USB device to the DualBoot folder
- Copy the BOOTSECT.EXE file from the root of the USB device to the DualBoot folder
- Copy the BOOT.SDI file from the \boot folder of the USB device to the DualBoot folder.
- Copy the BOOT.WIM file from the \sources folder of the USB device to the DualBoot folder
- Paste the following code into a file called bcd.vbs and save to the DualBoot folder
Dim WshShell, FSO
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
WSHShell.run "bcdedit /createstore", 0, TRUE
WSHShell.run "bcdedit /create {ramdiskoptions} /d ""Boot Windows PE""", 0, TRUE
WSHShell.run "bcdedit /set {ramdiskoptions} ramdisksdidevice partition=c:", 0, TRUE
WSHShell.run "bcdedit /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi", 0, TRUE
Set getGUID = WshShell.Exec("bcdedit /create /d ""Windows PE"" /application OSLOADER")
Do While getGUID.Status = 0
WScript.Sleep 100
Loop
'Fun little set of code to grep out the GUID
strGUID = getGUID.StdOut.ReadAll
arr1GUID = Split(strGUID, "{")
arr2GUID = Split(arr1GUID(1), "}")
strGUID = "{"&arr2GUID(0)&"}"
WSHShell.run "bcdedit /set "&strGUID&" device ramdisk=[c:]\boot\boot.wim,{ramdiskoptions}", 0, TRUE
WSHShell.run "bcdedit /set "&strGUID&" path \windows\system32\boot\winload.exe", 0, TRUE
WSHShell.run "bcdedit /set "&strGUID&" osdevice ramdisk=[c:]\boot\boot.wim,{ramdiskoptions}", 0, TRUE
WSHShell.run "bcdedit /set "&strGUID&" systemroot \windows", 0, TRUE
WSHShell.run "bcdedit /set "&strGUID&" winpe yes", 0, TRUE
WSHShell.run "bcdedit /set "&strGUID&" detecthal yes", 0, TRUE
WSHShell.run "Bcdedit /create {bootmgr} /d ""Boot Manager""", 0, TRUE
WSHShell.run "Bcdedit /set {bootmgr} device boot", 0, TRUE
'Create the entry to boot Windows XP (or whatever OS's you have booting via boot.ini
WSHShell.run "bcdedit /create {ntldr} /d ""Windows XP""", 0, TRUE
WSHShell.run "bcdedit /set {ntldr} device partition=C:", 0, TRUE
WSHShell.run "bcdedit /set {ntldr} path \ntldr", 0, TRUE
WSHShell.run "bcdedit /displayorder {ntldr} /addfirst", 0, TRUE
WSHShell.run "bcdedit /displayorder "&strGUID&" /addlast", 0, TRUE
'The following line sets the boot menu timeout
WSHShell.run "bcdedit /timeout 5", 0, TRUE
Msgbox "Your system is now set up to boot Windows PE 2.0 as well as your previous operating systems."
- Unmount the USB device and connect to the workstation that you wish to convert to Dual Boot.
- Boot the target workstation to WinPE from the USB device
- Create a folder on the C:\ drive of the XP workstation called C:\BOOT
- Identify the drive letter of your USB device, eg E: and type the following:
copy E:\DualBoot\*.* C:\BOOT
- Remove the USB device.
- Change to the C:\BOOT folder and type: BOOTSECT.EXE /NT60 ALL /force
(note that there is no / for the ALL command) This changes the boot sector format to Vista compatible to allow the boot manager to operate correctly.
- Reinstall the USB device and type EXIT to reboot the system. This is a required step as the previous command has unmounted the volumes.
- Boot WinPE from the USB device once more
- Change to the C:\BOOT folder.
- Type MOVE BOOTMGR C:\ -you should receive a "one file moved" response
- Type bcd.vbs and wait for the messagebox stating "Your system is now set up to boot Windows PE 2.0 as well as your previous operating systems."
- Remove the USB device and type EXIT. The system should reboot and display the boot manager menu for 5 seconds before automatically booting XP.
Should you wish to amend the timeout period for the boot menu, this can be accomplished by booting WinPE, and then typing at the command prompt:
bcdedit /timeout x - where x is the number of seconds you wish the boot menu displayed for.
The bcd.vbs file is no longer required in the C:\BOOT folder, and can be deleted.
Undoing the Dual Boot
Undoing the dual boot is even easier than putting it in place.
- Boot to WinPE
- Change to C:\BOOT folder
- Type BOOTSECT.EXE /NT52 ALL /force (note that there is no / for the ALL command)
- Type EXIT
- When system boots to XP, delete BOOTMGR from the root of C: and delete the BOOT folder.
Your system is now back to single boot operation.