This is going to be a somewhat unfamiliar post on my blog. The history for it goes back to 2003-2004 when I was involved in a local Microsoft Belux project called "SchoolServer". At that time, we used a Windows PE (where PE stands for "Pre-Installation Environment" and not "Portable Executable") version extracted from the Windows Server 2003 branch (NT 5.2), which was available to volume licensing customers only. But what's Windows PE?
Windows PE is a version of the Windows OS that runs without installation entirely in memory (no harddisk required) and boots from a cd-rom or the network (as we'll see it goes further than that in v2.0).
The reason to use it is pretty straightforward: for "Pre-Installation" tasks, such as disk partitioning, or even to build a (scripted) system setup that runs in a familiar Windows environment right from the start (e.g. generating a winnt.sif unattended installation file using a nice graphical wizard, making the right partitions, copying setup sources to the harddrive and invoking setup using winnt.exe or so). But also for day-to-day computer (disk) administration tasks, this proves very useful. Indeed, Microsoft's Windows PE solution isn't the only one out there but are others as well which have similar ideas like BartPE (I'm not that Bart).
If you've installed Windows Vista or Windows Server 2008 already (I hope you did), you'll have noticed that there's no blue-background textual setup anymore, the system boots into Windows from the cd to have an end-to-end graphical setup which is based on the Windows PE technology. As a developer I loved to have such a Windows PE version myself bootable from USB Flash and for free. In this post I explain how I did it from A to Z. I'll also explain how to create an ISO image for Windows PE cd's.
Getting started: download and install the WAIK
WAIK stands for the Windows Automated Installation Kit and is available as a download. It's a big download, but it's worth to put your connection under stress for :-). Burn it to a cd or mount it using some ISO/IMG mounting tool and install it.
The Windows PE Tools Command Prompt
Next, open up the Windows PE Tools Command Prompt from the Start Menu and make sure to Run as Administrator:
Alternatively, you can change the shortcut's properties, Advanced..., Run as Administrator to run it everytime elevated as an administrator:
You should see something like this:
Notice the message points you at a few usable executables: peimg, oscdimg and imagex. We're going to use these in a minute.
Building your Windows PE
In order to build your custom Windows PE, follow the next steps:
- Run copype.cmd as follows:
> copype.cmd x86 c:\winpe_x86
This makes a copy of the Windows PE files to the specified folder. Alternatively, you can specify amd64 for 64-bit machines. We'll manipulate this folder in the next steps.
- Next, you can customize the Windows PE image (using the Windows Imaging Format, aka WIM) using ImageX:
You can mount a WIM file to a folder like this:
> mkdir c:\winpe_x86\mount
> imagex /mountrw c:\winpe_x86\winpe.wim 1 c:\winpe_x86\mount
For the curious, this works through a file system driver called WimFltr (see sc queryex WimFltr).
- Add all apps you like to add to the image in the mounted folder. Windows PE is based on packages that can be added to the image at will. This is done through peimg, like this:
> peimg /list /image=c:\winpe_x86\mount\Windows
to show a list of all images:
Next, you can add packages by calling:
> peimg /install=<package> c:\winpe_x86\mount\Windows
where package is either * (all packages) or one from the list shown by invoking peimg with the /list switch.
- You could add drivers and language packs as well, but for that I refer kindly to the excellent help documentation that comes with the WAIK. When you're done with the image customization, run peimg with the prep switch:
> peimg /prep c:\winpe_x86\mount\Windows
and unmount the image using ImageX:
> imagex /unmount c:\winpe_x86\mount /commit
and copy the created .wim file to the ISO folder:
> copy c:\winpe_x86\winpe.wim c:\winpe_x86\ISO\sources\boot.wim
- Next you can create an ISO file for the image using oscdimg:
> oscdimg -n -bc:\winpe_x86\etfsboot.com c:\winpe_x86\ISO c:\winpe_x86\winpe_x86.iso
where the -b flag specifies the El Torito boot sector for the ISO to be created. It just takes a few seconds to complete:
- To test your image, just create a new Virtual PC virtual machine (e.g. with 256 MB of RAM) and mount the ISO file. No harddisk or network adapters needed:
VPC should boot like this:
Feel free to start taskmgr and notepad or so to get familiar with your next big friend :-). Finally shut it down using wpeutil shutdown.
- You might have noticed the image has the QWERTY keyboard layout, but you can change that if you like to do so. Go back to step 2 to mount and do the following on the mounted image using intlcfg:
> intlcfg -inputlocale:<locale> -image:c:\winpe_x86\mount
> intlcfg -syslocale:<locale> -image:c:\winpe_x86\mount
> intlcfg -userlocale:<locale> -image:c:\winpe_x86\mount
where <locale> is replaced by the locale you want (e.g. nl-be for Belgian Period keyboard).
Go back to step 4 to unmount, commit, prep and create the iso. Rerun VPC to test.
For the curious, this changes some of the <mount>\Windows\System32\config\*.* registry hives:
In regedit.exe you can mount these hives to see what's in. To do this, open regedit, select HKLM and choose File, Load Hive. Next select the file to load (e.g. DEFAULT) and specify a name for the loaded hive (e.g. Mount):
As you can see, intlcfg has changed the Keyboard Layout\Preload list. Of course, the hardcore ones of you might prefer to make changes to the registry hive directly this way. By the way, while you're in the loaded hive, check out other settings like:
- desktop wallpaper via Control Panel\Desktop\WallPaper
- (from the SYSTEM hive) command line to invoke after starting Windows PE via Setup\Cmdline
Tip: regedit.exe is also available in Windows PE itself, so you can check the outcome over there. However, changes mage while running Windows PE won't take effect since the registry is loaded in memory.
- Finally, it's time to put the whole thing on a USB Flash key or to burn the ISO created in step 5 to a cd-rom. I'll cover the former option. Open up diskpart and execute the following commands:
WARNING! Make sure to select the right disk in step 1; you can view all disks using the "list disk" command. In the steps below, all data from the USB Flash disk will be removed!
> select disk 1
> create partition primary
> select partition 1
> format fs=fat32
Now copy to the c:\winpe_x86\ISO folder contents to the USB disk (which I assume has letter E: assigned):
> xcopy c:\winpe_x86\ISO\*.* E: /E
- Now you should be able to boot from the USB Flash disk. Make sure to select the right boot device during the boot cycle or to change the boot order in your computer's BIOS.
| Digg It