Jump to content

Working with Windows Recover Environment

0
  adfm's Photo
Posted Mar 22 2010 08:50 AM

Do you need to build a custom Windows Recover Environment disk? In this excerpt from William R. Stanek's Windows® 7 Administrator's Pocket Consultant you'll learn what it takes to build a recovery disk image that you can install on a CD-R, DVD-r, or thumbdrive.


Windows Recovery Environment (RE) is a Windows Preinstallation Environment (PE) image with recovery extensions installed. After you create a customized Windows RE image, you can deploy the image by creating bootable media that uses the image or by importing the image into Windows Deployment Services.

To enable rapid recovery, Windows RE is installed with Windows 7 automatically. If you've added a custom Windows RE to the installation image, your custom environment is available to users. Normally, you configure Windows RE on a hard disk partition other than the one containing the Windows installation. This ensures that Windows RE is separate from the operating system.

Creating a Customized Windows RE Image

In Windows 7, users can initiate image-based recovery without having to first start Windows RE manually. The Recovery control panel allows users to back up their personal data and then restarts the system into Windows RE, where the image recovery application is launched automatically.

You can create a custom Windows RE image by completing the following steps:

  1. Click Start, point to All Programs, and then click either Microsoft Windows OPK, Microsoft Windows AIK, or Microsoft Windows PE Kit as appropriate.

  2. Right-click Deployment Tools Command Prompt, and then click Run As Administrator.

  3. Make directories for mounting the image. At the command prompt, do the following:

    1. Enter c:, and then enter mkdir c:\win7.

    2. Enter cd win7, and then enter mkdir mount. You will use this directory to mount the Windows 7 image.

    3. Enter mkdir mountre. You will use this directory to mount the Windows Recovery Environment.

  4. Insert the Windows 7 distribution media into the DVD-ROM drive, and then copy the Windows install image from the distribution media to your hard disk by entering copy e:\sources\install.wim c:\win7, where e: is the drive designator for the DVD-ROM drive.

  5. Mount the Windows 7 image on the distribution media by entering imagex /mountrw e:\sources\install.wim c:\win7\mount.

  6. Copy the original Windows RE image from the mounted image by entering copy c:\sources\mount\windows\system32\recovery\winre.wim c:\win7.

  7. Unmount the Windows 7 image by entering imagex /unmount c:\win7\mount.

  8. Mount the Windows RE image by entering imagex /mountrw c:\win7\winre.wim c:\win7\mountre.

  9. Customize the Windows RE image as necessary by using the techniques discussed in the section the section called “Customizing a Windows PE Image”. Be sure to add the following package to the image: WinPE-SRT-Package. This package is required.

  10. Unmount the customized Windows RE image, and then save your changes by entering imagex /unmount /commit c:\win7\mountre.

  11. Mount the Windows 7 image you copied previously to the C:\Win7 directory by entering imagex /mountrw c:\win7\install.wim c:\win7\mount.

  12. Overwrite the original Windows RE image in the Windows 7 image with your customized Windows RE image by entering copy c:\win7\winre.wim c:\win7\mount\Windows\System32\recovery.

  13. Save the changes to the Windows 7 image by entering imagex /unmount c:\win7\mount /commit.

Now you have a bootable Windows RE image in the C:\Win7\Winre.wim file and Windows 7 distribution media containing a bootable Windows RE image. You can create Windows RE recovery media using the C:\Win7\Winre.wim file as discussed in the next section.

Creating Windows RE Recovery Media

After you create a custom Windows RE image, you can create bootable Windows RE images on CD-ROM, DVD-ROM, or USB flash drives. Then, if a computer fails to start, you can start the computer by using this recovery media and attempt to fix the computer. The procedures to create recovery media are the same as those for creating Windows PE images. The key difference is that you create your ISO image from a Windows RE image rather than a Window PE image.

To set up a build environment for Windows RE on 32-bit computers, complete the following steps:

  1. Click Start, point to All Programs, and then click either Microsoft Windows OPK, Microsoft Windows AIK, or Microsoft Windows PE Kit as appropriate.

  2. Right-click Deployment Tools Command Prompt, and then click Run As Administrator.

  3. At the command prompt, enter copype x86 c:\winrec_x86.

You now have a build environment for Windows RE on 32-bit computers. You can create build environments for x64 and Itanium-based computers as well if you need to.

After you set up the build environment, create a customized Windows RE environment as discussed in the previous section, the section called “Creating a Customized Windows RE Image”. Next, copy the Windows RE image to the build environment by entering the following command:

copy c:\win7\winre.wim c:\winrec_x86\ISO\sources\boot.wim

You must name the Windows RE image file Boot.wim. This ensures that you can boot computers using the image.

Use the Oscdimg utility to create an ISO image that can be burned to a DVD. The following command creates an ISO image for the Windows RE image created previously:

oscdimg -n -bc:\winrec_x86\etfsboot.com c:\winrec_x86\iso

c:\winrec_x86\winrec.iso

Here, C:\Winrec_x86\Etfsboot.com is the path to the Etfsboot.com script required to create the ISO image, C:\Winrec_x86\ISO is the path to the folders for the ISO image, and C:\Winrec_x86\Winrec.iso is the path and file name of the ISO image that will be created. After you create the ISO image, you can burn the ISO image to a DVD by using a CD/DVD burning application such as Roxio Media Creator or Nero Media Burner.

To build a Windows RE x64 ISO image that supports both EFI and BIOS firmware, enter the following command:

oscdimg "-bootdata:2#p0,e,betfsboot.com#pEF,e,befisys.bin -u2 -udfver102

-o c:\winrec_x64\ISO c:\winrec_x86\winrec_2X.iso"

Here, –bootdata sets the boot information for EFI and BIOS, and –UDFVer sets the required UDF version. You set C:\Winrec_x64\ISO as the path to the folders for the ISO image, and C:\Winrec_x64\Winrec_2X.iso is the path and file name of the ISO image that will be created. After you create the ISO image, you can burn the ISO image to a DVD using a CD/DVD burning application.

You can create bootable Windows RE images on USB flash drives as well. The procedure is the same as described in the section called “Creating a Bootable USB Flash Drive” earlier in the chapter. Instead of copying a Windows PE image, copy your Windows RE image.

Adding Windows RE Images to Windows Deployment Services

When you've set up Windows Deployment Services on your network, you can add a Windows RE image to Windows Deployment Services so that you can easily deploy the image. To do this, follow these steps:

  1. On a management computer or a server running Windows Deployment Services, start the Windows Deployment Services console by clicking Start, pointing to All Programs, Administrative Tools, and then clicking Windows Deployment Services.

  2. In the Windows Deployment Services console, expand the Servers node and select the server you want to work with. Right-click the server's Boot Images folder, and then click Add Boot Image.

  3. On the Image File page, enter the path to the Windows RE image, and then click Open.

  4. On the Image Metadata page, type a name and description for the image, and then click Next.

  5. On the Summary page, click Next to add the image to Windows Deployment Services. When the import operation is complete, click Finish.

Deploying Windows with a Customized Windows RE

Windows RE is included with Windows 7. When you deploy a Windows computer, you can set up a recovery image. To do this, you must partition the hard disk with a recovery partition, copy the recovery image to this partition, and then create an association between the recovery image and the Windows 7 installation.

A Windows RE image can be installed on GUID partition table (GPT) disks that have the PARTITION_MSFT_RECOVERY_GUID attribute and on master boot record (MBR) disks with the type 0x7 or 0x27. With 0x27 disks, the recovery partition must be at the beginning of the disk. The partition used by Windows RE must be a primary partition formatted as NTFS on the same disk as the partition containing the Windows installation.

The recovery partition can be the same as the system partition, but it is better to separate the partitions. You should size the recovery partition so that it is appropriate for the size of the recovery image. Check the size of your modified Windows 7 installation image to help you size the partition. With a full recovery image, you normally need a recovery partition of between 9 and 10 gigabytes (GB).

To set up a computer with MBR hard disks for a recovery partition, follow these steps:

  1. Start the computer using bootable Windows PE media. The Windows PE into which you boot must include the WinPE-SRT package. Normally, this package is available only in the Windows OPK.

  2. At the Windows PE command prompt, enter diskpart, and then enter list disk. Note the disks that are available and their sizes. Disk 0 will need enough space for the recovery partition and the partition on which you will install Windows.

  3. Enter select disk 0, and then enter clean to wipe the disk and remove all contents.

  4. Create the system partition by entering create partition primary size=size, where size is the size in megabytes of the system partition, such as size=250.

  5. Format the system partition by entering format=fat32 label="System" quick. Make the system partition the active partition by entering active, and then assign drive letter S by entering assign letter=s.

  6. Create the recovery partition by entering create partition primary size=size id=27, where size is the size in megabytes of the recovery partition, such as size=1000, and the value id=27 creates a hidden recovery partition.

  7. Enter format=ntfs label="Recovery" quick to format the recovery partition with the NTFS file system.

  8. Enter assign letter=r to assign the drive letter R for the recovery partition.

  9. Create the Windows installation partition by entering create partition primary size=size, where size is the size in megabytes of the Windows installation partition, such as size=2000.

  10. Format the Windows partition by entering format=ntfs label="Windows" quick, and then enter assign letter=c to assign the drive letter C for the Windows partition.

  11. Enter exit to quit DiskPart. Don't exit the command prompt.

To set up a computer with GPT hard disks for a recovery partition, follow these steps:

  1. Start the computer using bootable Windows PE media. The Windows PE into which you boot must include the WinPE-SRT package. Normally, this package is available only in the Windows OPK. For Unified Extensible Firmware Interface (UEFI)-based computers, you must start Windows PE by using the EFI boot-mode option in the EFI shell.

  2. At the prompt, enter diskpart, and then enter list disk. Note the disks that are available and their sizes. Disk 0 will need enough space for the recovery partition and the partition on which you will install Windows.

  3. Enter select disk 0, and then enter clean to wipe the disk and remove all contents. For UEFI-based computers, you will need to set the GPT disk information by entering convert gpt.

  4. Create the EFI system partition by entering create partition efi size=size, where size is the size in megabytes of the EFI system partition, such as size=200.

  5. Format the EFI system partition by entering format=fat32 label="System" quick, and then assign drive letter S by entering assign letter=s.

  6. Create the MSR partition by entering create partition msr size=size, where size is the size in megabytes of the MSR partition, such as size=128.

  7. Create the recovery partition by entering create partition primary size=size, where size is the size in megabytes of the recovery partition, such as size=1000.

  8. Identify the partition as a recovery partition by entering set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac".

  9. Format the recovery partition by entering format=ntfs label="Recovery" quick, and then assign drive letter R by entering assign letter=r.

  10. Create the Windows installation partition by entering create partition primary. Because you don't specify a size, the partition will fill the remainder of the disk.

  11. Enter format=ntfs label="Windows" quick to format the partition with the NTFS file system.

  12. Enter assign letter=c to assign the drive letter C for the Windows partition.

  13. Enter exit to quit DiskPart. Don't exit the command prompt.

Now that you've configured the computer's hard disks, you can deploy Windows. One way to do this is to complete the following steps:

  1. Insert the media or connect to the network location containing the Windows 7 image you are deploying.

  2. Use ImageX to apply the Windows 7 image. For example, if the installation image is on the E drive, you would enter imagex /apply e:\images\install.wim 1 c:.

  3. You can use BCDBoot to copy system files to the system partition and update the BCD store. To do this, enter cd c:\windows\system32, and then enter bcdboot c:\windows /l en-us /s s:. The /l option sets the locale. The /s option specifies the drive designator for the system partition.

  4. Copy the Windows RE image to partition 1. For example, if the installation image is on the E drive, you would enter copy e:\images\winre.wim r:.

  5. Create an association between the Windows RE image and the Windows 7 installation using Reagentc.exe. For example, enter reagentc.exe /setreimage /path r:\.

Tip

Optionally, you can map a keyboard key or a custom hardware button to launch Windows RE directly when the key or button is pressed during startup of the system. To map the key or button, add the /Bootkey option when using Reagentc.exe to associate the Windows RE image to the Windows 7 installation. For example, enter reagentc.exe /setreimage /path r: /bootkey ScanCode, where ScanCode is the four-digit hexadecimal scan code of the keyboard key or custom hardware button.

Note

Normally, the Windows RE installation will be complete when the user finalizes the installation. However, if you need to start the computer in audit mode before completing the installation and you are not generalizing the installation again by using the Sysprep tool, you can complete the Windows RE installation during audit mode. At the command prompt, enter reagentc.exe /enable /auditmode.

Another way to deploy Windows is to use separate images for each partition. Let's say you capture separate images using the following steps:

  1. Start the computer using bootable Windows PE media. For UEFI-based computers, you must start Windows PE by using the EFI boot-mode option in the EFI shell.

  2. At the Windows PE command prompt, enter diskpart, then enter select disk 0, and then enter list volume. Note the partition information provided. If any partition you want to capture doesn't have a drive letter, you need to select the volume and then assign a drive letter. For example, if the recovery partition is volume 0 and it doesn't have a drive letter, enter select volume 0, and then enter assign letter=r.

  3. Enter cd c:\windows\system32 to change to the directory containing the ImageX tool.

  4. Capture images for each customized partition. If you have separate Windows, system, and recovery partitions, you could use the following commands:

    imagex /capture c:\ c:\win-partition.wim "Windows partition"
    
    
    
    imagex /capture s:\ c:\sys-partition.wim "System partition"
    
    
    
    imagex /capture r:\ c:\rec-partition.wim "Recovery partition"
  5. Connect to your distribution share by using the Net Use command, such as net use Z: \\ImageShare\Images. Copy the WIM files to the network share by using the following commands:

    copy c:\win-partition.wim Z:\
    
    
    
    copy c:\sys-partition.wim Z:\
    
    
    
    copy c:\rec-partition.wim Z:\

Now you can apply the separate images using the following steps:

  1. Start the computer using bootable Windows PE media. For UEFI-based computers, you must start Windows PE by using the EFI boot-mode option in the EFI shell.

  2. Insert media or connect to the network location containing images you are deploying. You can connect to a network location with Net Use—for example, net use Z: \\ImageShare\Images.

  3. At the Windows PE command prompt, enter diskpart, enter select disk 0, and then enter list volume. Note the partition information provided. If any partition you want to apply an image to doesn't have a drive letter, you need to select the volume and then assign a drive letter. For example, if the recovery partition is volume 0 and it doesn't have a drive letter, enter select volume 0, and then enter assign letter=r.

  4. Enter cd c:\windows\system32 to change to the directory containing the ImageX tool.

  5. Use ImageX to apply the Windows partition image. For example, if the installation image is on the Z drive, you would enter imagex /apply z:\win-partition.wim 1 c:.

  6. Use ImageX to apply the system partition image. For example, if the system partition image is on the Z drive, you would enter imagex /apply z:\sys-partition.wim 1 s:.

  7. Use ImageX to apply the recovery partition image. For example, if the recovery partition image is on the Z drive, you would enter imagex /apply z:\rec-partition.wim 1 r:.


Customizing a Windows PE Image

You can customize a mounted boot or installation image using the DISM utility. You work with mounted images by using the subcommands of Dism /image. DISM options designed for servicing Windows PE images are listed in Table 2.1.

Table 2.1. Common DISM Options for Windows PE Images

OPTION

DESCRIPTION

EXAMPLE

/Get-PESettings

Displays a list of Windows PE settings in the mounted Windows PE image. The list includes current profiling state, scratch space settings, and target path settings.

Dism /image:C:\winpe_x86\mount /Get-PESettings

/Get-Profiling

Displays the status of the profiling feature.

Dism /image:C:\winpe_x86\mount /Get-Profiling

/Get-ScratchSpace

Displays the configured amount of Windows PE system volume scratch space. This setting represents the amount of writable space available on the Windows PE system volume when booted in RAM disk mode.

Dism /image:C:\winpe_x86\mount /Get-ScratchSpace

/Get-TargetPath

Displays the target path of the Windows PE image. The target path represents a path to the root of the Windows PE image at boot time.

Dism /image:C:\winpe_x86\mount /Get-TargetPath

/Set-ScratchSpace:Size

Sets the available scratch space in megabytes. Valid values are 32, 64, 128, 256, and 512.

Dism /image:C:\winpe_x86\mount /Set-ScratchSpace:256

/Set-TargetPath:Path

When you are booting to a hard disk, this option sets the location of the Windows PE image on the disk. The path must start with a letter (any letter from C to Z) and must be followed by :\.

Dism /image:C:\winpe_x86\mount /Set-TargetPath:X:\

/Enable-Profiling

Enables profiling so that you can create your own profiles. By default, profiling is disabled.

Dism /image:C:\winpe_x86\mount /Enable-Profiling

/Disable-Profiling

Turns off profiling.

Dism /image:C:\winpe_x86\mount /Disable-Profiling

/Apply-Profiles:Path

Applies a profile and removes files that are not used in the custom profile. Critical boot files are not deleted. A Windows PE image that has been customized using any profile is not serviceable.

Dism /image:C:\winpe_x86\mount /Apply-Profiles: C:\profiles\prof.txt


If you mount an image using the following command:

imagex /apply c:\winpe_x86\iso\sources\boot.wim 1 c:\winpe_x86\mount\

you'll work with the image via the mount point:

c:\winpe_x86\mount\

All Windows PE images have the following settings:

  • Profiling status Specifies whether profiling is enabled or disabled.

  • Scratch space Specifies the amount of memory to allocate to the Windows PE work space, such as 32 MB.

  • Target path Specifies the target path used when you boot the Windows PE image, such as X:\.

To review the settings of the mounted image, enter the following command:

dism /image:ImagePath /Get-PESettings

where ImagePath is the path to the image you've mounted, such as:

dism /image:c:\winpe_x86\mount\ /get-pesettings

By default, Windows PE allocates 32 MB of writable memory for its work space. You can increase the work space up to 512 MB by typing the following at a command prompt:

dism /image:ImagePath /Set-ScratchSpace:Size

where ImagePath is the path to the image you've mounted, and Size is the work space size in megabytes. Valid values for Size are 32, 64, 128, 256, and 512. The following example sets the work space to 128 MB:

dism /image:c:\winpe_x86\mount\ /Set-ScratchSpace:128

You might want to increase the amount of memory allocated to the work space if you plan to use profiling or run nonstandard applications in the Windows PE environment. If Windows PE runs out of memory, applications might become unresponsive.

There are many other things you can do with Windows PE images. You can get information about all installed drivers by entering the following command:

dism /image:c:\winpe_x86\mount\ /get-drivers /all

Note

When a DISM option expects you to provide a working value, follow the option name with a colon and then specify the required value. Don't insert a space between the colon and the value.

To add a third-party driver to Windows PE images, you use /Add-Driver. The basic syntax is:

dism /image:MountPoint /add-driver /Driver:InfPath

where MountPoint is the path where the image is mounted, and InfPath is the path for the .inf file for the driver, for example:

dism /image:c:\winpe_x86\mount\ /add-driver

/driver:c:\drivers\remmedia\rem.inf

If a common folder has subdirectories containing drivers to add, you can specify the base folder to search recursively by using the following syntax:

dism /image:MountPoint /add-driver /driver:BaseFolder /recurse

where MountPoint is the path where the image is mounted, and BaseFolder is the folder to search for drivers, such as:

dism /image:c:\winpe_x86\mount\ /add-driver /driver:c:\drivers /recurse

Tip

With x64 and Itanium-based computers, you must use signed drivers by default. To force DISM to accept unsigned drivers, add the /ForceUnsigned option.

To add applications to a Windows PE image, simply use Copy or Xcopy to copy the necessary application files to the appropriate subdirectory. For example, you can copy Imagex.exe to the root directory of the image by using the following command:

xcopy "C:\Program Files\Windows AIK\Tools\x86\Imagex.exe"

c:\winpe_x86\mount\

You can get information about packages installed in a Windows PE image by using the /Get-Packages option. The basic syntax is:

dism /image:MountPoint /get-packages

such as:

dism /image:c:\winpe_x86\mount\ /get-packages

To add packages, you use the /Add-Package option. The available packages you can install include those listed in Table 2.2, “Common Windows PE Packages”. The basic syntax for adding packages is:

dism /image:MountPoint /add-package /PackagePath:PathtoCab

Here is an example:

dism /image:C:\winpe_x86\mount /Add-Package /PackagePath:"C:\Program Files\Windows AIK\Tools\PETools\x86\WinPE_OCs\winpe-wmi.cab"

Table 2.2. Common Windows PE Packages

PACKAGE NAME

DESCRIPTION

WinPE-FONTSupport-Language.cab

Installs fonts for the specified language: ja-jp, ko-kr, zh-cn, zh-hk, or zh-tw

WinPE-HTA.cab

Installs HTML application support

WinPE-LegacySetup.cab

Installs the legacy setup package

WinPE-MDAC.cab

Installs Microsoft Data Access Component support

WinPE-Scripting.cab

Installs Windows Script Host support

WinPE-Setup-Client.cab

Installs the client setup package (as long as you have already installed the main setup package)

WinPE-Setup.cab

Installs the main setup package

WinPE-Setup-Server.cab

Installs the server setup package (as long as you have already installed the main setup package)

WinPE-SRT.cab

Installs the Windows Recovery Environment component (Windows OPK only)

WinPE-WDS-Tools.cab

Installs the Windows Deployment Services tools package

WinPE-WMI.cab

Installs Windows Management Instrumentation (WMI) support


The base Windows PE image does not contain all the packages listed in the table. You must use the DISM tool to install the additional packages you want to use. The packages are located in the \Windows OPK\Tools\PETools\ProcType or \Windows AIK\Tools\PETools\ProcType directory, where ProcType is amd64, ia64, or x86. When you install font support for additional languages, be sure the required language resources are installed on the client computer. The language resources are located in a language-specific subfolder of the \Windows OPK\Tools\PETools\ProcType or \Windows AIK\Tools\PETools\ProcType directory.

Once you install language support, you can specify the user interface language you want by using the /SetUILang option. For example, if you want to use U.S. English, enter:

dism /image:c:\winpe_x86\mount /Set-UILang:en-US

You can verify the language settings by using the /Get-Intl option, such as:

dism /image:c:\winpe_x86\mount /Get-Intl

After you have made all the necessary changes, you can unmount the image and commit your changes. The basic syntax is:

imagex /unmount MountPath /commit

Here is an example: :

imagex /unmount c:\winpe_x86\mount /commit

Note

If you unmount an image without committing the changes, your changes will be discarded.

Now you have a customized Windows PE image. You can replace the default Windows PE image in the ISO directory with your customized image by entering the following command:

copy c:\winpe_x86\boot.wim c:\winpe_x86\ISO\sources\boot.wim

Creating a Bootable USB Flash Drive

You can create bootable Windows PE images on USB flash drives as long as the flash drive has the capacity to store the entire Windows image. You might need to modify computer firmware to allow booting from USB disk devices.

To create a bootable USB flash drive, insert the device into a USB port, and then use the DiskPart utility to prepare the device. The commands you need to run are as follows:

  1. At an elevated administrator command prompt, enter diskpart, and then enter list disk. Note the disk number and size of the USB flash drive.

  2. Enter select disk n, where n is the device you are preparing.

  3. Enter clean to wipe the device and remove all contents.

  4. Enter create partition primary size=size, where size is the size in MB of the USB flash drive listed previously.

  5. Enter select partition 1 to select the partition you just created, and then enter active to mark the new partition as active.

  6. Enter format fs=fat32 to format the partition with the FAT32 file system.

  7. Enter assign to assign the next available drive letter to the USB flash drive, and then enter exit to quit DiskPart. Note the drive letter assigned in the output. Don't exit the command prompt.

  8. Write a new boot sector to the USB flash drive by entering bootsect /nt60 e: /force, where e: is the drive letter of the USB flash drive.

    Note

    Bootsect is in the PeTools\x86 and PeTools\amd64 folders within the build. Use the version of Bootsect that supports the type of Windows PE image you are creating.

  9. Copy the contents of your ISO folder to the USB flash drive by entering xcopy /echry c:\winpe_x86\iso\*.* e:\.

When the copy is complete, remove your USB flash drive. The USB flash drive is now bootable Windows media.

Note

Some USB flash drives do not support this preparation process, and you might not be able to make the device bootable in this way. The devices that do not support this process are typically set so they are recognized as removable media devices and not USB disk devices. Because of this, you might need to refer to the device manufacturer's Web site for formatting documentation and tools.



0 Replies