How to Safely Remove Windows.old on Hyper-V Server 2012 R2 Without GUI Using Command Line


2 views

When upgrading from Hyper-V Server 2012 to 2012 R2, the system creates a Windows.old directory containing the previous installation. This folder often contains complex junction points and system files that make manual deletion risky.

Attempting to use rmdir /s or similar commands can:

  • Leave behind inaccessible files due to permission issues
  • Potentially damage the current OS through broken junctions
  • Fail to properly release disk space

Microsoft provides a built-in tool for this purpose:

Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase

For more aggressive cleanup (recommended for Hyper-V Server):

Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase /SPSuperseded

For administrators preferring PowerShell:


# First verify the folder can be removed
Get-WindowsUpdateLog -WindowsOldDirectory "C:\Windows.old"

# Then execute cleanup
Clean-WindowsOld -WindowsOldDirectory "C:\Windows.old" -Confirm:$false

If you encounter access denied errors:


takeown /f C:\Windows.old /r /d y
icacls C:\Windows.old /grant administrators:F /t

After cleanup, verify with:


fsutil file queryextents C:\Windows.old

This should return "Error: The system cannot find the file specified" if successful.

  • Ensure at least 15% free disk space before cleanup
  • The process may take significant time on large installations
  • Create a system restore point if possible (though limited on Server Core)

When upgrading from Hyper-V Server 2012 to 2012 R2, the installer creates a Windows.old directory containing the previous installation. Unlike GUI systems where Disk Cleanup handles this automatically, Server Core requires manual intervention due to:

  • No Desktop Experience features available
  • Special NTFS junctions and permissions
  • Potential system instability if removed incorrectly

The proper sequence involves using built-in command-line tools:

# First verify ownership
takeown /F C:\\Windows.old /R /D Y

# Then reset permissions
icacls C:\\Windows.old /reset /T /Q

# Finally remove (using 2012 R2 specific switches)
rd /s /q C:\\Windows.old

For stubborn files due to Hyper-V's virtualization components:

# Stop relevant services first
net stop vmms
net stop vds

# Remove virtualization-specific junctions
del /q /f C:\\Windows.old\\Windows\\Virtualization\\*
rmdir /s /q C:\\Windows.old\\Windows\\Virtualization

After removal, confirm system integrity:

# Check disk structure
dism /online /cleanup-image /scanhealth

# Verify Hyper-V services
sc query vmms
sc query vds

For completely clean removal, use deployment tools:

dism /online /cleanup-image /startcomponentcleanup /resetbase

This method is particularly effective when dealing with leftover component store references.

  • Perform during maintenance windows - some operations require service interruption
  • Create system restore point first: wbadmin start backup -backupTarget:C: -quiet
  • For large installations, consider using robocopy with mirror mode as intermediate step