A few months back, I wrote a post on how to reduce the size of the WinSxS directory and free up disk space on Windows Server 2012.
As a recap, the WinSxS directory is a large consumer of disk space on Windows Clients and Servers. Over time, the WinSxS directory steadily increases in size.
So why is this?
One cause of this is Windows Updates. To allow the ability to uninstall an update, all the previously installed versions of Windows Updates are kept in WinSxS directory even when they become superseded by an update released in future. This accounts for Windows updates taking a lot of space and it continues to grow significantly as more and more updates are installed.
So how do we cleanup the WinSxS directory? Well, with each service pack released, we also give the option of performing a cleanup that removes all previous versions of the files updated by the service pack. However, service pack 1 released well over 2 years ago, and there has not been another service pack since. Think about all those files updated by security updates and hotfixes? Up until today, we have not had the ability to cleanup these files.
But that all changes TODAY.
This morning, a new recommended update was released. It can be found here.
This update back ports some of the same functionality built into Windows 8 and later. It gives us the ability to cleanup previous versions of the files superseded by Windows updates.
Note: This is categorized as an “important” update. What does this mean for you? This means it’s not a critical security update which means it may not be automatically installed or deployed depending on your Windows Update settings, WSUS settings, or other 3rd party patch management software settings.
So what does this process look like?
After you install the update, click on Start, Search, type Disk Cleanup, and then right-click on Disk Cleanup and run it as Administrator.
First, you are prompted to select the drive you want to clean up. This is only valid for the operating system drive. So select C:\.
Disk Cleanup scans and calculates how much space you will be able to free on that drive:
If you didn’t launch Disk Cleanup as Administrator, at this point, you’ll need to take a couple extra steps. You’ll need to click on the Clean up system files button.
At that point, Disk Cleanup will relaunch as Administrator and you’ll need to repeat the first two steps again. So save yourself a couple extra clicks and launch Disk Cleanup as Administrator to begin with.
If you scroll through the files to delete, you’ll see the new option added by this update along with the amount of space you can save. It’s called Windows Update Cleanup. Notice it is checked by default?
Note: If nothing is found for Windows Update Cleanup to perform, it will not show up as an option.
Important note: After performing this cleanup, you may not be able to uninstall any of the updates currently applied. However, if you need to rollback to a previous version, you can still manually apply the previous version of the update.
If you highlight Windows Update Cleanup, you’re presented with the following details
“Windows keeps copies of installed updates from Windows Update, even after installing newer version of updates. Windows Update cleanup deletes older versions of updates that are no longer needed and taking up space. (You might need to restart your computer).”
When you click ok, Disk Cleanup runs and cleans up the unnecessary files on your machine. You can see it running the Windows Update Cleanup as part of this below:
Disk Cleanup finishes and exits.
In my experience with testing this update, we’re not prompted to reboot. However, when you next reboot, you’ll see Windows configuring Windows updates on shutdown and Cleaning up on startup.
The cleanup does take a few minutes so don’t be alarmed if it sits here for a minute or two. The larger the cleanup, the longer it will take. But even on my machine with 1.78GB of files to cleanup, it still ran in under 5 minutes.
The amount of space you will save will vary by machine, but here’s a screen shot from another example:
I know running around and running Disk Cleanup on 10,000 clients isn’t anyone’s idea of a good time. So how do we automate this?
Well, it’s a little cumbersome, but not too bad. It does take a bit of legwork first. It requires the export of a registry, and import of that registry on the clients. We can then use cleanmgr.exe (the command line version of Disk Cleanup) to automate Windows Update cleanup.
First a little background. Under the following registry key, we have a list of all the available disk cleanup plugins for Disk Cleanup:
Here’s an example of what this registry key looks like on my Windows 7 SP1 client:
Inside each one of these plugins, there’s a value called StateFlags. This is traditionally set to a value of 0 or 1. If it’s 1, it’s automatically checked when you run Disk Cleanup the next time. Here’s what it looks like for the Update Cleanup plugin on my Windows 7 SP1 client machine:
In order to automate Disk Cleanup using cleanmgr.exe, we need to push a new StateFlags registry value to the plugins we want to automate. So how do we do this?
Open an administrative command prompt and run the following command:
11 can be any random number you choose between 0 and 65535.
It will then look just like running Disk Cleanup. It will prompt you for the drive, present you with the options just like we did before. When it’s complete, if you go back and look at these plugins in the registry, you’ll notice the ones you had checked now have a new StateFlags value that corresponds to the number you specified with sageset. As an example here’s that same plugin now:
It’s important to note that running sageset does not perform the cleanup. It simply updates the settings for that set. The cleanup isn’t performed until you run the sage run command shown later in this post.
Now that you have this set, you can export this StateFlags registry key for each of the plugins you wish to automate and import it on your other Windows 7 SP1 clients. Just make sure you export the StateFlags registry key that was newly added by the sageset command. This will be the one that has the number you chose appended to the end. In my screen shot above, that would be StateFlags0011.
Once you have this key exported, you can push these entries through Group Policy if you’d like, use a batch file, or other means. The choice is yours.
After the import, you can then kick off cleanmgr.exe /sagerun:11 which will run through the same cleanup on all your clients.
Voila! Presto! More free space.
Similar to the registry keys, you can push out a scheduled task that would then execute the previous command on your clients say once a month. However, you may not want to be this aggressive and you need to be careful about when this runs. Remember, after you perform this cleanup, you cannot remove any Windows Updates that have been applied previously. You can still uninstall the latest updates that have been applied after the cleanup though, but it may take you all the way back to the SP1 level. You also do not want this scheduled task to run right after you apply updates. Depending on your patching schedule, you may want to schedule the cleanup to occur a day or two before regularly scheduled updates are applied. By default, the option to run a task as soon as possible after a scheduled start is missed is NOT checked. Because you do not want this to run right after applying new updates, I would advise against checking this box. If it’s missed, let the cleanup slide to the next scheduled run.
Happy Windows Update Cleanup Day!
Charity “Fall is the new Spring cleaning season” Shelbourne
Does Windows 8.1 RT supports 64-bit ARMv8 processors? No reply on technet forums so far.. social.technet.microsoft.com/.../does-windows-rt-81-support-armv8-64bit-processor Please confirm.
Awesome post, well written and extremely helpful.
Great news. Will this be coming for 2008r2 sometime soon?
the update is buggy and removes not superseded updates like the RDP 8.0 client.
the update should also work for 2008R2:
ApplicabilityInfo="Windows 7.0 Client SP1;Windows 7.0 Server Core SP1;Windows 7.0 Embedded SP1;Windows 7.0 Server SP1;"
it applies to Client Windows 7, Server (Core) and Embbeded with Sp1.
Thanks for breaking the news! I'd expect this info to come from Storage or Core team blogs first :) I've got a couple of questions, though.
1. Re: "Important note: After performing this cleanup, you may not be able to uninstall any of the updates currently applied."
This statement is not clear, and the same goes about the KB article.
In Windows 8 and 8.1, the cleanmgr operation is equivalent to:
Dism.exe /Online /Cleanup-Image /StartComponentCleanup
This does leave an option to uninstall the latest update and roll back to the older version. Here's the GUI screenshot http://bit.ly/1bGAKay (Russian UI, though).
In Windows 8.1 there's an additional DISM switch /ResetBase:
Dism.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase
Using this option does remove the ability to uninstall the latest update http://bit.ly/18OmxUr
So the "may not be able" clause is confusing. You are either able or not, depending on what exactly cleanmgr does. Please clarify.
2. What about DISM option? Are you aware of any plans to bring this feature to DISM in Windows 7 SP1? Automating cleanmgr is rather a workorund, and it doesn't really work on offline images.
Just to be sure (yep, I saw the previous comments about Windows Server) - Is this applicable to Windows Server 2008 R2 SP1? Andre mentioned that it is, however when I look on the kb page under "applies to" section, I see only Windows client editions. If it applies to server editions as well, could someone please update the "applies to" section"?
@ Frank Trout
Thank you! I'm glad you found it helpful!
@ Andrew Burt
This update is only applicable to Windows 7 SP1 clients. I've provided feedback to our Product Group that this is needed for Windows Server 2008 R2 as well, but there are no plans at this time. Please provide your feedback though! I would be happy to forward it to them. :-)
This update specifically targets Windows Updates specifically. I agree that this update *should* work with Windows Server 2008 R2, but it does not. I tested it before blogging on this update just to make sure. When attempting to apply it, you receive a not applicable message.
That's a good question. The ARMv8 processors are not expected to be out until 2014. As a result, Windows 8.1 RT will release provide to the ARMv8 processors. Let me see what I can find out.
Thank you, better late than never. This is how Windows Vista should have shipped in 2006. Well if not Vista then what Windows 7 RTM should have had this ability in 2009. It was bad design right from the beginning and Microsoft knew it. They only didn't care about fixing it until Windows 8 when the mobile era arrived and huge capacity HDDs started getting replaced by smaller flash memory. Uncontrolled WinSxS growth was a huge problem for SSDs even for desktop platforms and servers and we kept telling MS and NOW they listen - "ONLY" 7 years after Vista. Hopefully that other disk space hogging behavior will be corrected as well which was introduced in Windows 7 where Windows Installer 5.0 caches the entire MSI in %windir%\Installer without stripping off the CAB files stored inside it. That also causes serious disk bloat and needs to be addressed in the next update to Windows Installer.
Could you guys make this happen for Windows Server 2008 R2 as well. My servers are crying for free space. Pretty please.
I still don't understand why Server 2008R2 doesn't work. The meta data don't show any restrictions to Client only.
What do you mean with "Windows Updates"? So it only removes Updates which are installed by WU? No Updates which are installed locally with a MSU or CAB?
@ Vadim Sterkin
It doesn't block the uninstall. It performs a subset of what dism /startcomponentcleanup does in Windows 8, except it is online only and only available from cleanmgr.
There are no plans at this time to update DISM. I personally agree that this is where this cleanup belongs, but this functionality has only been back ported to Disk Cleanup (cleanmgr.exe) at this time.
I feel your pain. My customers are in similar situations. Keep providing the feedback. I'm forwarding it all to our Product Group. :-)