In order to create custom operating system images, first set up a folder structure on the system to facilitate the process. This can be accomplished by following the steps outlined below:
- Open up the command prompt (or PowerShell) with administrator privileges.
- Navigate to the root of the
C:\
drive by entering the following command
cd c:\
- Create two folders; the first of which will act as a repository for the operating system install images (e.g., the
install.wim
file located in the sources folder of the target operating systems image file) and the second will act as the mount point for the images. This can be accomplished by entering the following commands in your terminal:
mkdir .\iso
mkdir .\mount
Now that a folder structure in place, begin the customization process by conducting an initial investigation of the Windows image file (install.wim
).
- Copy the
install.wim
to the.\iso
folder that was created in the previous step. This can be accomplished either manually via the File Explorer or through the command prompt by mounting (or extracting the contents of) the target operating systems image file (.iso
) to a folder that is accessible from the system, and entering in the following command:
copy .\exampleInstall.wim c:\iso
- Once the Windows image file (
install.wim
) has been copied to thec:\iso
directory, enter the following string in the command prompt to extract information (e.g., version index number, etc.) about the Windows image:
DISM /Get-ImageInfo /imagefile:"C:\iso\exampleInstall.wim"
If the previous command executed successfully, there should be a list of the various versions of Windows embedded in the Windows image file (install.wim
). Each version will be denoted by an index number that can be used to mount that specific edition.
- Identify the index number for the required edition of Windows and enter the following string in the command prompt: source
DISM /Mount-image /imagefile:"C:\iso\exampleInstall.wim" /Index:<targetEditionsIndexNumber> /MountDir:"C:\mount" /optimize
DISM is extremely powerful and can be used to prune unnecessary or superseded core components from the operating system image. Specifically, DISM can be leveraged to add or remove drivers, applications, packages, updates, language packs, features, and more. This is advantageous for a number of reasons, but in particular it reduces the size of the operating systems image file in addition to reducing the attack surface of the operating system image itself.
- To begin with, enter the following string in the command prompt to create a list of the Application Packages that have been included in the edition of Windows that you are working on:
DISM /Image:"C:\mount" /Get-ProvisionedAppxPackages /format:table > "C:\iso\appx.txt"
- Next, create a list of the operating systems inherent capabilities by entering the following string in the command prompt:
DISM /Image:"C:\mount" /Get-Capabilities /format:table > "C:\iso\capabilities.txt"
- As with the previous step, enter the following string in the command prompt to generate a list of the features that have been included in the operating system image:
DISM /Image:"C:\mount" /Get-Features /format:table > "c:\iso\features.txt"
- Last but not least, enter the following string into the command prompt to export a list of the packages that have been included in the operating system image:
DISM /Image:"C:\mount" /Get-Packages /format:table > "c:\iso\packages.txt"
Once the previous steps have been completed, there should be four new text files located in the "c:\iso" folder. These text files can be used to identify undesirable applications, features, packages, and capabilities that have been embedded in the edition of windows that is being worked on.
- Open the appx.txt file that was created in Step 4 and use the "PackageName", in conjunction with the following command, to remove the application from the operating system image file:
DISM /Image:"C:\mount" /Remove-ProvisionedAppxPackage /PackageName:<PackageName>
- Once the command executes successfully, repeat the process until all undesirable applications have been removed from the operating system image file.
- Open the capabilities.txt file that was created in Step 4 and use the "Capability Identity", in conjunction with the following command, to remove the capability from the Windows image file:
DISM /Image:"C:\mount" /Remove-Capability /CapabilityName:<Capability Identity>
- Once the command executes successfully, repeat the process until all unnecessary capabilities have been removed from the Windows image file.
- Open the features.txt file that was created in Step 4 and use the "Feature Name", in conjunction with the following command, to disable the feature present in the Windows image file:
DISM /Image:"C:\mount" /Disable-Feature /FeatureName:<Feature Name>
- Once the command executes successfully, repeat the process until all unnecessary features have been disabled on the Windows image file.
- Open the packages.txt file that was created in Step 4 and use the "Package Identity" of the package to be removed, in conjunction with the following command, to remove the package from the Windows image file:
DISM /Image:"C:\mount" /Remove-Package /PackageName:<Package Identity>
- Once the command executes successfully, repeat the process until all undesirable packages have been removed on the Windows image file.
At this point in the process, all that remains is to use DISM to reduce the footprint of the Windows image file by cleaning up superseded components, resetting the base of the superseeded components, and then exporting the image to a new image file.
- In the command prompt, enter the following command to cleanup the component base and optimize the Windows image file:
DISM /Image:"C:\mount\" /Cleanup-Image /StartComponentCleanup /ResetBase
- Next, enter the following string in the command prompt to commit all of the changes that were made in the previous steps and unmount the Windows image file:
DISM /Unmount-Image /MountDir:"C:\mount\" /Commit
- Upon successful execution of the previous command (e.g., the Windows image file was successfully unmounted), enter the following string in the command prompt to export the modified edition of Windows to its own Windows image file:
DISM /Export-Image /SourceImageFile:"C:\iso\exampleInstall.wim" /Index:<targetEditionsIndexNumber> /DestinationImageFile:"C:\iso\modifiedInstall.wim"