If you make regular changes to your WIM files with the use of the /MOUNTRW or /DELETE switches of IMAGEX, then you may have noticed that your WIM files do not shrink in size after you commit the changes back to the file. You could delete 500mb of data from an image file, only to see the file stay the same size, or even grow by a few megabytes. The reason for this is that the data in a WIM file are not actually removed from the file when deleted, rather the references to it’s contents are simply removed; this is a bit like how deleting a file from your C: drive only deletes the reference to it in the allocation table rather than actually scrubbing all the files binary 1’s and 0’s from the disk sectors.
But don’t worry, there is a solution to this which you can use to optimise the size of your WIM files! With the use of the /EXPORT switch of IMAGEX, you simply export the image from the WIM file into a new one, and you can even change the level of compression used. An example of the use of the command is:
ImageX.exe /export existing.wim X new.wim "My optimised WIM file" (where X is the number of the image file you want to export)
If you make regular manual edits to your existing WIM files then you might want to consider including the process of exporting the WIM to a new one into your work routine. However, it is probably not worth using export if you make infrequent or one off changes. One important thing to remember when using the export command is not to lose any of the /FLAGS settings during your export!
The question that clients always ask me about this subject is: why has Microsoft designed IMAGEX like this? The answer is logical, if not always obvious though at first glance. So, why does IMAGEX not optimise the file upon every commit action? Well, for a start, it would be very inefficient to have to do this each time you change the WIM file. Imagine that you add a 10kb file to a 12Gb WIM, then commit the changes. You’d have to wait while IMAGEX streams the 12Gb of data into a new WIM file, which would take a very long time.
Finally, I would not consider it good practice manually editing your WIM files on a regular basis. It would be better to use MDT to include any changes you need to make by incorporating them in future versions of your image files. Infrequent manual changes are fine, but if you are regularly having to manually edit your WIM files in order to include new files/registry keys etc. then you should be looking at automating this process in order to reduce this required manual administration. It will make work easier!
This post was contributed by Daniel Oxley a consultant with Microsoft Services Spain