使用 DISM 修改 Windows 映像Modify a Windows image using DISM

可对脱机装载或应用的 Windows 映像进行更改,而无需启动进入要修改的操作系统。You can make changes to offline mounted or applied Windows images without booting into the operating system you're going to modify.

装载的 映像是其内容已映射到某个文件夹的 WIM、VHD 或 FFU 文件。Mounted images are WIM, VHD, or FFU files that have their contents mapped to a folder. 可以通过 Windows 10 技术人员电脑或 WinPE 对装载的映像进行更改。Changes to mounted images are made from either a Windows 10 technician PC, or from WinPE. 可以针对装载的映像运行 DISM 命令,并对其运行常见的文件操作,例如复制、粘贴和重命名。You run run DISM commands against a mounted image, as well as run common file operations such as copying, pasting, and renaming on a mounted image. 若要保存对映像所做的更改,请在使用 DISM 卸载映像时使用 /commit 选项。To save changes you make to the image, use the /commit option when you use DISM to unmount the image. 若要更改装载的映像,请使用 DISM /image:To make changes to a mounted image, use DISM /image:.

应用的 映像是已应用到指定分区的 WIM、VHD 或 FFU 映像文件。Applied images are WIM, VHD, or FFU image files that have been applied to a specified partition. 对应用的映像进行脱机更改通常是通过 WinPE 执行的。Offline changes to an applied image are usually performed from WinPE. 若要更改应用的映像,请使用 DISM /image:To make changes to an applied image, use DISM /image:.

重要

应用某个要重新捕获的映像时,请将该映像应用到驱动器的根文件夹。When you apply an image that you're going to recapture, apply the image to the root folder of a drive. 如果重新捕获某个未应用到驱动器根目录的映像,该映像将继承父文件夹的安全描述符;如果该映像已应用到驱动器的根目录,该映像可能与捕获的映像不同。If you recapture an image that wasn't applied to the root of a drive, the image will inherit the parent folder's security descriptors and might not be the same as what would be captured if the image was applied to the root of a drive. 请参阅应用映像了解如何应用映像。See Applying an image to learn how to apply an image.

可以在一台计算机上装载和修改多个映像。You can mount and modify multiple images on a single computer. 有关详细信息,请参阅部署映像服务和管理 (DISM) 最佳做法For more information, see Deployment Image Servicing and Management (DISM) Best Practices.

脱机修改映像:从映像文件(.wim 或 .ffu 格式)开始。

装载映像Mount an image

可以使用 /optimize 选项装载映像,以减少初始装载时间。You can mount an image using the /optimize option to reduce initial mount time. 但是,在使用 /optimize 选项时,通常在装载期间执行的进程将改为在你首次访问目录时完成。However, When using the /optimize option, processes that are ordinarily performed during a mount will instead be completed the first time that you access a directory. 因此,在使用 /optimize 选项装载映像后,首次访问目录所需的时间可能会增加。As a result, there may be an increase in the time that is required to access a directory for the first time after mounting an image using the /optimize option.

  1. 使用管理员特权打开命令提示符。Open a command prompt with administrator privileges.

    备注

    如果使用的 Windows 版本不是 Windows 8 或 Windows 10,请使用与 ADK 一起安装的部署工具命令提示。If you are using a version of Windows other than Windows 8 or Windows 10, use the Deployment Tools Command Prompt that gets installed with the ADK.

  2. 使用 DISM 装载映像Use DISM to mount the image

    DISM /Mount-image /imagefile:<path_to_Image_file> {/Index:<image_index> | /Name:<image_name>} /MountDir:<target_mount_directory> [/readonly] /[optimize]}
    

    备注

    若要从 VHD 或 FFU 文件装载 Windows 映像,必须指定 /index:1To mount a Windows image from a VHD or FFU file, you must specify /index:1.

    有关 DISM 中 /Mount-Image 选项的可用选项的详细信息,请参阅 DISM 映像管理命令行选项For more information about the options available for the /Mount-Image option in DISM, see DISM Image Management Command-Line Options.

修改映像Modify an image

装载映像后,可以使用 DISM 添加和删除驱动程序、包、语言包,枚举驱动程序和包,修改配置设置,等等。After you mount an image, you can use DISM to add and remove drivers, packages, language packs, enumerate drivers and packages, modify configuration settings, and more.

查看和修改映像View and modify an image

可以在装载的映像中创建、查看和编辑文件,就像在电脑上对任何其他文件执行这些操作一样。You can create, view, and edit files on a mounted image, just as you would any other file on your PC. 修改装载的映像中的文件时,这些文件更改将保存在该映像中。When you modify the files in a mounted image, those file changes get saved in the image. 请注意,尽管可以添加应用程序文件和文件夹,但无法像在运行中的电脑上那样,将应用程序直接安装到装载的映像中。Note that although you can add application files and folders, you can't install applications directly into a mounted image in the same way that you would on a running PC. 如果必须添加应用程序或设备,请验证是否包含了所有必需文件。If you must add an application or a device, verify that you included all of the required files.

添加和删除驱动程序Add and remove drivers

请参阅在脱机 Windows 映像中添加和删除驱动程序了解如何处理驱动程序。See Add and remove drivers to an offline Windows image to learn how to work with drivers. 请注意,DISM 驱动程序命令只能针对脱机映像运行。Note that the DISM driver commands will only run against an offline image.

添加和删除包Add and remove packages

请参阅使用 DISM 脱机添加或删除包了解如何处理包。See Add or remove packages offline using DISM to learn how to work with packages.

添加或删除语言Add or remove languages

请参阅使用 DISM 脱机添加和删除语言包了解如何处理语言。See Add and remove language packs offline using DISM to learn how to work with languages.

升级到更高的 Windows 版本Upgrade to a higher Windows edition

对装载的映像所做的任何更改也会应用到每个潜在的 Windows 目标版本。Any changes you make to a mounted image are also applied to each potential target edition of Windows. 每个目标版本暂存在映像中。Each target edition is staged in the image. 升级到更高的 Windows 版本时,所做的更改不会丢失。The changes will not be lost when you upgrade to a higher edition of Windows.

请参阅使用 DISM 将 Windows 映像更改为更高版本了解如何更改版本。See Change the Windows image to a higher edition using DISM to learn how to change editions.

减小映像大小Reduce the size of an image

可以使用 DISM,通过清理已被取代的组件并重置已被取代的组件的基目录来减小 Windows 映像的占用空间。You can use DISM to reduce the footprint of a Windows image by cleaning up superseded components and resetting the base of the superseeded components.

  • 在权限提升的命令提示符下,运行以下命令减小映像文件的大小:At an elevated command prompt, run the following command to reduce the size of the image file:

    Dism /Image:C:\test\offline /cleanup-image /StartComponentCleanup /ResetBase 
    

提交对映像的更改Commit changes to an image

无需卸载映像,即可提交对映像的更改。You can commit changes to an image without unmounting the image.

  • 在管理员命令提示符下,键入:At the administrator command prompt, type:

    Dism /Commit-Image /MountDir:C:\test\offline
    

    提交对映像的更改时,请使用 /CheckIntegrity 来检测和跟踪 .wim 文件损坏情况。Use /CheckIntegrity to detect and track .wim file corruption when you commit changes to the image. 应用或装载映像时,请再次使用 /CheckIntegrity,以便在检测到文件损坏时停止操作。When you apply or mount the image, use /CheckIntegrity again to stop the operation if file corruption was detected. 不能对虚拟硬盘 (VHD) 文件使用 /CheckIntegrity/CheckIntegrity cannot be used with virtual hard disk (VHD) files.

卸载映像Unmounting an image

修改装载的映像后,必须将其卸载。After you modify a mounted image, you must unmount it. 如果使用默认的读/写权限装载了映像,则可以提交更改。If you mounted your image with the default read/write permissions, you can commit your changes. 这样,所做的修改就会在映像中永久保留。This makes your modifications a permanent part of the image.

如果修改了某个应用的映像,则无需执行任何其他操作。If you modified an applied image, you don't have to do anything else. 启动电脑时将会看到所做的任何更改。You'll see any changes you made when you boot the PC.

  1. 使用管理员特权打开命令提示符或“部署和映像工具环境”。Open a command prompt or the Deployment and Imaging Tools Environment with administrator privileges.

  2. 卸载映像。Unmount the image.

    Dism /Unmount-image /MountDir:<target_mount_directory> {/Commit | /Discard}
    

    其中 C:\test\offline 是装载目录的位置。where C:\test\offline is the location of the mount directory. 如果未指定卸载参数,则此选项将列出所有装载的映像,但不会执行卸载操作。If you do not specify the parameters to unmount, this option lists all of the mounted images but does not perform the unmount action.

    重要

    使用 /unmount 选项时,必须使用 /commit/discard 参数。You must use either the /commit or /discard argument when you use the /unmount option.

疑难解答Troubleshooting

请参阅修复 Windows 映像See Repair a Windows Image.

如果本主题中的 DISM 命令失败,请尝试以下做法:If the DISM commands in this topic fail, try the following:

  1. 确保使用随 Windows ADK 一起安装的 Windows 10 版 DISM。Make sure that you are using the Windows 10 version of DISM that is installed with the Windows ADK.

  2. 不要将映像装载到受保护的文件夹,例如 User\Documents 文件夹。Don’t mount images to protected folders, such as your User\Documents folder.

  3. 如果 DISM 进程中断,请考虑暂时断开网络连接并禁用病毒防护。If DISM processes are interrupted, consider temporarily disconnecting from the network and disabling virus protection.

  4. 如果 DISM 进程中断,请考虑改为从 Windows 预安装环境 (WinPE) 运行命令。If DISM processes are interrupted, consider running the commands from the Windows Preinstallation Environment (WinPE) instead.

相关主题Related topics

DISM 映像管理命令行选项DISM Image Management Command-Line Options

使用 DISM 为 Windows 映像提供服务Service a Windows Image Using DISM