Use WIM to create archived installers

Recently, I’ve came across Aaron’s response to a tweet regarding large packages like Autodesk, Adobe. Visual Studio, and it brought up some memories.

I haven’t used this in a long while, since i haven’t dealt with large packages for some time.

 

What is the issue?

The issue is simple, large packages are a nightmare to deal with in an infrastructure for large organizations who have distribution points all over the world.

When you distribute a package on all the distribution points, network issues will occur, trust me. By default, each distribution point retries to download the sources in case they fail. There is also a possibility that the package is downloaded, but at the end the hash will fail. Why? Some bits were lost, thus leading to countless retries.

You can tackle this problem in multiple ways:

  1. Create a zip file and extract it before the installation
  2. Create a self-extracting .exe file with 7-zip
  3. Create a self-installing .exe with 7-zip
  4. Create a bundle/exe with Advanced Installer

 

As you can see, the most common answer you can find is “create an archive” to save up space. But here comes another issue.

Every type of archive you make, has the downside that you must first extract it before you start the installation. If the user downloads a 20 GB ZIP file (or self-extracting .exe done with 7-zip), it means that he must have enough disk space for:

  1. The 20 GB archive
  2. The 20+ GB of extracted files from the archive
  3. The 20+ GB of installed files on the machine

So for 20 GB of installation, the user must have over 60GB of free disk space, which is outrageous.

 

What is the solution?

As Aaron reminded me, you could use WIM files to tackle all the problems. WIM files are technically Windows Image files, but that doesn’t mean they are limited to creation of Windows images, you can create whatever you want.

WIM files are basically zip files which compress the data to save space. One other benefit of WIM files is that they can be mounted, meaning that you don’t have to extract the archive to start the installation.

In this article, you will learn how to create a WIM file, mount the WIM file, install the package and unmount the WIM file.

As a note, i am using PowerShell cmdlets to achieve this, but this can also be done with DISM.

 

The code

Create WIM

Let’s assume that a folder “MSI Install” with all the source files is present in E:\.

The first step is to create the WIM file. To do this, the following code must be executed in PowerShell with administrator privileges:

New-WindowsImage -ImagePath “c:\custom.wim” -CapturePath “E:\MSI Install\” -Name “MSI Install”

This will create a WIM file called custom in C:\. The WIM file will contain all the files present in E:\MSI Install\

After the above code is executed, the custom.wim file can be found in C:\.

Mount and install

After the WIM has been created, is time to mount it and start the installation.

The WIM file will be mounted on a directory in C:\, in our example, C:\offline. The folder must be present on the machine prior to the mounting of the WIM file, so we must create it with PowerShell:

New-Item -ItemType Directory -Force -Path C:\offline

After that, the WIM file can be mounted with:

Mount-WindowsImage -ImagePath “c:\custom.wim” -Index 1 -Path “c:\offline”

Last, we must start the installation. In our case we are starting another PowerShell script:

Invoke-expression (start powershell (“C:\offline\install.ps1”))

If we navigate to C:\offline we can see that the WIM file contains the files from E:\MSI Install, and the best part is that it didn’t need to be extracted.

Dismount

After the installation is finished, the WIM file must be dismounted. To do this, the following code must be added to the script:

Dismount-WindowsImage -Path “c:\offline”

After the above code is executed, if we navigate to C:\offline we can see that is empty. Now it’s save to also be deleted:

Remove-Item ‘C:\offline’

 

Recap

And that is it. You can see how easy it is to create a WIM using powershell, and how easily you can attach it and install your large application. This is definitely an alternative way to keep in mind when you create archived installers.

The full code for the WIM creation is:

New-WindowsImage -ImagePath “c:\custom.wim” -CapturePath “E:\MSI Install\” -Name “MSI Install”

 

The full code for the installation script is:

New-Item -ItemType Directory -Force -Path C:\offline
Mount-WindowsImage -ImagePath “c:\custom.wim” -Index 1 -Path “c:\offline”
Invoke-expression (start powershell (“C:\offline\install.ps1”))
Dismount-WindowsImage -Path “c:\offline”
Remove-Item ‘C:\offline’

 

Note

As Aaron mentions in a further tweet, he found out that wimlib.net is a far faster method of creating WIM files, although personally i never used it. But if you really want to experiment with these kind of archives, i definitely would recommend to check wimlib.net as Aaron mentions.

 

I hope you enjoyed this tutorial.

Sharing is caring!

Leave a comment

Your email address will not be published. Required fields are marked *

11 − two =