How to Extend C: Drive of Windows Server 2012 R2 Virtual Machine in Azure

How to Extend C: Drive of Windows Server 2012 R2 Virtual Machine in Azure

By John Shen

Creating Virtual Machines in Azure using Windows Server 2012 R2 is a very good option to get a flexible platform with many different uses, that will easily integrate with on-premises hardware. When created, however, disk size is defaulted to a 128GB C: drive that cannot be easily expanded, despite being cloud hosted. While this size is suitable for most use cases, many needs may require more storage.

We recently found ourselves facing this issue when a customer requested an increase to the size of their C: drive from the default 128GB to 1TB. Many online guides provided the right PowerShell script, which increased the server’s capacity to the desired amount:

PS C:\> Update-AzureDisk -DiskName TinyVM-TinyVM-0-201507181508090740 -ResizedSizeInGB [DESIRED NUMBER OF GB, NO BRACKETS OR UNITS] -Label TinyVMOS

 

We then ran into a new problem: the new space was not added into the C: drive. This is because a hidden partition labeled Windows Recovery was effectively blocking the allocation of storage to the C: drive.

This relatively small partition contains the files needed to boot the server, acting as a failsafe against C: drive failures. Due to this, it cannot simply be deleted. Using a little known trick in Windows 8/10, however, we are able to delete this partition and allocate our new storage to the C: drive. In this guide, we’ll go through the steps we took to do this.


Please be advised that any changes you make to your server should be performed at your own risk. Performed incorrectly, the below actions can result in irreparable harm to your cloud server, and should only be attempted by an IT professional.


Backup the Virtual Machine

  1. Due to the risks associated with the actions described in this guide, we recommend that you first backup your VM as a precaution against any potential errors
    1. Steps to backup an Azure VM can be found in Microsoft's documentation for Azure.
    2. Be sure to set the backup frequency to an interval that will not result in any replication while the C: drive extension process is occuring

Make the Windows Recovery Partition Visible

  1. Open the Run command bar by typing WindowsKey + R, and enter diskmgmt.msc into the text line to open the Disk Manager tool
  2. Right click the System Reserved partition and choose the Change Drive Letter and Paths… option
    1. For the sake of this guide we will use the letter X:
  3. Click the Add button to create a new drive letter
  4. Choose an available drive letter and select OK
  5. Open Windows Explorer without closing out the Disk Management window
  6. Confirm the addition of the new drive letter and close the window

Disable the Recovery Environment:

  1. Begin an Administrator mode command prompt
    1. In the search bar, type “CMD” to open command prompt
  2. Disable the recovery environment within the system reserved partition by typing: reagentc /disable
    1. You will want to confirm the successful movement of the winre.wim file to the Recovery folder. Use the following directory path to confirm the location: C:\Windows\System32\Recovery
    2. Alternatively, the location can be confirmed by typing dir /a C:\Windows\System32\Recovery into the command prompt

Copy Boot Files into the C: Drive

  1. Unload the BDC Registry Hive by typing the following command into the Command Prompt: Reg unload HKLM\BCD00000000
  2. Copy bootmgr file from the System Reserved partition into the Windows partition by using the following command: robocopy x:\ c:\ bootmgr
  3. Copy the boot folder form the system reserved partition into the Windows partition with command line: robocopy x:\boot c:\boot /s
  4. At this point all bootable files should be copied into the Windows partition, confirm this by running command prompt: dir c:\ /ah
    1. This command will produce a list of files. If bootmgr and the boot folder are included the list, the move was completed successfully.
  5. In order to boot properly, the boot files must be updated to work within the Windows partition. This is accomplished with a few more command lines:
    1. Update the BCD file: bcdedit /store c:\boot\bcd /set {bootmgr} device partition=C:
    2. Update the Memory Diagnostics entry: bcdedit /store c:\boot\bcd /set {memdiag} device partition=C:

Remove the System Reserved Partition

  1. Now that the files have been successfully copied, we can remove the Drive letter assignment we gave the System Reserved partition earlier
    1. Bring up the Disk Management window.
    2. Right click the System Reserved Partition and select Change Drive Letter and Paths...
    3. Click the Remove option, and then Yes to confirm
  2. Now that the Drive letter has been removed we will set the Windows partition as the Active (Booting) partition.
    1. In the Disk Management windows, right click the Windows partition, and select Mark Partition as Active
    2. Select Yes to confirm the action.
  3. Restart the server
  4. Reopen the Command Prompt
  5. Enable the Windows Recovery Environment buy entering the following command line: reagentc /enable
  6. Open Disk Management
  7. Right click the System Reserved partition and select the Delete Volume... option and confirm the action

Add "Unallocated" space to the C: Drive

  1. In the Disk Management window, right click the C: drive and select the Extend Volume... option
  2. In the window that pops up, click the number that appears in the Available: box.
  3. Click Add
  4. From that number, select the amount you wish to allocate to the C: drive
  5. Click Next and Finish

Congratulations! You have successfully extended the C: drive of your server!


OD4BVSPOCTA
 

Interested in more guides like this?

Sign up for our blog and get all our latest posts sent directly to your inbox!








1 Comment

  1. Thank you. This worked perfectly very useful and simple to follow

Leave a comment!

All fields marked with an asterisk* are required.