Ghost Solution Suite

 View Only

Adventures with WinPE 

Aug 07, 2009 12:52 PM

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:

  1. Start the Windows PE Tools command prompt from the Start Menu.
  2. 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).
  3. 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)"
  4. 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.
  5. 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.
  6. 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.

  7. 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.
  8. 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
  9. 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:

  1. Start the Windows PE Tools command prompt from the Start Menu.
  2. 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).
  3. 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)"
  4. 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.
  5. 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.
  6. 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.

  7. 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.
  8. 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
  9. 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:

  1. Mount the WinPE.wim file:
    imagex /mountrw WinPE.wim 1 c:\winpe_x86\mount\
  2. 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.
  3. 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.

  1. 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>
  2. Type: DISKPART
  3. 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
  4. Type: select disk 1 (sel dis 1)
  5. Type: clean
  6. 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)
  7. Type: select partition 1 (sel part 1)
  8. Type: active
  9. For USB hard disks type: format fs=ntfs LABEL="BOOT" QUICK. For USB flash memory devices type: format fs=fat32 LABEL="BOOT" QUICK
  10. Type: assign
  11. 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:

  1. Create a folder named "DualBoot" on your USB device
  2. Copy the BOOTMGR file from the root of the USB device to the DualBoot folder
  3. Copy the BOOTSECT.EXE file from the root of the USB device to the DualBoot folder
  4. Copy the BOOT.SDI file from the \boot folder of the USB device to the DualBoot folder.
  5. Copy the BOOT.WIM file from the \sources folder of the USB device to the DualBoot folder
  6. 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."
    
  7. Unmount the USB device and connect to the workstation that you wish to convert to Dual Boot.
  8. Boot the target workstation to WinPE from the USB device
  9. Create a folder on the C:\ drive of the XP workstation called C:\BOOT
  10. Identify the drive letter of your USB device, eg E: and type the following:
    copy E:\DualBoot\*.* C:\BOOT
  11. Remove the USB device.
  12. 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.
  13. Reinstall the USB device and type EXIT to reboot the system. This is a required step as the previous command has unmounted the volumes.
  14. Boot WinPE from the USB device once more
  15. Change to the C:\BOOT folder.
  16. Type MOVE BOOTMGR C:\ -you should receive a "one file moved" response
  17. 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."
  18. 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.

  1. Boot to WinPE
  2. Change to C:\BOOT folder
  3. Type BOOTSECT.EXE /NT52 ALL /force (note that there is no / for the ALL command)
  4. Type EXIT
  5. 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.

Statistics
0 Favorited
5 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Feb 22, 2012 05:05 AM

I have created an article describing how to build a WinPE V3.1 boot environment. It can be found at:

https://www-secure.symantec.com/connect/articles/adventures-winpe-31?om_ext_cid=biz_con_cmgr_cp_20120221_pm

Sep 20, 2011 11:18 AM

The payload associated with making the system dual boot is not huge - probably less than 200Mb, so I would suggest that there is not much to be saved in moving the boot.wim to another volume.

Once WinPE is loaded, it runs entirely from memory, so I would expect Ghost to be able to image the entire C: drive including the boot.wim without running into any problems - but this is not something I have tried.

What you may wish to consider is making an external USB device such as a key or hard disk into a WinPE bootable device, or even a CDROM, and put Ghost on there. Then you can add command scripts to a menu and use it to create backup images where ever you like and restore images from where ever you like. Since WinPE supports HTA files, you can write quite a nice graphical front end to do this for you. In addition, as WinPE also supports WMI (assuming the necessary support is loaded), you can use this to detect the hardware that is being booted and automatically choose the right image if you want to spend a bit of time coding this.

Sep 20, 2011 11:05 AM

I'm trying to get the boot.wim to reside on another partition besides C: if possible  For example C: for OS only and another partition where the boot.wim and ghost image can reside.  In your example where would a ghost backup image reside?  Also I assume after completing your guide an image would have to be created of the C: partition that would be used to restore. I will play around with BCDEDIT to see what I did wrong.  Thank you!

Sep 20, 2011 04:29 AM

This article was specifically written for WinPE V2, as the V3 version you are referring to has substantial differences which make this article inapplicable. DISM is just one of those differences.

I do have the basic code for a new article but have not had the time to write it yet.

Sep 20, 2011 04:27 AM

What exactly are you trying to do? I developed the BCD.VBS file on a dual partition XP system and there was no real need to mess with any settings for the second partition to get the dual boot implemented.

So please give more information on what you are trying to do.  Also, there is a freeware tool called BCDEDIT which you can use to inspect the BCD configuration on any machine, which may help you determine what settings may not be quite right in your environment.

Sep 19, 2011 06:05 PM

By any chance can you provide an example of a working bcd.vbs file that uses two partitions.  Being new to BCD commands I'm having a slight problem on getting it to work.  I have two partitions 1. C: OS/Data  2. D: Image to restore.

Thanks

Sep 14, 2011 05:24 AM

Thank you  for wonderful link

Jun 28, 2011 02:01 PM

  Hi EdT,
 
I've installed WAIK, and then updated it with the WAIK Supplement for Win7 SP1 (WinPE v3.1).
Tried to follow your guide, but as other users noted, PEimg.exe is missing.
 
After a quick search, I found that DISM should be used instead.
 
Please update this guide as soon as you can.
 
Here's a link to a good explanation on how to use DISM:
http://sysengineers.wordpress.com/2010/11/08/peimg-exe-missing-here-is-how-to-fix-it/

 

Mar 28, 2011 12:11 PM

No guide at this time, but it should be quite straightforward using two partitions, putting the WinPE stuff on the second partition and updating the bcd.vbs accordingly.

Mar 24, 2011 04:00 PM

Great job on this guide. I was wondering wherer you have a guide on how to do the same thing on 2 different partitions (one Windows XP and one WinPE)?

Jul 14, 2010 11:10 PM

Thanks a lot...This is really a great piece of work...

Jun 29, 2010 09:33 AM

That was Amazing!.. I was looking for something like this...

May 10, 2010 01:47 PM

Thank you for providing this; this is an excellent article!

May 07, 2010 02:48 PM

WinPE V3, which ships with Windows 7, has had some significant changes made to the way it works, and so I will have to sit down when I have a spare moment and update this guide.

Jan 27, 2010 05:32 PM

Just installed latest release of WAIK on Windows 7 pro 64 bit.

I run the Administrator Deployment tools command prompt, but I'm not finding peimg.

I'm searching my system but am not finding it.


C:\Program Files\Windows AIK\Tools\PETools>peimg
'peimg' is not recognized as an internal or external command,
operable program or batch file.


C:\Program Files\Windows AIK\Tools\PETools>dir
 Volume in drive C is SYSTEM
 Volume Serial Number is 66E7-A7D4

 Directory of C:\Program Files\Windows AIK\Tools\PETools

01/27/2010  11:55 AM    <DIR>          .
01/27/2010  11:55 AM    <DIR>          ..
01/27/2010  11:56 AM    <DIR>          amd64
06/10/2009  02:44 PM             2,084 copype.cmd
01/27/2010  11:56 AM    <DIR>          ia64
06/10/2009  02:44 PM               806 pesetenv.cmd
06/10/2009  02:44 PM             3,485 setsanpolicy.cmd
07/14/2009  07:10 AM           116,096 ssshim.dll
01/27/2010  11:55 AM    <DIR>          x86
               4 File(s)        122,471 bytes
               5 Dir(s)  23,632,867,328 bytes free



My windows system Image Manager is saying version (6.1.7600.16385)

does this guide still apply?


Thanks.
 

Aug 10, 2009 10:04 PM

Excellent article. Very thorough too.

i will be trying this soon.

Kevin

Related Entries and Links

No Related Resource entered.