Skip to content

tannerharkin/REsizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REsizer: WinRE Resizer Script

REsizer Logo

REsizer is a PowerShell script designed to automate the resizing and configuration of the Windows Recovery Environment (WinRE) as per KB5028997 to address Windows Update error 0x80070643 when installing the WinRE update. This script is only designed for standard Windows installs.

Table of Contents

Introduction

This PowerShell script manages the Windows RE partition by shrinking the primary OS partition, deleting the old Windows RE partition, and creating a new one to ensure that system recovery mechanisms function correctly post-update.

Disclaimer: THIS SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Use at your own risk!

Prerequisites

Ensure your system meets the following before running REsizer:

  • System Layout: Single disk with a standard partition layout.
  • Operating System: Windows 10. No other operating systems installed.
  • Administrative Rights: The script must be run as an Administrator.
  • Data Backup: Backup all important data on the disk, assume this script will wipe your computer.
  • Free Disk Space: At least 250MB of space must be free in the OS partition.

Usage

To use REsizer, follow these steps:

  1. Open PowerShell as an Administrator (right-click, Run as Administrator).

  2. Set Execution Policy: Run Set-ExecutionPolicy Bypass and press Y at the prompt.

  3. Execute the REsizer Script:

    $uri='https://raw.githubusercontent.com/tannerharkin/REsizer/main/REsizer.ps1';$hash='968EDB783501BEB3B7AD980A6F4343AB3FED60CD295C588D3031217A6147651E';if((Get-FileHash -Algorithm SHA256 -InputStream (iwr $uri -UseBasicParsing).RawContentStream).Hash -eq $hash){iex (iwr $uri -UseBasicParsing).Content}else{Write-Error 'Hash mismatch'}
    Woah! That's a lot longer than the usual download and run one-liner, what is all that?

    This command ensures that only an approved version of the script is executed, providing a security measure against unauthorized changes or potential hostile takeovers of the script repository (as unlikely as that would be). Here's what each part of the command does:

    • Set Variables: Sets $uri for the script URL and $hash for the expected SHA256 hash.
    • Download the Script: Uses Invoke-WebRequest (iwr) to download the script once with -UseBasicParsing, which is necessary for older versions of PowerShell, and most Windows Server installs (we still don't recommend using REsizer on server!).
    • Store Script Content: Stores the downloaded script content in a variable, reducing the risk of the script being tampered with between download and execution (mitigates a theoretical TOCTOU bug if we were to fetch twice).
    • Hash Verification:
      • Get-FileHash computes the SHA256 hash of the stored script's content stream directly.
      • Compares this computed hash with the expected hash, ensuring script integrity.
    • Conditional Execution:
      • If the hashes match, the script is executed using Invoke-Expression (iex).
      • If there's a hash mismatch, an error is issued using Write-Error, preventing the execution of a potentially compromised script.

    This approach ensures you always run the approved version of your script. If the script's content at the specified URL changes without a corresponding update to the expected hash in your command, the hash check will fail, and an error will be raised. This is particularly important if there's a potential hostile takeover of the repository hosting the script, as it safeguards against executing tampered code.

    TL;DR This is implemented as a security measure.

  4. Follow On-Screen Prompts: The script will guide you through the necessary steps, asking for confirmations before making any changes.

Important Considerations

  • Modifying disk partitions can lead to data loss. Follow all prompts carefully and ensure you understand the changes being made.
  • This is only intended for simple systems with standard partition layouts.
  • Consult a professional if you encounter errors or have doubts about your system's partition layout.

About

A PowerShell script designed to automate the resizing of the Windows Recovery Environment (WinRE) to fix a Windows Update error.

Resources

License

Stars

Watchers

Forks

Contributors