Skip to content

Freeing space on Server 2008 R2 and 2012

July 10, 2013

While looking to remind myself of the exact command to remove the SP1 removal files for 2008 R2, I happened on some other useful utilities that I hadn’t seen previously.

Now, I’m aware that the price per GB is coming down all the time, and multi-TB drives can be had for change out of £150 (I’ve got a NAS box with 4 x 3TB drives, I know), but enterprise-grade spindles are still pricey, due to the far-superior MTBF numbers. Once you’re into the realm of SAN’s, every GB counts. There, it’s not just drives, but hit the magic number and it’s another shelf with cabling etc. It all adds up. Having said that, if you’re using de-duplication of some flavour, the results of the below might be more limited as these will be static files, similar on each install.

Most interesting to me is the 2012 stuff, this is what I’m really concentrating on improving on at the moment, so these tips are gold dust 🙂 First off, the WinSXS (or ‘Side By Side’ folder, as you might see it written) that has taken so much criticism. Not fair really, this folder holds a lot of Windows Update stuff but is also important for the OS, had it been called System or similar, it might have been let off. So, first a little utility that shows how big the actual folder is, while Windows Explorer and the ‘dir’ command-line utility cannot differentiate between actual files and hardlinks, this little beauty can. While the end-user forums are full of torrents of abuse against Microsoft for this ‘stupid way of doing things’, the true value can be found using du ( The utility will display the true size of any folder but the WinSXS folder can targeted by using :

du -v c:\windows\winSXS

So once that’s been discovered, we can start to see how we can improve it.

A feature of 2012 that I felt was well-overdue was Features On Demand, This sort of mimics the Linux way of doing things, by enabling the server OS to hold only features and roles it’s using. So a Domain Controller, assuming you’re following something close to best practice, should only be running ADDS, DNS and a few other minor bits to supports these roles. Everything else can be uninstalled to lower the possible attack surface, and for every day value, reduce the amount of drive space consumed. The awkward thing about this is that individually uninstalling all the roles takes a) a bit of research to discover the list to uninstall, and b) time to run each command. But there is of course a better way of doing it and that’s to be clever with PS. Such is the versatility of PS that if you can imagine it, you can probably translate that into verb-noun speak. The following command is designed to be run on a system set up as it intends to continue, the Domain Controller being a good example. So add the roles and features you desire, and then run :

Get-WindowsFeature | where-object{$_.Installed -eq 0 -and $_.InstallState -eq ‘Available’} | uninstall-windowsfeature -remove

As you can likely see, it’s a pipe of a result into a filter, and then piped to a command to act on the result. It looks at the feature payload list, filters that list to what’s not (0) installed (Available) on the current server, and removes that list. I ran this on a lab W2012 DC install on my laptop, and free space went from 10.6GB to 12.3GB. Not amazing, but bear in mind we’re not talking personal laptop here, an organisation may have hundreds or thousands of server installs, and this can then add up. Add in the fact that you’re reducing the backup size (of a full backup) by several GB, again over many server installs, it’s a hefty saving again, and could bring backup windows back down a touch. Features can still be added by the way, the OS will look to the WinSXS folder, and fallback to Windows Update if the required files are there.

Another probably more widely known command is the one that removes SP uninstall files. From what I can see, it’s the same for 2012 as it was for 2008R2, no reason to reinvent the wheel, DISM is not a bad tool. Appropriate to 2008R2, where SP1 should be installed, is :

dism /online /cleanup-image /SPSuperseded

This will remove the uninstall files for SP1, but it’s unlikely you’d want to uninstall that anyway. I ran this on a production server not long ago and pulled back north of 4GB, not bad for a five minute wait for the command to complete. A final cleanup can be performed by using :

dism /online /cleanup-image /StartComponentCleanup

to clean up the superseded components and reduce the size of the component store. Use /ResetBase additionally to reset the base of superseded components, which can further reduce the component store size. I might consider the value of scheduling some variation of these commands perhaps once a month. Production servers, following a period of dev testing on new updates, could use the scheduled method too. Once an update is deemed safe and stable, security statements would rarely allow the removal of Critical and Security anyway.

Hope this helps someone 🙂

EDIT – In addition, I just ran : Dism /Online /Cleanup-Image /startcomponentcleanup on that Server 2012 DC, following the feature removal command, and free space has gone from 12.5GB to 12.9GB. Not a huge gain again, but multiply over many servers etc. Also, 2012 is relatively young in Windows Update terms, as time goes by, the gain from this command will increase. Bear in mind also that when the command completes in Powershell, it will request a reboot. On reboot, it will go through the ‘Configuring Updates’ stage before the desktop appears, and follow that with a similar style ‘Cleaning’ message that took about 30 seconds to run through. Once booted, I did the comparison and there was some gain to be had, as mentioned.

I did try appending the /resetbase command and it errored, coming back with the fact that that switch is not used that context. I just removed that and the command ran through successfully.


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: