Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.7k stars 1.07k forks source link

1903 (insider build 18312) reserved storage #194

Open Disassembler0 opened 5 years ago

Disassembler0 commented 5 years ago

https://blogs.windows.com/windowsexperience/2019/01/09/announcing-windows-10-insider-preview-build-18312/

https://blogs.technet.microsoft.com/filecab/2019/01/07/windows-10-and-reserved-storage/

Starting with the next major update we’re making a few changes to how Windows 10 manages disk space. Through reserved storage, some disk space will be set aside to be used by updates, apps, temporary files, and system caches. Our goal is to improve the day-to-day function of your PC by ensuring critical OS functions always have access to disk space.

...we anticipate that reserved storage will start at about 7GB...

Find if this can be disabled or reduced. It's a NTFS feature, so it might not be that easy :/

Ainatar commented 5 years ago

CMD: reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" /v "ShippedWithReserves" /t REG_DWORD /d "0" /f

PS: Set-ItemProperty -LiteralPath "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "ShippedWithReserves" -Value 0 -Type DWord -ErrorAction SilentlyContinue

develtom commented 5 years ago

this does not work. I have a cleanly installed Windows 10 1903, free space of 20GB on the system disk and still can't disable the reserved space.

Disassembler0 commented 5 years ago

This worked for me:

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "BaseHardReserveSize" -Value 0 -Type QWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "BaseSoftReserveSize" -Value 0 -Type QWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "HardReserveAdjustment" -Value 0 -Type QWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "MinDiskSize" -Value 0 -Type QWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "ShippedWithReserves" -Value 0 -Type DWord -ErrorAction SilentlyContinue

After that I have clicked on Clean now in Storage settings and the reserved space disappeared from the listing.

However I have no idea: 1) If it really deallocated the space or if it just hid it from UI 2) What some of those values under ReserveManager registry key mean 3) How to run the cleanup from script or how to achieve the same result as the cleanup does 4) If it is safely reversible simply by setting the original values

I have tried to reset it using the original values via

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "BaseHardReserveSize" -Value 5368709120 -Type QWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "BaseSoftReserveSize" -Value 1610612736 -Type QWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "HardReserveAdjustment" -Value 522039296 -Type QWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "MinDiskSize" -Value 21474836480 -Type QWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager" -Name "ShippedWithReserves" -Value 1 -Type DWord -ErrorAction SilentlyContinue

and after reboot my reserved storage shows 110 MB. I can only assume that it will eventually grow when the space is needed, but I haven't confirmed that either.

develtom commented 5 years ago

Super this works. I have back 7GB available. Thank you very much

Disassembler0 commented 5 years ago

Some small update for fellow researchers. The reserve is indeed a NTFS feature. In can be seen in overall statistics via

fsutil fsInfo ntfsInfo C:

It can be queried to see the individual "buckets"

fsutil storageReserve query C:

where

And it can be queried for individual file listing

fsutil storageReserve findByID C: *

There doesn't seem to be any subcommands for direct manipulation of reserves via fsutil.

The Storage Sense which triggers the resize does quite a lot. So far I have been able to completely rule out involvement of cleanmgr.exe which is executed by it and I have string suspicion that the resize is triggered by some code in C:\Windows\System32\SettingsHandlers_StorageSense.dll or one of libraries which it loads. I'll poke around a bit more later.

Disassembler0 commented 5 years ago

The registry keys are read by StorSvc service in following order:

  1. PassedPolicy
  2. ActiveScenario
  3. BaseHardReserveSize
  4. BaseSoftReserveSize
  5. HardReserveAdjustment
  6. PostUpgradeFreeSpace (doesn't exist in default state)
  7. UserFreeSpaceMarker (doesn't exist in default state)

This service uses library C:\Windows\WinSxS\amd64_microsoft-windows-servicingstack_31bf3856ad364e35_10.0.18362.110_none_5f52ccdc58d07895\ReserveManager.dll which exposes following entry points:

Looks like I'm on the right track. Also looks like this won't be possible without P/Invoke :(