在脱机 Windows 映像中添加和删除驱动程序Add and Remove Drivers to an offline Windows Image

可以使用 DISM 在脱机 Windows 或 WinPE 映像中安装或删除驱动 () 文件。You can use DISM to install or remove driver (.inf) files in an offline Windows or WinPE image. 您可以使用命令提示符直接添加或删除驱动程序,或将无人参与的答案文件应用到装载的 .wim、. ffu、.vhd 或 .vhdx 文件。You can either add or remove the drivers directly by using the command prompt, or apply an unattended answer file to a mounted .wim, .ffu, .vhd, or .vhdx file.

使用 DISM 将设备驱动程序安装到脱机映像时,会将设备驱动程序添加到脱机映像的驱动程序存储区中。When you use DISM to install a device driver to an offline image, the device driver is added to the driver store in the offline image. 启动映像时,即插即用 (PnP) 运行,并将存储中的驱动程序与计算机上相应的设备关联。When the image is booted, Plug and Play (PnP) runs and associates the drivers in the store to the corresponding devices on the computer.

备注

若要将驱动程序添加到脱机 Windows 10 映像,你必须使用运行 Windows 10、Windows Server 2016 或 Windows 预安装环境 (用于 Windows 10 的 WinPE) 的技术人员计算机。To add drivers to a Windows 10 image offline, you must use a technician computer running Windows 10, Windows Server 2016, or Windows Preinstallation Environment (WinPE) for Windows 10. 如果从运行任何其他操作系统的技术人员计算机脱机向 Windows 10 映像添加驱动程序,则驱动程序签名验证可能会失败。Driver signature verification may fail when you add a driver to a Windows 10 image offline from a technician computer running any other operating system.

若要了解如何在运行的 Windows 电脑上添加驱动程序,请参阅 在审核模式下联机添加驱动程序安装即插即用设备To learn how to add a driver on a running Windows PC, see Add a driver online in audit mode or Install a plug and play device. 若要了解如何将驱动程序添加到运行 WinPE 的 PC,请参阅 Drvload 命令行选项To learn how to add a driver to a PC running WinPE, see Drvload command line options.

驱动程序类型Driver types

  • .inf-style 驱动程序:很多驱动程序包含一个信息文件(具有 .inf 扩展名)来帮助安装驱动程序。.inf-style drivers: Many drivers include an information file (with an .inf extension) to help install the driver. 可以使用本主题中所述的工具安装这些驱动程序。These can be installed using tools described in this topic.
  • .exe-style 驱动程序:不包含 .inf 文件的驱动程序通常必须像常规 Windows 桌面应用程序一样来安装。.exe-style drivers: Drivers without an .inf file often must be installed like typical Windows desktop applications. 若要了解如何添加这些项,请参阅 在审核模式下联机添加驱动程序To learn how to add these, see Add a driver online in Audit Mode
  • 启动关键驱动程序:有时可能需要将图形和存储驱动程序添加到 windows 映像 (如本主题) 、windows PE 映像以及 windows Recovery (WinRE) 映像中所示。Boot-critical drivers: Graphics and storage drivers may sometimes need to be added to the Windows image (as shown in this topic), as well as the Windows PE image, and in the Windows recovery (WinRE) image.

将驱动程序添加到脱机 Windows 映像Add drivers to an offline Windows image

若要将驱动程序添加到脱机映像,必须先装载映像,然后再添加驱动程序。To add drivers to an offline image, you have to mount an image prior to adding drivers.

如果要将驱动程序添加到 WinPE 映像,可以将其添加到 运行 copype.cmd时指定的输出文件夹中的 WinPE 映像,例如: C:\WinPE_amd64\media\sources\boot.wimIf you're adding drivers to a WinPE image, you can add them to the WinPE image in the output folder you specified when you ran copype, for example: C:\WinPE_amd64\media\sources\boot.wim. 这可确保每次从该文件夹中生成 WinPE 媒体时,驱动程序都将包含在 WinPE 中。This ensures that drivers will be included in WinPE each time you build WinPE media from that folder.

  1. 装载 Windows 映像。Mount a Windows image. 例如:For example:
Dism /Mount-Image /ImageFile:C:\test\images\install.wim /MountDir:C:\test\offline

有关详细信息,请参阅 使用 DISM 装载和修改 Windows 映像See Mount and modify a Windows image using DISM for more info.

  1. 将驱动程序添加到映像。Add a driver to the image.
Dism /Image:C:\test\offline /Add-Driver /Driver:C:\drivers\mydriver.inf

若要安装文件夹及其所有子文件夹中的所有驱动程序,请指向该文件夹,并使用 /Recurse 选项。To install all of the drivers from a folder and all its subfolders, point to the folder and use the /Recurse option.

Dism /Image:C:\test\offline /Add-Driver /Driver:c:\drivers /Recurse

若要查看所有 DISM 驱动程序服务命令行选项,请参阅 dism 驱动程序服务命令行选项To see all DISM driver servicing command line options, see DISM driver servicing command-line options.

警告

使用 /Recurse 可以很方便,但使用它可以轻松地将图像膨胀。Using /Recurse can be handy, but it's easy to bloat your image with it. 一些驱动程序包包含多个 .inf 驱动程序包,通常它们从同一文件夹共享负载文件。Some driver packages include multiple .inf driver packages, which often share payload files from the same folder. 在安装过程中,每个 .inf 驱动程序包都展开到一个单独的文件夹中。During installation, each .inf driver package is expanded into a separate folder. 每个单独的文件夹都有有效负载文件的副本。Each individual folder has a copy of the payload files. 我们已看到这样的情况:使用 /Recurse 选项添加时,900MB 文件夹中的常见驱动程序导致映像大小增加了 10GB。We've seen cases where a popular driver in a 900MB folder added 10GB to images when added with the /Recurse option.

若要安装未签名的驱动程序,请使用 /ForceUnsigned 来替代安装在基于 X64 的计算机上的驱动程序必须具有数字签名的要求。To install an unsigned driver, use /ForceUnsigned to override the requirement that drivers installed on X64-based computers must have a digital signature.

Dism /Image:C:\test\offline /Add-Driver /Driver:C:\drivers\mydriver.inf /ForceUnsigned
  1. 检查是否已添加驱动程序。Check to see if the driver was added. 添加到 Windows 映像的驱动程序名为 "Oem" * 。Drivers added to the Windows image are named Oem*.inf. 这可确保新添加的驱动程序具有唯一的命名。This guarantees unique naming for newly added drivers. 例如,文件 MyDriver1.inf 和 MyDriver2.inf 会被重命名为 Oem0.inf 和 Oem1.inf。For example, the files MyDriver1.inf and MyDriver2.inf are renamed Oem0.inf and Oem1.inf.
Dism /Image:C:\test\offline /Get-Drivers
  1. 提交更改并卸载映像。Commit the changes and unmount the image.
Dism /Unmount-Image /MountDir:C:\test\offline /Commit

从脱机 Windows 映像中删除驱动程序Remove drivers from an offline Windows image

  1. 在提升的命令提示符下,装载脱机 Windows 映像:At an elevated command prompt, mount the offline Windows image:
Dism /Mount-Image /ImageFile:C:\test\images\install.wim /Name:"Windows 10 Home" /MountDir:C:\test\offline
  1. 从映像中删除特定驱动程序。Remove a specific driver from the image. 还可以在一个命令行上删除多个驱动程序。Multiple drivers can also be removed on one command line.
Dism /Image:C:\test\offline /Remove-Driver /Driver:OEM1.inf /Driver:OEM2.inf

警告

删除启动关键驱动程序包可能导致脱机 Windows 映像无法启动。Removing a boot-critical driver package can make the offline Windows image unbootable. 有关详细信息,请参阅 DISM 驱动程序服务 Command-Line 选项For more information, see DISM Driver Servicing Command-Line Options.

  1. 提交更改并卸载映像。Commit the changes and unmount the image.
Dism /Unmount-Image /MountDir:C:\test\offline /Commit

使用无人参与应答文件将驱动程序添加到脱机 Windows 映像Add drivers to an offline Windows image by using an unattended answer file

  1. 收集要在 Windows 映像上安装的设备驱动程序 .inf 文件。Gather the device driver .inf files that you intend to install on the Windows image.

备注

将答案文件中引用的目录和子目录中的所有驱动程序添加到映像。All drivers in the directory and subdirectories that are referenced in the answer file are added to the image. 应当小心管理答案文件和这些目录,以解决有关因不必要的驱动程序包而增加映像大小的问题。You should manage the answer file and these directories carefully to address concerns about increasing the size of the image with unnecessary driver packages.

  1. 使用 Windows 系统映像管理器 (Windows SIM) 创建一个应答文件,其中包含指向要安装的设备驱动程序的路径。Use Windows System Image Manager (Windows SIM) to create an answer file that contains the paths to the device drivers that you want to install.
  • Microsoft-Windows-PnpCustomizationsNonWinPE\DriverPaths\PathAndCredentials\CredentialsofflineServicing 配置阶段将组件添加到答案文件中。Add the Microsoft-Windows-PnpCustomizationsNonWinPE\DriverPaths\PathAndCredentials\Credentials component to your answer file in the offlineServicing configuration pass.

对于要访问的每个位置,通过右键单击 "应答文件" 窗格中的 " DriverPaths ",然后单击 "插入新 PathAndCredentials",添加一个单独的 PathAndCredentials 列表项。For each location that you intend to access, add a separate PathAndCredentials list item by right-clicking on DriverPaths in the Answer File pane and clicking Insert New PathAndCredentials.

有关如何修改应答文件的信息,请参阅 在答案文件中配置组件和设置See Configure components and settings in an answer file for information on how to modify an answer file.

  1. 对于中的每个路径 Microsoft-Windows-PnpCustomizationsNonWinPE ,如果文件位于网络共享上,请指定设备驱动程序的路径以及用于访问该文件的凭据。For each path in Microsoft-Windows-PnpCustomizationsNonWinPE, specify the path to the device driver and the credentials that are used to access the file, if the file is on a network share.

备注

如果通过添加多个 PathAndCredentials 列表项来包含多个设备驱动程序路径,则必须递增每个路径的 值。When you include multiple device driver paths by adding multiple PathAndCredentials list items, you must increment the value of Key for each path. 例如,你可以添加两个单独的驱动程序路径,其中第一个路径的 值等于 1 ,第二个路径的 值等于 2For example, you can add two separate driver paths where the value of Key for the first path is equal to 1 and the value of Key for the second path is equal to 2.

  1. 保存答案文件并退出 Windows SIM。Save the answer file and exit Windows SIM. 答案文件必须类似于以下示例。The answer file must resemble the following sample.
<?xml version="1.0" ?><unattend xmlns="urn:schemas-microsoft-com:asm.v3" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<settings pass="offlineServicing">
<component name="Microsoft-Windows-PnpCustomizationsNonWinPE" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<DriverPaths>
<PathAndCredentials wcm:keyValue="1">
<Path>\\networkshare\share\drivers</Path>
<Credentials>
<Domain>Fabrikam</Domain>
<Username>MyUserName</Username>
<Password>MyPassword</Password>
</Credentials>
</PathAndCredentials>
</DriverPaths>
</component>
</settings>
</unattend>
  1. 使用 DISM 装载要安装驱动程序的 Windows 映像:Mount the Windows image that you intend to install the drivers to by using DISM:
Dism /Mount-Image /ImageFile:C:\test\images\install.wim /Index:1 /MountDir:C:\test\offline

如果使用的是 VHD 或 FFU,请指定 /Index:1If you're working with a VHD or FFU, specify /Index:1.

  1. 将答案文件应用到已装载的 Windows 映像:Apply the answer file to the mounted Windows image:
DISM /Image:C:\test\offline /Apply-Unattend:C:\test\answerfiles\myunattend.xml

有关如何应用答案文件的详细信息,请参阅 DISM 无人参与服务 Command-Line 选项For more information about how to apply an answer file, see DISM Unattended Servicing Command-Line Options.

将在答案文件的路径中参考的 .inf 文件添加到 Windows 映像。The .inf files referenced in the path in the answer file are added to the Windows image.

  1. 检查是否已添加驱动程序。Check to see if the driver was added. 添加到 Windows 映像的驱动程序名为 "Oem" * 。Drivers added to the Windows image are named Oem*.inf. 这可确保新添加的驱动程序具有唯一的命名。This guarantees unique naming for newly added drivers. 例如,文件 MyDriver1.inf 和 MyDriver2.inf 会被重命名为 Oem0.inf 和 Oem1.inf。For example, the files MyDriver1.inf and MyDriver2.inf are renamed Oem0.inf and Oem1.inf.

例如,键入:For example, type:

Dism /Image:C:\test\offline /Get-Drivers
  1. 卸载 .wim 文件并提交更改。Unmount the .wim file and commit the changes. 例如,键入:For example, type:
Dism /Unmount-Image /MountDir:C:\test\offline /Commit

如果需要 WinPE 驱动程序查看本地硬盘驱动器或网络,则必须使用应答文件的 windowsPE 配置阶段将驱动程序添加到 winpe 驱动程序存储,并反映 winpe 所需的启动关键驱动程序。If you need drivers for WinPE to see the local hard disk drive or a network, you must use the windowsPE configuration pass of an answer file to add drivers to the WinPE driver store and to reflect boot-critical drivers required by WinPE. 有关详细信息,请参阅 在 Windows 安装程序期间将设备驱动程序添加到 WindowsFor more information, see Add Device Drivers to Windows During Windows Setup.

相关主题Related topics

设备驱动程序和部署概述Device Drivers and Deployment Overview

在 Windows 安装程序期间将设备驱动程序添加到 WindowsAdd Device Drivers to Windows During Windows Setup

DISM - Windows 的部署映像服务和管理技术参考DISM - Deployment Image Servicing and Management Technical Reference for Windows