web analytics
Press "Enter" to skip to content

Expanding C Drive on Azure VM when MBR Partition is at the end

Lars Fiedler

By default, the C drive on an Azure VM  is only 127 GB. Usually after a few programs are installed and perhaps a Sql Database is setup, you’re on your way to filling up the hard drive. After running the machine for a few weeks you’ll also notice Azure logs start to build up on your drive, and pretty soon you’re out of disk space.

So increasing the C drives diskspace should be a piece of cake right? After all, this is why we’re all paying big dollars for Azure’s convenience right? Wrong. Some of Azure’s VMs actually have the System Reserved / Master Boot Record partition at the end of the drive, rather than the beginning. Why would Microsoft create VMs with the MBR at the end? I have no idea, and it makes no sense to me, but below is how to fix it, and a reference to this article for more details.

Upon looking at the C drive in Disk Management, you’ll notice a very small active partition after your C drive. DO NOT delete this partition. We must take the contents of this active boot partition and move it to the C drive, then we can delete it, and make room to extend the C Drive partition.

 

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
Lars Fiedler
Latest posts by Lars Fiedler (see all)