Microsoft Windows Registry Guide, Second Edition
Using Windows PE as an Installation Platform
You probably used MS-DOS-bootable disks to handle system configuration, prepare computers for installation, and then install the operating system on the computer. MS-DOS-bootable disks are difficult to configure and maintain for this purpose because you must first track down the 16-bit device drivers required and then customize the disks to connect to the network. Each type of network adapter requires a unique disk, too, escalating the amount of work involved in maintaining these MS-DOS-bootable disks. Add to that the computer systems with atypical mass-storage devices that require you to customize disks with mass-storage device drivers, and the number of combinations that you must maintain grows quickly. Even after all the time you spend building and maintaining MS-DOS-bootable disks, they are barely adequate to get the job done because MS-DOS provides minimal scripting capabilities and memory resources'and the utilities it provides are the bare essentials. For example, after you start computers with an MS-DOS-bootable disk, you must usually perform many tasks manually before starting the Windows installation instead of moving on to the next computer to install Windows. After formatting a hard disk, you must usually restart the computer before installing Windows.
Microsoft developed Windows PE specifically for deployment scenarios. Windows PE provides a lightweight, 32-bit environment that leverages the same device drivers as Windows. You have access to a similar set of basic features that Windows provides, including the NTFS file system and DFS shares. Windows PE supports long file names, too. In addition, you can fully automate the installation process, so you can move on to the next computer or the next disk image faster. In deployment scenarios, there are a variety of ways you can use Windows PE, including the following examples:
You can use the Windows PE bootable CD as-is'that is, without customizations'to start computers. (You must still build a Windows PE CD from Windows XP or Windows Server 2003 source files, however.) Then you can connect to the network and install an operating system from a customized network share. Without customizations, the Windows PE bootable CD doesn't support WSH, HTA, or ADO.
You can customize Windows PE in a variety of ways'such as adding device drivers, optional components, and other utilities'and then create a new Windows PE CD. You use the Windows PE CD to connect to the network and install an operating system from a customized network share. In this scenario, the user or technician starts the computer using the CD. Windows PE starts and then processes Startnet.cmd, which starts the networking connection. You can also customize this batch script to map a drive letter to the network share that contains the Windows source files, verifies that the computer's configuration matches the require configuration, backs up the user's data to the network, runs Diskpart to partition the hard disk, formats the hard disk with the NTFS file system, and then runs Windows Setup fully unattended. Alternatively, the script can run a third-party disk-imaging utility to restore an operating-system image from the network share to the hard disk. (See Chapter 15, “Cloning Disks with Sysprep,” for a list of disk-imaging products that support Windows PE.)
You can create a Windows PE CD that contains both Windows PE and the operating system that you're installing and then customize the CD so that it automatically installs the operating system when the CD starts. Because more powerful scripting capabilities are available with Windows PE than with MS-DOS, you're more able to completely automate the process. You can then distribute the CD to users or technicians so that they can automatically install the operating system. This scenario is much like the previous one, except that the CD contains the Windows source files, so a network connection isn't necessary.
In an Active Directory environment, you can customize and install Windows PE using RIS. Rather than starting computers with a CD, you can start Windows PE remotely by using RIS. This scenario is similar to using a Windows PE CD to start the computer and connect to the network, except that the user or technician starts the computer from the Windows PE image on the RIS server. Then the custom scripts you add to Windows PE connect to the network, verify the computer's configuration, prepare the disk for installation, and then start Windows Setup. No floppy disks or CDs are required.
The following sections describe how Windows PE and your customizations enable these scenarios. They start with the basics, starting the computer. Then they describe how to verify that the computer's configuration meets requirements, how to configure the computer's hard disk, and how to install Windows.
Starting the Computer
To start the computer using a Windows PE CD, insert the CD into the computer's CD-ROM, configure the computer's BIOS to boot from the CD before booting from the local hard disk (only if necessary), and then restart the computer. When prompted, press any key to boot the computer from the CD. Windows PE loads and then runs the all-important Startnet.cmd batch script to configure the environment. (Startnet.cmd serves a similar purpose to Autoexec.bat in MS-DOS.) Windows PE runs Startnet.cmd every time it starts, making this file the central location from which to customize Windows PE for your scenarios.
There are two versions of Startnet.cmd that you might encounter, depending on when and from where you received Windows PE. The first version contains the line factory –winpe. This version relies entirely on Factory to configure the network connection. The second version contains the line factory –minint followed by several other lines that configure the network connection. The first version is the default in newer versions of Windows PE, beginning with version 1.2. The second version is the default in older versions. I prefer the first version because it's much cleaner. You should use it, too. Listing 16-1 shows a slightly customized version of Startnet.cmd, and the following steps describe how it works:
- if exist oc.bat call oc.bat.
This command installs optional components only if they exist. See the section “Optional Components,” later in this chapter.
- factory -winpe.
This command detects, installs, and configures network support for Windows PE. It first looks for the Winbom.ini file, as described in the sidebar “Finding Winbom.ini,” later in this chapter. When Factory finds a Winbom.ini, it looks in the file's [Factory] section for the WinbomType entry and checks that it is WinPE. If not, it continues looking for another Winbom.ini file. After locating the Winbom.ini file, Factory configures the network connection as specified in the [WinPE.Net] section. Factory uses Plug and Play to install the network interface card and then configures the networking services and binds the network protocols.
- if exist a:\floppy.cmd a:\floppy.cmd.
This command runs the batch script called Floppy.cmd located on drive A, only if it exists. It provides an easy way to further customize Windows PE for different scenarios without requiring a separate copy of Windows PE for each. Instead, simply create a separate floppy for each scenario.
Listing 16-1 Startnet.cmd
@echo off @rem startnet.cmd: configure Windows PE networking, etc. echo Installing optional components... if exist oc.bat call oc.bat echo Configuring network components... factory -winpe cls if exist a:\floppy.cmd a:\floppy.cmd :end
More Info
Using Windows PE, you can accomplish many tasks by using three methods: answer files, batch scripts, or Winbom.ini. Winbom.ini is a simple configuration settings file that Windows PE uses when the command factory 'winpe runs in Startnet.cmd. Using Winbom.ini to partition and format disks is often easier than using Diskpart, for example. Winbom.ini also gives you a moderate amount of control over how Windows PE starts.
NOTE
“Windows Preinstallation Environment User's Guide,” which is Winpe.chm in the Docs folder on the Windows PE CD, contains a complete reference for the Factory command and for Winbom.ini. I typically use batch scripts because they give me more control of the installation process than Winbom.ini does.
Finding Winbom.ini
When you run the command factory –winpe in Startnet.cmd, Factory searches for Winbom.ini in the following order:
The path and file name specified by the registry key HKLM\SOFTWARE\Microsoft\Factory\Winbom
The root of all removable media drives that are not CD-ROM drives, such as a floppy disk drive
The root of all CD-ROM drives
The location of Factory.exe, usually the %SystemRoot%\System32 or %SystemRoot%\Sysprep folders
The root of %SystemDrive%
Configuring the Hard Disks
There are two ways to configure the target computer's hard disk using native Windows PE tools. The first is using Diskpart to partition the disk and using Format to format it. This method provides the greatest amount of flexibility for scenarios in which you want to support various computer configurations from a single Windows PE CD or RIS image.
The second method is using the [DiskConfig] section in Winbom.ini. Using this section, you describe the disk layout using settings such as SizeNN, PartitionTypeNN, and FileSystemNN.
More Info
Winbom.ini is predominately an Original Equipment Manufacturer (OEM) tool, and I prefer the flexibility of using batch scripts and Diskpart, so I'll refer you to “Windows Preinstallation Environment User's Guide,” which is Winpe.chm on the Windows PE CD in the Docs folder, for more information about using Winbom.ini to configure hard disks.
Listings 16-2 and 16-3 show how to use the first method. Listing 16-2 is Diskpart.txt (similar to an answer file). This file is a script for Diskpart.exe that automatically configures the disk. It selects the first disk installed on the computer, removes its current partitions, creates a new primary partition using all the available space, assigns the drive letter C, and then marks the partition as active so that it will boot.
Listing 16-3 shows the command necessary to run Diskpart.exe with Diskpart.txt as the script and then format the disk. The batch script setup32.cmd contains these commands. The command to use diskpart.txt in Windows PE is diskpart.exe/s diskpart.txt. Diskpart does not format the disk, so you must format the disk after partitioning it. The command format c: /q /fs:ntfs/y quickly formats the newly partitioned disk with the NTFS file system and without a volume label. The command-line option /y runs Format without prompting for input. You can run both commands within a batch script to automatically partition and format a disk, which is what you see happening in setup32.cmd in the next section, Listing 16-3.
Listing 16-2 diskpart.txt
select disk=0 clean create partition primary assign letter=c active
Listing 16-3 setup32.cmd
diskpart /s diskpart.txt format c: /q /fs:ntfs /y
Installing Windows
After configuring the computer's hard disk and performing any other preinstallation tasks you've planned, you run Winnt32 (not Winnt) to start Windows Setup. Listing 16-4 shows setup32.cmd, updated with the commands to run Winnt32 from Windows PE and restart the computer.
The important takeaway from Listing 16-4 is the command-line option /syspart:c:. If you partition the disk using Diskpart and then format it using Format, Windows Setup fails without using the /syspart command-line option. This option changes Windows Setup so that it simply copies the source files to the target computer and then prepares the disk so that Windows Setup continues after the computer restarts.
So how do you restart the computer in Windows PE from a batch script? I'm embarrassed to say that it took a few tries for me to figure this out. I first tried the Shutdown utility. Then I tried some third-party utilities. None of them worked. I tried a script. That didn't work. Then, out of frustration, I typed exit at the command prompt and, low and behold, Windows PE restarted the computer. So, that's the trick and that's why you see the line exit in the listing.
Listing 16-4 setup32.cmd
diskpart /s diskpart.txt format c: /q /fs:ntfs /y @..\i386\winnt32 /unattended:winnt.sif /syspart:c: exit