I recently spun up a Windows 11 virtual machine in VirtualBox to test various scripts before posting them here to the site. Initially, I provisioned the VM with a 20GB C:\ drive, figuring that would be plenty of room for basic testing.
I was wrong.
This morning, I noticed the disk was crying for help, showing only a few hundred megabytes of available space. It was clear I needed to expand my virtual disk. I was pretty sure I already knew the drill for VirtualBox, so I powered down the VM and got to work.
Here is the standard process for expanding the disk, the unexpected roadblock I hit inside Windows, and the custom PowerShell script I wrote to solve it.
Part 1: The Standard Method (Expanding the Disk in VirtualBox)
If you just need to expand your virtual disk and don’t have any partition layout issues, this two-step process is usually all it takes.
Step 1: Expand the Virtual Disk Container
⚠️ CRITICAL WARNING: Ensure your virtual machine is completely powered off and that you have deleted any existing snapshots. Resizing disks with active snapshots can cause severe data corruption.
- Open the Oracle VM VirtualBox Manager.
- Navigate to File > Tools > Media.
- Select the
.vdifile of your Windows virtual machine from the list. - At the bottom of the window, drag the Size slider or type in your newly desired capacity.
- Click Apply.
Step 2: Extend the Partition Inside Windows
Now that the virtual disk container is physically larger, you have to tell Windows to actually utilize that extra “unallocated” space.
- Boot up your Windows VM.
- Right-click the Start button in your taskbar and select Disk Management.
- Locate your primary system drive (usually
C:). You should see the newly added space right next to it, labeled as Unallocated. - Right-click your main Windows partition and select Extend Volume.
- Click Next through the Extend Volume Wizard, ensure the maximum available space is selected, and click Finish.
Under normal circumstances, you’re done. However, this is exactly where I ran into a wall.
The Roadblock: The Stubborn Recovery Partition
When I opened Disk Management, I could plainly see the 10GB of unallocated space I had just added. But when I right-clicked on my existing 20GB C: drive, the Extend option was grayed out.
The culprit? The Windows Recovery Partition.
Windows requires unallocated space to be directly adjacent (to the right) of the partition you want to expand. In my case, the Recovery Partition was sitting squarely between my C:\ drive and my new 10GB of free space. Even worse, right-clicking the Recovery Partition only yielded a “Help” option—Windows intentionally locks this partition down to prevent you from breaking the Recovery Environment.
I knew the solution: I needed to delete the recovery partition, extend my C: drive into the new space, and then carve out a new recovery partition at the absolute end of the disk. I wanted to do it all cleanly, and I wanted to do it via PowerShell.
The Solution: RecoveryPartitionManager.ps1
To fix this—and to make sure I never have to manually wrestle with diskpart or reagentc to fix this issue again—I wrote RecoveryPartitionManager.ps1.
This script is an interactive, menu-driven PowerShell utility designed to safely and cleanly manage Windows recovery partitions. It takes the risk and guesswork out of modifying core disk structures.
Core Capabilities
- Interactive Menu System: Provides a clean console-based UI, so you don’t have to memorize complex disk management commands.
- Disk & Partition Auditing: Scans and lists your current physical disks and partition layouts so you know exactly what environment you are working in.
- Deletion & Cleanup: Identifies and securely deletes existing recovery partitions (especially handy for undersized, corrupted, or duplicated ones).
- Automated Provisioning: Safely shrinks your primary OS drive (
C:) by a custom, user-defined size to carve out unallocated space, then formats and mounts a fresh recovery partition.
Safety & System Integration
- Admin Verification: The script forces an administrative privilege check at launch. It will refuse to run unless executed in an elevated PowerShell session.
- Data Loss Guardrails: Includes explicit safety disclaimers and robust error handling to prevent the accidental wiping of your active Windows partition.
- GPT Attribute Tagging: After creating the new partition, the script automatically applies the correct GUID and GPT attributes (such as the
0x8000000000000001flag). This ensures Windows correctly recognizes the volume as the official Windows RE (Recovery Environment) and hides it from appearing as a clunky, usable drive letter in Windows Explorer.
Download the Script
If you are stuck behind a stubborn recovery partition, you can grab the script directly from my public GitHub repository:
🔗 Download RecoveryPartitionManager.ps1 on GitHub
Note: Because this script modifies core Windows partitions, it goes without saying: You must run this in an Administrative PowerShell prompt.