Capturing a Windows System Using WIM

If you’ve ever found yourself in a situation where you needed to capture your Windows system (7/8/10/11) in various stages, whether for backup purposes or to make a default image that you want to replicate to other systems, then this how-to may be for you.

I recently needed to create an image of an existing Windows 10 system that was initially installed in BIOS (Legacy) mode, while the new system required UEFI. Although there are ways to convert the system (some easier than others), I eventually succeeded in applying the image after converting it to GPT and creating an EFI partition. However, this process involved more steps than I preferred. Additionally, I had to deal with moving the EFI partition around since the image originated from a 128GB SSD and was being transferred to a new 500GB NVMe drive. I wanted to utilize all the available space!

Enter my son, Tyler Adkisson. He is well-versed in using WIM capture for backing up running systems and previously employed a method to "install" an image of a system exactly as needed on each new PC. One of the benefits of this method is that it doesn't matter if the original image was on a BIOS/Legacy installed system when installing on a new UEFI system. Additionally, the installer doesn’t care if the new drive is larger when the image was initially on a different-sized installation drive. It made everything just work seamlessly.

To help me out, Tyler created a script using wimlib-imagex (with a fallback to DISM) along with some instructions on how to create an install for a system I had already imaged to a VHDX using Microsoft’s Disk2VHD tool. Below is the readme.txt file he created for me to follow. You can download the zipped folder of the tools. Just unzip them somewhere you can easily access them in an administrative command prompt.

README.txt

# WIM system capture script #

This script automates capturing a system image and building an "installer" that can be run on

another system to re-install the captured image. This **does not** make a bootable USB or

anything; if you want a bootable USB, use a tool like Rufus with a Windows installation ISO

first, then replace the files with the ones this script creates.

# How do I use this? #

You will need:

- A Windows 10/11 installation disc or ISO (technically 7/8 may work as well, but currently untested)

- A source system disk or VHD/VHDX

- A storage device with enough room to store the compressed image of the source system disk

- A bootable Windows 10/11 installation USB of any size (A DVD copy will also work in a pinch)

With those at hand, prepare:

1. Insert the Windows 10/11 installation disc or mount the ISO. Make a note of the drive letter (e.g. D:\)

2. Attach the source system disk or mount the VHD/VHDX. Make a note of the Windows partition drive letter (e.g. E:\)

3. Make sure the destination storage device is connected. Make a note of its drive letter (e.g. F:\)

Now that you're prepared, run the capture script. You can use the following example:

capture.bat D:\ E:\ F:\captures

The script will begin and preform all actions to prepare an "installable" system image of the

source system (E:\) using the installation media (D:\) and place it all into the destination

folder (F:\captures). The resulting folder structure will look like the following:

- F:\captures

- README.txt

- sources\

- ...regular installer files...

- install.wim <-- Your system image(s) are in here

The README.txt contains instructions for how to "install" the image on a system.

The install.wim file can be moved and/or replaced to allow the installer to "install" different

sets of images if you didn't image several systems into the same WIM file (you can do this,

see the notes section below).

# Notes #

## BIOS/CSM vs UEFI (and MBR vs GPT) ##

System images generally do not care what boot method was used on the original system, nor do

they care which method is used on the target system. The Windows installer will choose the

proper combination of disk format and bootloader type (MBR for BIOS/CSM or GPT for UEFI)

based on the system you're installing on. This works exactly like a fresh installation does.

If you wish to convert a system from BIOS to UEFI (or vice versa), you can take an image of

the system, switch the boot mode, then "re-install" the system image to restore Windows back

to the way it was, just using the changed boot mode and partition table.

## Imaging a running system ##

This can be done only using wimlib-imagex; DISM does not have snapshotting functionality.

If you must image a running system, the capture script must be modified to add the

--snapshot flag to the end of the wimlib-imagex command to tell it to create a VSS snapshot

before capturing. Keep in mind that while imaging a running system is possible, it may

result in some files being inconsistent after re-installing the image. Many database

systems have VSS providers so that they can sync data to the disk during snapshotting.

Other software may not handle it as gracefully.

## Multiple partitions ##

WIM files do not handle multiple partitions like a disk image (VHDX) does. A WIM file operates

at the file level so it is unaware of any partition structure. If you're attempting to make

an image of a multi-partition disk, you will need to capture both partitions separately, then

manually re-create the partition layout in the installer. Secondary partitions will need to

be restored ("applied") separately after Windows has been re-installed.

## Multiple system images in the same install.wim ##

You can capture multiple system images into the same install.wim file! This can be useful if

you're taking snapshots of a system over time for backups, or if you have multiple similar

systems and wish to save space compared to storing multiple VHDX files.

Any files that are identical between multiple system images will be deduplicated and stored

only once inside the WIM file, allowing for great space saving potential when storing multiple

systems that are running the same OS version.

If you store multiple system images into the same install.wim file, the installer will show

the edition selection screen just like when using a multi-edition Windows installation USB.

The difference here is that instead of selecting the Windows edition, you select the system

image to "install".

## Windows version compatibility ##

The Windows installer is backwards compatible and able to install older versions of Windows.

Older installers may not be fully able to install a newer version of Windows, especially if

the WIM file contains new metadata or compression methods that the older installer can't

handle. It's best practice to use the newest Windows installer ISO for building the

system image installers.

For booting a system, you can use an older install USB to run the newer installer generated

by this script. That will work just fine as long as they're the same architecture.

## Wimlib-imagex ##

This script prefers using wimlib-imagex, but can use DISM if wimlib-imagex is not present. The

experience is degraded a little bit when using DISM: the resulting image names in the edition

selection screen in the installer will just list the OS version and not the system name and date.

## Over the network ##

In place of an external disk to store the system image installer, you can also store the files

on a network share, then run it over the network on the target system. To do this, you must

first enable networking inside of the Windows installer, if it has a driver for your network

interface. Once booted, press Shift+F10 to open a command prompt, then enter:

wpeutil initializenetwork

This command will enable networking and fetch an IP address using DHCP if network drivers are

available. If drivers are not available, running ipconfig will show no network interfaces.

Once you're on the network, map a network drive using net use, but specify the username in the

command:

net use Z: \\yourservername\sharename /user:youruser *

This will locally prompt you for the password for that user, then attempt to make the connection.

It must be done this way because username/password negotiation doesn't always work in Windows PE

that the installer runs in.

## BitLocker ##

You can capture system images of BitLocker encrypted volumes. You must first unlock the volume

using the key or recovery password. Once unlocked, you can capture the image using the

instructions at the top of this document. Once re-installed, BitLocker will need to be

re-enabled.

NOTE: It is strongly recommended to disable bitlocker before imaging to reduce the risk of

conflicts or other strange issues.

Previous
Previous

Activating Windows on New PCs Before Reinstalling