HiddenRecoveryPartition
A Windows recovery partition solution that enables automatic operating system backup and restore functionality using a hidden recovery partition. This solution leverages Microsoft Deployment Toolkit (MDT), Windows PE, and Windows Recovery Environment (WinRE) to create a Dell/HP/Lenovo-style factory reset capability for custom Windows deployments.
This solution creates a hidden recovery partition that stores a complete Windows image backup. When triggered (via boot key or automatic recovery), the system boots into Windows PE and either:
- Creates a recovery image of the current OS installation
- Restores the OS from a previously created recovery image
- Hidden Recovery Partition: Uses partition type
0x27(MBR) or GUIDde94bba4-06d1-4d40-a16a-bfd50179d6ac(GPT) to hide the recovery partition from Windows - Boot Key Support: Configure a function key (F1-F12) to boot directly into recovery mode
- Dual Architecture: Supports both x86 and x64 Windows installations
- Legacy and UEFI Support: Automatically detects BIOS mode and adjusts recovery operations accordingly
- Automatic Detection: Can detect newer recovery scripts from optical media for updates
- Microsoft Deployment Toolkit (MDT) with Generic Windows PE boot images generated
- Windows Assessment and Deployment Kit (ADK)
- Administrator privileges on the target system
- A disk layout with:
- Partition 1: Recovery partition (labeled "RECOVERY")
- Partition 2: OS partition (labeled "OS")
- Optional: Data partition (labeled "DATA")
HiddenRecoveryPartition/
├── Diskpart/
│ ├── 0x27.txt # DiskPart script to set partition type 0x27 (MBR)
│ └── de94bba4-06d1-4d40-a16a-bfd50179d6ac.txt # DiskPart script for GPT
├── HiddenRecoveryPartition/
│ ├── ConfigureRecoveryPartition.vbs # Configures Windows Recovery Agent
│ ├── ModifyGenericWindowsPE.vbs # Customizes MDT boot images
│ └── WindowsPE/
│ ├── x64/ # 64-bit PE resources
│ │ ├── Scripts/
│ │ │ ├── Initialize.vbs # PE startup script
│ │ │ └── Recovery.vbs # Main recovery logic
│ │ ├── Tools/ # Architecture-specific tools
│ │ ├── Unattend.xml # PE automation config
│ │ └── Windows/ # Additional Windows components
│ └── x86/ # 32-bit PE resources (same structure)
└── README.md
Run ModifyGenericWindowsPE.vbs to customize the MDT generic boot images with recovery scripts:
cscript.exe "HiddenRecoveryPartition\ModifyGenericWindowsPE.vbs"This script will:
- Prompt you to select your MDT Deployment Share
- Mount the Generic_x86.wim and Generic_x64.wim boot images
- Copy the recovery scripts and tools into the WIM files
- Commit changes and output the modified images to
{DeployShare}\Custom\HiddenRecoveryPartition\Output\
After deploying Windows to a machine with the appropriate partition layout, run:
cscript.exe "HiddenRecoveryPartition\ConfigureRecoveryPartition.vbs" /Bootkey:"F11"The /Bootkey parameter is optional. Supported values: F1, F2, F3, F4, F6, F7, F9, F10, F11, F12
This script will:
- Assign a drive letter to the recovery partition
- Copy the recovery environment files (Winre.wim, boot.sdi)
- Configure the Windows Recovery Agent (reagentc.exe)
- Remove the recovery partition drive letter
- Configure BCD to ignore minor boot failures
diskpart /s "Diskpart\0x27.txt"diskpart /s "Diskpart\de94bba4-06d1-4d40-a16a-bfd50179d6ac.txt"Note: These scripts target Disk 0, Partition 1. Modify if your layout differs.
Sets the partition type to 0x27 (OEM Recovery Partition), which hides it from Windows Explorer.
Sets the partition GUID type and applies GPT attributes to hide and protect the partition:
- GUID:
de94bba4-06d1-4d40-a16a-bfd50179d6ac(Windows Recovery Environment) - Attributes:
0x8000000000000001(Required partition + No drive letter)
- Trigger Recovery: Boot using the configured function key or through Windows Recovery options
- Windows PE Loads: The hidden recovery partition boots into Windows PE
- Initialize.vbs Runs: Checks for updates on optical media, then launches Recovery.vbs
- Recovery.vbs Executes:
- Detects BIOS mode (Legacy/UEFI)
- Locates the RECOVERY, OS, and DATA partitions
- If no recovery image exists: Creates
Install.wimfrom the OS partition - If recovery image exists: Prompts user to restore with confirmation
| Key | Scan Code |
|---|---|
| F1 | 0x3b00 |
| F2 | 0x3c00 |
| F3 | 0x3d00 |
| F4 | 0x3e00 |
| F6 | 0x4000 |
| F7 | 0x4100 |
| F9 | 0x4300 |
| F10 | 0x4400 |
| F11 | 0x8500 |
| F12 | 0x8600 |
Note: F5 and F8 are reserved by Microsoft and cannot be used.
The solution expects specific volume labels:
- RECOVERY: The hidden recovery partition containing WinRE and recovery images
- OS: The main Windows operating system partition
- DATA: Optional data partition (preserved during recovery)
- Recovery partition not detected: Ensure the volume label is exactly "RECOVERY"
- Boot key not working: Verify reagentc is properly configured:
reagentc /info - WIM mount failures: Run
dism /cleanup-wimto clear stale mount points - Architecture mismatch: Ensure you're using the correct x86/x64 boot image for your OS
See LICENSE for details.