Thursday, January 13, 2011

How to Combine WIM images

One of the neat features of Microsoft WIM format is Single Instancing and the ability to hold more than 1 image in a single WIM file.  In Single Instancing, you only need to have one copy of a file for multiple images.  Let’s say I have 3 Windows 7 images.  Each one has 3 different configurations.  They all have windows in common.  Why keep a single copy of Notepad.exe?  The first image will contain every file that it needs.  Each additional image will contain a reference to identical files in the first image. Anything the previous images do not have will be contained in the image.  This will greatly reduce your image storage requirements.

This blog article looks at combining two separate images into one.  For this example, I have two images.  One called Lab1.wim, which is my base image for a Windows Server 2008 R2. The second is the setup for course 10215 called Lab1-10215.wim.  The base image is 2.90 GB and the class setup is 64.6 GB.  OK, we will not see much of a space savings here but you will get the idea.

We are going to apply the smaller image to the larger one to save some time.
To do this we need to mount one of the images.  First create an empty folder to mount the image in.  For my example, I am going to use a folder called MountedWim on the M: drive.

Open a command prompt with administrative rights.

We will mount the image using Deployment Image Servicing and Management command line tool.
DISM /mount-wim /wimfile:M:\lab1.wim /name:”Basic Image” /mountre:M:\Mount


Now that we have mounted the image, we can append it to the larger image. I copied the ImageX program from the Windows Automated Installation Kit to my M: drive.  If you have images to work with, you more than like already have a copy of ImageX.

Imagex /append m:\Mount m:\Lab1-10215.wim “Lab1 Images”


The imaging process will begin.
image
Once the process is completed, type ImageX /info Image_file_name. You will see the XML file for the WIM file.  It now will show two image indexes (In green below)

ImageX Tool for Windows
Copyright (C) Microsoft Corp. All rights reserved.

WIM Information:
----------------
GUID:        {52583ec7-4f82-4810-84a6-c91532d045a9}
Image Count: 2
Compression: LZX
Part Number: 1/1
Attributes:  0x8
             Relative path junction

Available Image Choices:
------------------------
<WIM>
  <TOTALBYTES>69394622319</TOTALBYTES>
  <IMAGE INDEX="1">
    <NAME>10215 Setup</NAME>
    <WINDOWS>
      <ARCH>9</ARCH>
      <PRODUCTNAME>Microsoft« Windows« Operating System</PRODUCTNAME>
      <HAL>acpiapic</HAL>
      <PRODUCTTYPE>ServerNT</PRODUCTTYPE>
      <PRODUCTSUITE>Enterprise</PRODUCTSUITE>
      <LANGUAGES>
        <LANGUAGE>en-US</LANGUAGE>
        <DEFAULT>en-US</DEFAULT>
      </LANGUAGES>
      <VERSION>
        <MAJOR>6</MAJOR>
        <MINOR>1</MINOR>
        <BUILD>7600</BUILD>
        <SPBUILD>16385</SPBUILD>
      </VERSION>
      <SYSTEMROOT>WINDOWS</SYSTEMROOT>
    </WINDOWS>
    <DIRCOUNT>14732</DIRCOUNT>
    <FILECOUNT>65989</FILECOUNT>
    <TOTALBYTES>188740921939</TOTALBYTES>
    <CREATIONTIME>
      <HIGHPART>0x01CBABBE</HIGHPART>
      <LOWPART>0x26D4A429</LOWPART>
    </CREATIONTIME>
    <LASTMODIFICATIONTIME>
      <HIGHPART>0x01CBABBE</HIGHPART>
      <LOWPART>0x2709027F</LOWPART>
    </LASTMODIFICATIONTIME>
  </IMAGE>
  <IMAGE INDEX="2">
    <NAME>Lab1 Images</NAME>
    <WINDOWS>
      <ARCH>9</ARCH>
      <PRODUCTNAME>Microsoft« Windows« Operating System</PRODUCTNAME>
      <HAL>acpiapic</HAL>
      <PRODUCTTYPE>ServerNT</PRODUCTTYPE>
      <PRODUCTSUITE>Enterprise</PRODUCTSUITE>
      <LANGUAGES>
        <LANGUAGE>en-US</LANGUAGE>
        <DEFAULT>en-US</DEFAULT>
      </LANGUAGES>
      <VERSION>
        <MAJOR>6</MAJOR>
        <MINOR>1</MINOR>
        <BUILD>7600</BUILD>
        <SPBUILD>16385</SPBUILD>
      </VERSION>
      <SYSTEMROOT>WINDOWS</SYSTEMROOT>
    </WINDOWS>
    <DIRCOUNT>14472</DIRCOUNT>
    <FILECOUNT>64628</FILECOUNT>
    <TOTALBYTES>11788310784</TOTALBYTES>
    <CREATIONTIME>
      <HIGHPART>0x01CBAC92</HIGHPART>
      <LOWPART>0xB243BD59</LOWPART>
    </CREATIONTIME>
    <LASTMODIFICATIONTIME>
      <HIGHPART>0x01CBAC92</HIGHPART>
      <LOWPART>0xB366183B</LOWPART>
    </LASTMODIFICATIONTIME>
  </IMAGE>
</WIM>

Now, let’s look at the file sizes. The original WIM file sizes is 2.90 GB and 64.4 GB.  A file combination of those two files without Single Instancing is 67.3 GB.  The new, combined WIM file is 64.6 GB.  Only a .2 GB increase in files size.  Again, this is a very basic demo but it goes to show the hard drive savings that storing more than one image in the same WIM file can bring to your storage system.
Do not forget to unmount the wim file.

dism /unmount-wim /mountdir:m:\Mount /commit

6 comments:

Dustin said...

Your unmount command won't save the new WIM file with the changes. You need to use /commit instead of /discard.

Jason Yoder, MCT said...

Thanks Dustin. I made the correction.

Martin B said...

I don't think you need to commit as you are saving any changes to the lab1.wim.

Probably best to discard to make sure that it is unchanged.

Jason Yoder, MCT said...

Martin, Thank you. You are correct.

Taylor said...

- DISM /mount-wim /wimfile:M:\lab1.wim /name:”Basic Image” /mountre:M:\Mount
+ DISM /mount-wim /wimfile:M:\lab1.wim /name:”Basic Image” /mountdir:M:\Mount

Taylor said...

- DISM /mount-wim /wimfile:M:\lab1.wim /name:”Basic Image” /mountre:M:\Mount
+ DISM /mount-wim /wimfile:M:\lab1.wim /name:”Basic Image” /mountdir:M:\Mount