WinPE:装载和自定义WinPE: Mount and Customize

WinPE 是以 .wim 文件形式提供的。WinPE ships as a .wim file. 装载和自定义 WinPE 映像的过程与装载和自定义任何其他 Windows 映像的过程相同。Mounting and customizing a WinPE image is the same process as any other Windows image. WinPE 还有一些特定于自身的自定义项。WinPE also has some customizations that are specific to it. 本主题将介绍自定义 WinPE 映像的常用方法。This topic covers the common ways to customize a WinPE image.

常用自定义项:Common customizations:

获取包含 Windows PE 工具的 Windows 评估和部署工具包Get the Windows Assessment and Deployment Kit with Windows PE tools

创建一组 32 位或 64 位 Windows PE 文件Create a set of either 32-bit or 64-bit Windows PE files

在能够自定义 WinPE 之前,需有一个可用的 WinPE 映像。Before you can customize WinPE, you need to have a WinPE image to work with. 如果需要获取 WinPE 映像,请参阅 WinPE:创建可启动的 USB 驱动器了解如何操作。If you need to get a WinPE image, see WinPE: Create USB bootable drive to learn how.

装载 Windows PE 启动映像Mount the Windows PE boot image

  • 使用 DISM 将 WinPE 映像装载到技术人员电脑上的某个临时位置:Use DISM to mount the WinPE image into a temporary location on your technician PC:

    Dism /Mount-Image /ImageFile:"C:\WinPE_amd64\media\sources\boot.wim" /index:1 /MountDir:"C:\WinPE_amd64\mount"
    

添加自定义项Add customizations

添加设备驱动程序(.inf 文件)Add device drivers (.inf files)

  • 使用 DISM /add-driver 可将设备驱动程序添加到 WinPE 映像。Use DISM /add-driver to add a device driver to your WinPE image.

    Dism /Add-Driver /Image:"C:\WinPE_amd64\mount" /Driver:"C:\SampleDriver\driver.inf"
    

    可以使用一个命令将多个驱动程序添加到映像,但如果单独添加每个驱动程序包的话,通常可以更轻松地排查问题。You can add multiple drivers to an image by using one command, but it's often easier to troubleshoot problems if you add each driver package individually.

    若要详细了解驱动程序,请参阅添加设备驱动程序(.inf 文件)To learn more about drivers, see Add device drivers (.inf files). 若要查看所有可用的 DISM 驱动程序服务选项,请参阅 DISM 驱动程序服务命令行选项To see all available DISM driver servicing options, see DISM driver servicing command-line options.

添加包/语言/可选组件/.cab 文件Add packages/languages/optional components/.cab files

  • 可以使用 DISM 添加 WinPE 中的某些包,以启用其他功能和语言。WinPE has packages that you can add with DISM to enable additional features and languages. 使用 DISM /add-package 可将可选组件添加到映像。Use DISM /add-package to add optional components to your image. 添加某个 WinPE 可选组件时,请确保添加该可选组件及其关联的语言包。When you add a WinPE optional component, make sure that you add both the optional component and its associated language packs.

    Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-HTA.cab"  
    
    Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"C:\Program Files\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-HTA_en-us.cab"
    

    若要详细了解可用的可选组件和语言,请参阅 WinPE:添加包(可选组件参考)To learn more about available optional components and languages, see WinPE: Add packages (Optional Components Reference).

添加文件和文件夹Add files and folders

  • 将文件和文件夹复制到 C:\WinPE_amd64\mount 文件夹中。Copy files and folders into the C:\WinPE_amd64\mount folder. 这些文件将显示在 WinPE 中的 X:\ 文件夹下。These files will show up in the X:\ folder in WinPE.

    不要添加太多的文件,否则会减慢 WinPE 的速度,并可能会填满默认 RAMDisk 环境中的可用内存。Don't add too many files, as these will slow down WinPE and can fill up the available memory in the default RAMDisk environment.

添加启动脚本Add a startup script

  • 修改 Startnet.cmd 以包含自定义的命令。Modify Startnet.cmd to include your customized commands. 此文件位于装载的映像上的 C:\WinPE_amd64\mount\Windows\System32\Startnet.cmd 中。This file is located in your mounted image at C:\WinPE_amd64\mount\Windows\System32\Startnet.cmd.

    还可以从此文件调用其他批处理文件或命令行脚本。You can also call other batch files or command line scripts from this file.

    若要获得即插即用或网络支持,请确保在自定义的 Startnet.cmd 脚本中包含对 wpeinit 的调用。For Plug and Play or networking support, make sure that you include a call to wpeinit in your customized Startnet.cmd script. 有关详细信息,请参阅 Wpeinit 和 Startnet.cmd:使用 WinPE 启动脚本For more info, see Wpeinit and Startnet.cmd: Using WinPE Startup Scripts.

添加应用Add an app

  1. 在装载的 WinPE 映像中创建一个应用目录。Create an app directory inside the mounted WinPE image.

    md "C:\WinPE_amd64\mount\windows\<MyApp>"
    
  2. 将所需的应用文件复制到本地 WinPE 目录。Copy the necessary app files to the local WinPE directory.

    Xcopy C:\<MyApp> "C:\WinPE_amd64\mount\windows\<MyApp>"
    
  3. 稍后将通过启动 WinPE 并从 X: 目录运行应用程序来测试应用。Test the app later by booting WinPE and running the application from the X: directory.

    X:\Windows\System32> X:\Windows\<MyApp>
    

    如果应用需要临时存储,或者 WinPE 在运行应用时无响应,则你可能需要增加分配给 WinPE 的临时存储量(暂存空间)。If your app requires temporary storage, or if WinPE becomes unresponsive when it runs an app, you may need to increase the amount of temporary storage (scratch space) allocated to WinPE.

  4. 若要自动启动在 WinPE 启动时运行的 shell 或应用程序,请将路径位置添加到 Winpeshl.ini 文件。To automatically launch a shell or application that runs when WinPE starts, add the path location to the Winpeshl.ini file. 有关详细信息,请参阅 Winpeshl.ini 参考:启动 WinPE 时启动应用For more info, see Winpeshl.ini Reference: Launching an app when WinPE starts.

添加临时存储(暂存空间)Add temporary storage (scratch space)

  • WinPE 在 X: 驱动器中留出了内存用于解包 WinPE 文件,并留出了额外的临时文件存储(称为暂存空间)供应用程序使用。WinPE reserves memory on the X: drive to unpack the WinPE files, plus additional temporary file storage, known as scratch space, that can be used by your applications. 如果电脑的 RAM 超过 1GB,那么此临时存储量默认为 512MB,否则默认值为 32MB。By default, this is 512MB for PCs with more than 1GB of RAM, otherwise the default is 32MB. 有效值为 32、64、128、256 或 512。Valid values are 32, 64, 128, 256, or 512.

    Dism /Set-ScratchSpace:256 /Image:"C:\WinPE_amd64\mount"
    

替换背景图像Replace the background image

如果你有多个版本的 WinPE,可以设置背景图像,以便能够立即判断哪个 WinPE 版本正在运行。If you've got multiple versions of WinPE, you can set the background image so you can instantly tell which version of WinPE is running.

更改 WinPE 背景图像文件 (\windows\system32\winpe.jpg) 的安全权限。Change the security permissions of the WinPE background image file (\windows\system32\winpe.jpg). 这样就可以修改或删除该文件。This allows you to modify or delete the file.

  1. 在 Windows 资源管理器中导航到 C:\WinPE_amd64\mount\windows\system32In Windows Explorer, navigate to C:\WinPE_amd64\mount\windows\system32.

  2. 右键单击 C:\WinPE_amd64\mount\windows\system32\winpe.jpg 文件,然后选择“属性”>“安全性”选项卡 >“高级”。 Right-click the C:\WinPE_amd64\mount\windows\system32\winpe.jpg file, and select Properties > Security tab > Advanced.

  3. 在“所有者”旁边,选择“更改”。 Next to Owner, select Change. 将所有者更改为“管理员”。 Change the owner to Administrators.

  4. 应用更改,然后退出“属性”窗口以保存更改。Apply the changes, and exit the Properties window to save changes.

  5. 右键单击 C:\WinPE_amd64\mount\windows\system32\winpe.jpg 文件,然后选择“属性”>“安全性”选项卡 >“高级”。 Right-click the C:\WinPE_amd64\mount\windows\system32\winpe.jpg file, and select Properties > Security tab > Advanced.

  6. 修改“管理员”的权限以允许完全访问。 Modify the permissions for Administrators to allow full access.

  7. 应用更改,然后退出“属性”窗口以保存更改。Apply the changes, and exit the Properties window to save changes.

  8. winpe.jpg 文件替换为自己的图像文件。Replace the winpe.jpg file with your own image file.

将电源方案设置为高性能Set the power scheme to high performance

注意:使用高性能电源方案可能会使运行的设备的温度高于往常。Note: Using the high performance power scheme can make the device run hotter than usual.

  1. 在记事本中编辑文件 C:\WinPE_amd64\mount\windows\system32\startnet.cmd,添加一条命令,以将电源方案设置为“高性能”。In Notepad, edit the file: C:\WinPE_amd64\mount\windows\system32\startnet.cmd, adding a command to set the power scheme to High Performance.

    wpeinit
    powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 
    

添加应答文件设置Add answer file settings

  • 可以使用应答文件来管理某些 WinPE 设置,例如防火墙、网络和显示设置。Some WinPE settings can be managed by using an answer file, such as firewall, network, and display settings. 创建一个应答文件,将其命名为 unattend.xml,然后将其添加到 WinPE 媒体的根目录以处理这些设置。Create an answer file, name it unattend.xml, and add it to the root of the WinPE media to process these settings. 有关详细信息,请参阅 Wpeinit 和 Startnet.cmd:使用 WinPE 启动脚本For more information, see Wpeinit and Startnet.cmd: Using WinPE Startup Scripts.

向 WinPE 添加更新(如果需要)Add updates to WinPE (if needed)

可对 WinPE 映像应用更新,但只在特定的情况下才需要这样做。You can apply updates to your WinPE image, but you'll only need to for certain situations.

如果已收到指示,需要对 WinPE 映像应用更新,必须先从 Microsoft 更新目录下载适用于你的 WinPE 版本的最新更新。If you've been instructed to apply an update to your WinPE image, you'll have to first download the latest update for your WinPE version from the Microsoft update catalog. 适用于 Windows 10 匹配版本的更新中包含了 WinPE 更新。Updates for WinPE are included in updates for the matching version of Windows 10. 可以在 Windows 10 更新历史记录中找到有关最新可用 Windows 10 更新的信息。You can find information about the latest available updates for Windows 10 at Windows 10 update history.

  1. 下载最新的更新。Download the latest update.

  2. 对装载的 WinPE 映像应用更新。Apply the update to your mounted WinPE image.

    Dism /Add-Package /Image:"C:\WinPE_amd64\mount" /PackagePath:"E:\windows10.0-kbxxxxx.msu"
    

    其中,Windows10.0-kbxxxxx.msu 是更新文件的名称Where Windows10.0-kbxxxxx.msu is the name of the update file

  3. 锁定更新:Lock in the update:

    dism /cleanup-image /image:C:\WinPE_amd64\mount\windows /startcomponentcleanup /resetbase /scratchdir:C:\temp
    

卸载 Windows PE 映像并创建媒体Unmount the Windows PE image and create media

  1. 卸载 WinPE 映像并提交更改。Unmount the WinPE image, committing changes.

    Dism /Unmount-Image /MountDir:"C:\WinPE_amd64\mount" /commit
    
  2. 创建可启动的媒体,例如 U 盘。Create bootable media, such as a USB flash drive.

    MakeWinPEMedia /UFD C:\WinPE_amd64 F:
    
  3. 启动该媒体。Boot the media. WinPE 将自动启动。WinPE starts automatically. WinPE 窗口出现后,wpeinit 命令会自动运行。After the WinPE window appears, the wpeinit command runs automatically. 这可能需要几分钟。This may take a few minutes. 验证自定义项。Verify your customizations.

故障排除Troubleshooting

删除工作目录:To delete a working directory:

在某些情况下,你可能无法恢复装载的映像。In some cases, you may not be able to recover the mounted image. DISM 可以防止意外删除工作目录,因此,你可能需要尝试以下步骤才能着手删除装载的目录。DISM protects you from accidentally deleting the working directory, so you may have to try the following steps to get access to delete the mounted directory. 尝试以下每个步骤:Try each of the following steps:

  1. 尝试重新装载映像:Try remounting the image:

    dism /Remount-Image /MountDir:C:\mount
    
  2. 尝试卸载映像并丢弃更改:Try unmounting the image, discarding the changes:

    dism /Unmount-Image /MountDir:C:\mount /discard
    
  3. 尝试清理与已装载映像关联的资源:Try cleaning up the resources associated with the mounted image:

    dism /Cleanup-Mountpoints
    

相关主题Related topics

WinPE:优化和收缩映像WinPE: Optimize and shrink the image

适用于 Windows 10 的 WinPEWinPE for Windows 10

WinPE:创建 USB 可启动驱动器WinPE: Create USB Bootable drive

WinPE:创建启动 CD、DVD、ISO 或 VHDWinPE: Create a Boot CD, DVD, ISO, or VHD

WinPE:在硬盘驱动器(平面引导磁盘或非 RAM)上安装WinPE: Install on a Hard Drive (Flat Boot or Non-RAM)

WinPE:以 UEFI 或旧版 BIOS 模式启动WinPE: Boot in UEFI or legacy BIOS mode

WinPE:添加包(可选组件参考)WinPE: Add packages (Optional Components Reference)