Saturday, June 18, 2011

Clean up Winsxs on Windows 2008 R2 after SP1 install

Last year I wrote a post where I explained what the Winsxs folder was and which were the possible solutions to contain its bad habit of eating free space on your hard drive. Some days ago I have discovered that, starting from Service Pack 1, Windows 2008 R2 (... and Windows 7) finally has a built-in tool to reduce the size of the Windows Side-by-Side DLL repository and free up some GBs on your server storage. This tool is DISM.exe.

Cool news isn't it? Personally I am happy to know that someone at Microsoft has finally decided to make it possible to reclaim a few GBs on the system partition and to partially solve this major bug.

The procedure is the following:
  • Install Windows Service Pack 1 then ...
  • Start and elevated command prompt (run 'CMD' as administrator) and ...
  • Run the DISM command, which replaces the old VSP1CLN and COMPCLN we used on previous Windows versions: DISM.exe /online /Cleanup-Image /spsuperseded
  • Wait 10 minutes before the task completes ( it ends with “Service Pack Cleanup operation completed. The operation completed successfully”)
Normally you should have been able to reduce the Winsxs folder size by 1 or maybe 2 GBs, sometimes more. Saved space may vary a lot.

Just know that after using DISM you will not be able to uninstall the Service Pack 1 anymore.

Let's have a look at the used switches for DISM.exe:
  • The /online switch tells DISM to work on the running OS installation
  • The /spsuperseded option removes the backup files created during installation. 
Optionally you could use the /hidesp option which will remove SP1 (KB976932) from the “Installed Updates” section of Programs and Features, to ensure that users do not try to uninstall the Service Pack.

I hope this helps. Please let me know how much disk space you were able to free up using the given command.

48 comments:

  1. Can you remove the backup files of hotfixes/updates?

    ReplyDelete
  2. Note: A space is needed after the "/online" switch in "DISM.exe /online/Cleanup-Image /spsuperseded"

    Thanks!!

    ReplyDelete
  3. Thanks so much for this. I've spent a while trying to find where VSP1CLN or COMPCLN were in Server 2008 R2, because I couldn't find them. Finally I found your post about using DISM to remove old files. I ran it on my server and freed up about 3 gig of space! Thanks again!

    ReplyDelete
  4. I only was able to clean up 600 MB... Still 9 GB left in winsxs... :(

    ReplyDelete
  5. I was pleasantly surprised to clean up about 4GB. I went from 9.7 GB to 5.7GB. Thanks!

    ReplyDelete
  6. Brilliant. I managed to clear up 2.7 GB of space :)

    ReplyDelete
  7. Seems that /spsuersceded and hidesp are not good options. Note also that typing dism /? (for help) doesn't show /Cleanup-Image as an option. Shoddy work MS.

    PS C:\Windows\system32> dism.exe /online /Cleanup-Image /spsuperseded /hidesp

    Deployment Image Servicing and Management tool
    Version: 6.1.7600.16385

    Image Version: 6.1.7600.16385


    Error: 87

    The spsuperseded option is not recognized in this context.
    For more information, refer to the help.
    The hidesp option is not recognized in this context.
    For more information, refer to the help.

    The DISM log file can be found at C:\Windows\Logs\DISM\dism.log

    ReplyDelete
  8. C:\Windows\system32>DISM.exe /online /Cleanup-Image /spsuperseded /hidesp

    Deployment Image Servicing and Management tool
    Version: 6.1.7600.16385

    Image Version: 6.1.7601.17514

    Removing backup files created during service pack installation.
    [==========================100.0%==========================]
    Service Pack Cleanup operation completed.
    The operation completed successfully.


    This cleaned up 1.5Gb on my desktop machine.

    Thanks for the post!
    Lexas

    ReplyDelete
  9. The help is context sensitive. Use:
    dism /online /Cleanup-Image /?
    to see the spsuperceded and hidesp options.

    ReplyDelete
  10. Got back about 4 Gigs - was 11184MB, now 6813MB
    (Win2008R2)

    Thanks

    ReplyDelete
  11. I have windows 2008 Enterprise Service pack 2, but dism command is not working, it says it is not internal or external command

    ReplyDelete
  12. Did you start the dism command from an elevated command prompt? Otherwise UAC is probably preventing this action.

    Check this:

    http://www.happysysadm.com/2011/11/windows-2008-r2-folder-security-issue.html

    ReplyDelete
  13. I have windows server 2008 SP2, when I am running
    "dism /online /cleanup-image /spsuperseded", its giving error:
    Error: 50
    DISM does not support servicing Windows Vista or Windows Server 2008 with the /O
    nline option.

    ReplyDelete
  14. No such option...

    c:\Windows\System32>DISM.exe /online /Cleanup-Image /spsuperseded

    Deployment Image Servicing and Management tool
    Version: 6.1.7600.16385

    Image Version: 6.1.7600.16385

    Error: 87

    The spsuperseded option is not recognized in this context.
    For more information, refer to the help.

    The DISM log file can be found at C:\Windows\Logs\DISM\dism.log

    c:\Windows\System32>DISM.exe /online /Cleanup-Image /?

    Deployment Image Servicing and Management tool
    Version: 6.1.7600.16385

    Image Version: 6.1.7600.16385

    /Cleanup-Image /RevertPendingActions

    WARNING! This operation will revert pending actions from previous servicing
    operations. It should be used for recovery operations only. This command
    is not supported against an online image.

    Example:
    DISM.exe /Image:C:\test\offline /Cleanup-Image /RevertPendingActions

    ReplyDelete
  15. error 87 appears to mean: SP1 isnt on the installed list.

    best to check your list of installed updates to see it is actually there.

    ReplyDelete
  16. Hi,

    I confirm, this command ONLY works with SP1 installed (it is not available with no SP installed and obviously you don't need it if you don't have SP installed...)

    ReplyDelete
  17. Thank you, it worked well.
    Before
    Size on Disk 11.9GB
    Files 59,264
    Folders 15,744

    After
    Size on Disk 6.16GB
    Files 42,707
    Folders 11,180

    ReplyDelete
  18. Any option to remove old hotfixes or security updates after SP1 or is this just for SP1.

    ReplyDelete
  19. Good question. I also ask myself the same question.

    Other question is, does this only work on Windows 7 and Server 2008 R2, or also on Server 2008 Enterprise 32-bit / 64-bit?

    ReplyDelete
  20. Reduced size from 13GB to 6GB Allen Suski

    ReplyDelete
    Replies
    1. Thanks for you feedback, Allen!

      Delete
    2. All good here, worked like a charm - managed to shave 4GB off my winsxs file alone!

      i5-2500k, 3.3GHz, 8GB Ram, Kingston SSD, Win 7 Pro (64-bit).

      John (UK)

      Delete
  21. Thank you! winsxs reduced by over 5 Gigs!!! 2008 R2.

    ReplyDelete
  22. Ran elevated cmd (as Administrator), copy/pasted your command line in from above, and voila +2.2GB!

    Thanks, much appreciated.

    ReplyDelete
  23. Saved 2.3GB! Thanks!

    ReplyDelete
  24. OMG!!!!!

    Before: 300 mb
    After: 14 mb

    Why!?!?!?!? What happened??

    ReplyDelete
  25. Saved 4.5 Gigs of space on the first Hyper-V Guest I tried it on. Assuming it stays stable during testing, 44 more to go!

    ReplyDelete
  26. Thanks a lot. Saved almost 7Gb. Works fine

    ReplyDelete
  27. Old size: 12.7G new size: 7.3 G

    ReplyDelete
  28. Awesome - went from 1.56GB to 6.28 Win2k8 R2.

    Thank you

    ReplyDelete
  29. locked by winsxs
    previously 9,174.2 MB
    now 6,526.5 MB
    so 2647.7 MB spared

    Thanks for this lovely command.
    --

    As this additional question is asked above by others, I repeat ask it: - does it just removes W7SP1 or there are methods to remove all windows updates and other updates (say, done by WUD Windows updates downloader)? I don't want to keep so much space locked in updates backup files, even if deleting them means I will never be able to revert to older version.

    Please tell the method to remove all updates backups.

    Thanks.
    Rawat
    India

    ReplyDelete
  30. I cleaned up 4.5g of space on a 40g drive. Thanks a bunch!

    ReplyDelete
  31. Nice, 4,45 GB

    Thank's

    ReplyDelete
  32. I guess no option to remove unneeded backups of hotfixes and updates.
    My WINSXS is at a wopping 11GB! And that's after removing the SP1 backups.

    ReplyDelete
  33. This has worked great for my 2008 R2 Standard SP1 virtual with the following message:


    Deployment Image Servicing and Management tool
    Version: 6.1.7600.16385

    Image Version: 6.1.7600.16385

    Removing backup files created during service pack installation.
    Removing package Microsoft-Windows-ServerEnterpriseEdition~31bf3856ad364e35~amd64~~6.1.7600.16385
    [==========================100.0%==========================]
    Service Pack Cleanup operation completed.
    The operation completed successfully.

    The WinSxS size has gone down from 11275.3 MB to 7237.4MB

    ReplyDelete
    Replies
    1. @mandrew2000

      Thanks for sharing your results and glad I could help!

      Delete
  34. I don't understand why it works for some and not others.

    ReplyDelete
  35. Before: 1.5 gig ram. After: 4.47 gig. Cleared nearly 3 gigs. Thanks a million!

    ReplyDelete
  36. I managed to free up 3G, yay

    ReplyDelete
  37. I moved that folder to another partition. My server is Windows 2008 R2, and is DC. Here's the steps:
    1. Logon as administrator. Copy C:\windows\winsxs to z:\windows\winsxs. Drive Z is on a different partition.
    2. Create a link for the new folder. In Command Prompt, excute "mklink /j c:\windows\winsxs_1 z:\windows\winsxs". It creates a link with name winsxs_1.
    3. Restart the server with Winodws 2008 R2 Installation Disk. When it starts, select Repair your OS, NOT Install. It will pop up the System Recovery Options window. Select the option "Use recovery tools that can help fix problems starting Windows". It lists the OS installed on this server. Write down the drive letter. Your C drive may not be C at this time. Mine is drive G. Then click Next.
    4. Use Command Prompt. Go to the drive that your OS was installed. And go to Windows folder. Rename Windows\winsxs to be winsxs_original. Rename the link windows\winsxs_1 to be winsxs.
    5. Exit the command windows, and restart the server.
    6. Logon as administrator. Find windows\winsxs_original. Take ownership. And grant administrator to have full control.
    7. Restart the server again. When it's fully started, try update/install/uninstall. And then check which folder has been updated. In my case, z:\windows\winsxs is updated. That means the OS is using the new location. Now you can delete c:\windows\winsxs_original.

    ReplyDelete
  38. The WinSxS size has gone down from 13,4 GB to 9,0 GB...
    Gain 4,4 GB

    ReplyDelete
  39. wau, 10 GB free

    ReplyDelete
  40. I get the below error. Please advice.


    C:\Users\Administrator>DISM.exe /online /Cleanup-Image /spsuperseded

    Deployment Image Servicing and Management tool
    Version: 6.1.7600.16385

    Image Version: 6.1.7600.16385

    Service Pack Cleanup can't proceed: No service pack backup files were found.
    The operation completed successfully.

    ReplyDelete
  41. 30gb was filled on a VM server. DISM freed up about 5GB.

    Thanks a bunch!

    ReplyDelete
  42. DISM for Server 2008R2 SP1 whereas we're still stuck with COMPCLN for Server 2008 SP2 and 16GB winsxs directories.

    ReplyDelete
  43. Freed up 3 GIGS. Thanks

    ReplyDelete
  44. Service Pack Cleanup can't proceed: No service pack backup files were found.
    The operation completed successfully.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...