.\Matthew Long

{An unsorted collection of thoughts}

Posts Tagged ‘WIM’

Cleaning up Windows 7 / Server 2008 R2 Service pack 1 Files

Posted by Matthew on March 4, 2011

I’ve recently been updating various computers, wim images and virtual machines with NT 6.1 Sp1 (Windows 7 and Server 2008 R2).  As many people may have noticed before, this once again means you can expect a large jump in the size of your Side-By-Side repository (the C:\Windows\Winsxs).  Unlike with Vista and Server 2008 SP1/SP2 there is no cleanup tool provided with the service pack.  This is because DiskCleanup / DISM are already provided for you to do this.

So what does this involve?  Removing the service pack backup files will essentially remove all of the superseded files and libraries that the service pack updated, at the cost of now being unable to remove the service pack (as you cannot roll back to the superseded versions).  The amount of space you will recover can vary but is usually between 1-2gb.  That isn’t a lot for end-user machines, but that can be huge when you are looking at machine images and virtual environments.  Obviously you should thoroughly test your machines / images before committing to such an endeavour. 

There are essentially two ways to complete this process.  If you have access to the Disk Cleanup tool (Windows 7 or Windows Server 2008 R2 with the desktop experience pack installed) you can run that, click on the “Cleanup System Files” button (requires user elevation) and when the tool re-opens select “Service Pack Backup Files”.

If you don’t have Disk Cleanup installed, or are working with an offline WIM image, you are going to need to use DISM.

  1. Start an elevated command or Powershell prompt (Run as Administrator)
  2. If you are servicing this machine, enter dism /online /cleanup-image /spsuperseded /hidesp to cleanup the online computer.  If you want to cleanup an offline wim image, instead enter dism /image:wimfile.wim /Cleanup-Image / spsuperseded /hidesp.  The /hidesp option will remove SP1 from the “Installed Updates” section of Programs and Features, to ensure that users do not try to uninstall the service pack.  
  3. DISM will now remove backup files and superseded components from your machine.  When finished, you should have the below output :
dism /Cleanup-Image /spsuperseded /hidesp results
dism /Cleanup-Image /spsuperseded /hidesp results

And that’s it, your done!


Posted in Computing | Tagged: , , , | 2 Comments »

Edit the registry contained in a Wim File

Posted by Matthew on January 13, 2011

I’ve been asked recently to document how you can change registry hives contained within a WIM file.  This could be used either to make changes to a user account (such as the registry of the default user) or to edit the system registry settings.

The basic process for this is actually very simple, all we need to do is mount our WIM file.  Once mounted, we can use the reg command to load the hive into the live system’s registry, and make the required changes. Finally, we need to unload the registry hive and then commit the changes back to the WIM.

Obviously access to DISM is a requirement for this operation.  This can be located in the Windows Automated installation Kit.

Note : If you want to know where I got the Software registry hive location from, you can find HKey_Local_Machine registry hives in the C:\Windows\System32\Config folder.  The hives are named as they appear in Regedit.

  • Open the Deployment Tools Command Prompt (Contained in the Microsoft Windows AIK folder on your start menu)
  • Mount your wim file, by entering the below command .  Substitute the filename, index and mount directory for your wim filename and image index.  The mount directory just needs to be an empty pre-existing directory.

dism /mount-wim /wimfile:C:\WimImages\Win7.wim /index:2 /mountdir:C:\AIKMount

  • Once DISM reports that the image has been mounted successfully, you need to mount the registry.  I’m going to mount the wim’s HKLM\Software hive in this example.  You’ll notice the root of my reg path below is the folder I mounted the WIM into, given in the previous command.  Type

reg load HKLM\WimRegistry c:\AIKMount\windows\system32\config\software

  • If you now open RegEdit you will now see under HKey_Local_Machine\WimRegistry your registry hive.  You are now free to make your required changes.
  • Once you are finished, exit Regedit.  We now need to unmount the registry hive, which can be accomplished by typing

reg unload HKLM\WimRegistry

  • Now we need to unmount your wim image and commit the changes back into the .wim file.  To do this, type in

dism /unmount-wim /mountdir:C:\AIKMount /commit

And once DISM has unmounted the image, you’re done!  If you decided not to keep the changes you made (or didn’t make any and were just poking around in the reg) you would use the /discard switch instead of /commit

Posted in Computing | Tagged: , , | 3 Comments »

Combining multiple images into a single wim

Posted by Matthew on December 23, 2010

One of the most useful features of WIM technology is the ability to stage multiple images within a single wim file and let the single instancing technology of the format save you an awful lot of space.  This can be important when you are trying to reduce the amount of duplicated space in an SCCM hierarchy.

I recently combined 6 legacy Windows XP thick images that were almost identical (differing HAL types & image architectures, for the most part) and managed to save 30GB of space on each site server in the environment.  Combined with the space saved on Distribution points this accounts for near 420GB across the environment!

The procedure is remarkably easy, but first a couple of tips to help you get the most out of this technique :

  1. Firstly, because the only way to shrink a wim file is to export all of the images out of it into a new file, take a copy of your WIMs before you start this process.  If you combine two images (or even worse, the last of many..) and find that the resulting file is too large to realistically image from, you won’t want to go through the “shrink” procedure to undo the last image appended.
  2. Try and combine images with the same OS Codebase into one wim.  While there is nothing to stop you placing XP and Windows 7 images in the same wim, there will be significant differences between the two and you won’t achieve much of a space saving unless your images are quite thick.
  3. Placing images that are around the same patch level will also help keep the wim file size low.  A year’s worth of Software updates can have a remarkable effect on the size of an image!
  4. If you store installation folders such as the i386 folder in your images, update the images so that they all have the same version.

Right, enough waffling, on with the guide!

1. Copy your wim files to a system with the Windows Automated Installation Kit installed and start the Deployment Tools Command prompt.
2. If you want to cleanup or update the images before combining them, use DISM to mount each wim and service it (using the below command).  Otherwise, skip to step 3.

DISM.exe /Mount-Wim /WimFile:<wimfile> /index:<imageindex> /MountDir:C:\test\offline

Once you’ve made your changes, run the below command to commit your changes and unmount your wim

DISM.exe /Unmount-Wim /MountDir:C:\test\offline /commit

3. Once you are ready to combine your images, pick one of your wim’s to be the base wim that the other images will be added to.  If you carried out changes in Step 2, you will generally want to pick the wim that had the least modifications.  This is because no data is actually ever removed from a wim file, only the metadata that associates the file with the image.  When we run the export command any deleted data is not exported and effectively a “clean” wim is generated.  As such you want to add heavily modified images to wims that have had very few / no changes, as this will keep your final wim’s size down to a minimum.  So, once you have decided, rename your base wim to something descriptive (WinXPCombined.wim, for example) and then run the below command

imagex /export d:\imaging\source.wim <imageindex> d:\imaging\WinXPCombined.wim “<ImageName>

The <ImageName> argument is a unique name for the image inside the wim file.  If you want to modify the name of the image that already existed inside the wim, you can Use Imagex’s /info option to change it :

imagex /info d:\imaging\WinXPCombined.wim <imageindex> “New Name”

4. Once the export is finished, and you are happy with wim’s size, repeat the above step until all of your images are in the wim!  You’ll note that the export function will only move data that isn’t already inside the wim, so the procedure can be extremely quick or rather lengthy..

Finally, I would recommend that you test your combined wim file and make sure that all of the images have been successfully exported and appended into the final wim before you delete your originals…

Posted in Computing | Tagged: , , , | Leave a Comment »