Some time ago I upgraded my Windows Server 2012 machine to Windows Server 2012 R2. The upgrade was seamless and the server has hummed along just fine until recently, when it began running out of space.
Windirstat, a great little disk space usage reporting program, reported that the largest hog of space was the windows.old folder. Upon upgrade of the OS, the old Windows folder was renamed to Windows.old to make room for the new OS files and has sat there, untouched, ever since.
I tried to remove this folder with hilarious results. The folder is owned by TrustedInstaller. Easy enough, I’ll just replace the owner with my own user account, right? Wrong. Even after becoming the owner of the folder and everything inside it, I was prompted that I needed permission from… myself.. to delete the folder. I then tried changing the owner to “Everyone” and receive a rother comical message that I needed permission from Everyone to remove the folder. That would take some time!
That’s when I decided to throw in the towel and google. The solution to this problem involves the command line (thanks to here for the information.) Open an administrator command prompt and issue the following commands:
takeown /F c:\Windows.old\* /R /A /D Y cacls c:\Windows.old\*.* /T /grant administrators:F rmdir /S /Q c:\Windows.old
That did the trick! No more full disk.
Nick’s technical musings
Skip to content
How to remove the windows.old is still an issue on some servers. Well it is easy to remove but you will need a reboot.
<remove the windows.old>
What you need to do is install the Desktop Experience Go to the server manager and add new feature
Find the Desktop Experience and add this you will need a reboot.
Get-WindowsFeature *desk*
install-WindowsFeature -Name Desktop-Experience –IncludeAllSubFeature
Now that we installed the Desktop Experience there is a new option if you do properties on the C drive.
Press the Disk Cleanup and a quick scan will find all the info that we need to remove the previous Windows installation.
Now the Cleanup is running and after this I have 28.5 GB free space
Robert Smit is Senior Technical Evangelist and is a current Microsoft MVP in Clustering as of 2009.
Robert has over 20 years experience in IT with experience in the educational, health-care and finance industries.
Robert’s past IT experience in the trenches of IT gives him the knowledge and insight that allows him to communicate effectively with IT professionals
who are trying to address real concerns around business continuity, disaster recovery and regulatory compliance issues. Robert holds the following certifications:
MCT — Microsoft Certified Trainer, MCTS — Windows Server Virtualization, MCSE, MCSA and MCPS. He is an active participant in the Microsoft newsgroup community and is currently focused on Hyper-V, Failover Clustering, SQL Server, Azure and all things related to Cloud Computing and Infrastructure Optimalization.
Follow Robert on Twitter @ClusterMVP
Or follow his blog https://robertsmit.wordpress.com
Linkedin Profile Http://nl.linkedin.com/in/robertsmit
Robert is also capable of transferring his knowledge to others which is a rare feature in the field of IT. He makes a point of not only solving issues but also of giving on the job training of his colleagues.
A customer says » Robert has been a big influence on our technical staff and I have to come to know him as a brilliant specialist concerning Microsoft Products. He was Capable with his in-depth knowledge of Microsoft products to troubleshoot problems and develop our infrastructure to a higher level. I would certainly hire him again in the future. »
Details of the Recommendation: «I have been coordinating with Robert implementing a very complex system. Although he was primarily a Microsoft infrastructure specialist; he was able to understand and debug .Net based complext Windows applications and websites. His input to improve performance of applications proved very helpful for the success of our project
View all posts by Robert Smit [MVP]
It turns out that all the tips for Windows 7 and 8 rely on assumptions that are not valid in Windows Server 2012.
See here for some good Win 8 tips:
Removing Windows.old from Windows 8
For Windows Server 2012, I eventually figured out this kludge to get rid of the 16GB Windows.old folder:
- Take a backup of the OS Drive on your Server (Usually C:).
- As an Administrator on the local machine, or as a Domain Administrator, right-click on the Windows.old folder and choose Properties.
- Choose the Security tab.
- Choose the Advanced… button
- Beside Owner at the top of the dialog, click Change.
- Enter your own User Id. Check Names. Ok.
- Now check the box that appeared for Replace owner on subcontainers and objects.
- Click Apply.
- When it’s done, Cancel out of the Advanced Security Settings and Windows.old Properties dialogs.
- Then, reopen the Properties and select Security and select the Advanced… button.
- Now hit the Change Permissions button.
- Now click the Add button.
- At the top, click Select a principal and put your own User Id in. Check Names. Ok.
- Under Basic Permissions, click Full Control. Click Ok.
- Back on the Advanced Security Settings dialog, in the lower left check the Replace all child object permissions with inheritable permission entries from this object.
- Click Apply. Click Yes when it asks you to confirm.
- Click Ok when it’s done. Close the Properties dialog.
- Now, close any other windows you happen to have opened in your frustrated attempts to get rid of Windows.old (I had many).
- In Explorer, right-click the Windows.old folder. Hold down Shift and select Delete. (Shift will skip the Recycle Bin and just delete the folder and it’s contents). Some time later, the Windows.old folder “should” be gone. I did this on two servers and on one it disappeared, on the other two files were in use somehow. Even after a reboot, those two files are still in use. Weird. They only take up 8K, so I’m going to ignore them. One day, I might go after them again, but I doubt it.
- It’s probably a good idea to force a reboot after deleting the Windows.old folder to make sure you didn’t just hose your server. If you did, then you have a backup to restore from, right?
One of my Windows Server 2012 R2 ran out of space. A quick folder analysis using the free portable tool TreeSize revealed that both Windows.old and WinSxS folders are the ones taking most of the spaces.
On Windows desktop systems, both folders are easy to clean up with the built in tool Disk Cleanup Utility. But, it’s not the case in Windows Server, especially the more recent versions like 2012 R2. You probably could enable Desktop Experience feature to bring back the Disk Cleanup Utility but it won’t guarantee to clean up these two giant folders managed by the system upgrades and updates. If you are facing the same challenge as I do, here are the options you can take away.
WinSxS, aka Windows component store, contains all the files required for a Windows installation as well as any updates to those files within the component store. Therefore, the folder could become quite big over time. Because it’s associated with system installation it’s not a good idea just simply deleting the folder. Rather, utilizing a command-line tool called DISM, Deployment Image Servicing Management, is way more appropriate. It has a parameter /cleanup-image
that provides a few more advanced options to reduce the size of the WinSxS folder.
First of all, you can run the following to analyze the component store to see what’s included in there.
dism /online /cleanup-image /AnalyzeComponentStore
Then, run the following to remove superseded and unused system files from the system and reset the base so all existing updates cannot be removed after the command is completed.
dism /online /cleanup-image /StartComponentCleanup /ResetBase
It didn’t clean up a whole lot in my case, only claimed back a little over 1 GB space.
Note: If you are somehow still using Windows Server 2008 R2, installing KB2852386 after enabling Desktop Experience feature makes things a lot easy to clean up right with the Disk Cleanup Utility tool.
How to clean up WinSxS folder on Windows 2008 R2
How to clean up Windows.old on Windows Server 2012 R2
With Disk Cleanup out of the equation, manual cleanup seems to be the option left. Thanks to this Q&A at ServerFault, here is what I did to bring back over 50 GB of storage space.
First of all, run Sysinternals junction.exe utility to get a list of all junctions in a text file, junc.txt on my desktop.
junction.exe -s -q c:\windows.old > %UserProfile%\desktop\junc.txt
Then, run the following script in PowerShell to remove all junction points and single symbolic links on the system.
foreach ($line in [System.IO.File]::ReadLines("$env:userprofile\desktop\junc.txt")) { if ($line -match "^\\\\") { $file = $line -replace "(: JUNCTION)|(: SYMBOLIC LINK)","" & $env:userprofile\desktop\pstools\junction.exe -d "$file" } }
Replace with the correct path for junction.exe utility and the junc.txt files, if needed.
Once that’s done, run the following to take over ownership of the windows.old folder.
takeown /f c:\windows.old /r /d y
And reassign the full control rights to everyone.
cacls c:\windows.old /t /g everyone:F
Then, finally to remove the whole folder.
rmdir /s /q c:\windows.old
It may take a little while for the command to complete but once it’s done you will be so delighted to see how much space you just brought it back to life. Enjoy.
Posted: October 20, 2014 by lowarcticsun in Computer Basics
1) Download Junction.exe from Sysinternals. I extracted and saved it to c:source. You will use this tool to generate a list of all the junctions that have to be removed.
2) create a reference file that lists all the junction points and symbolic links in use by opening up a command prompt, changing into C:source and running
junction.exe –s –q c:\windows.old >junctions.txt
3) open up PowerShell ISE administrator rights and run the following script to remove all symbolic links and junction points in c:windows.old.
foreach ($line in [System.IO.File]::ReadLines(“c:\source\junctions.txt”)){
if ($line -match “^\\\\”){
$file = $line -replace “(: JUNCTION)|(: SYMBOLIC LINK)”,””
& c:\source\junction.exe -d “$file”
}
}
You should get the following scrolling by…
Now it’s some simple taking of ownership, granting rights and deleting windows.old to get your space back.
4) to take ownership use
- takeown /F C:windows.old /R /D Y
- cacls C:windows.old /T /G Everyone:F
rmdir /s /q C:\windows.old
5) delete c:windows.old – you now have permissions and ownership.