Moving EFI partition before C:

Moving EFI partition before C:

So a coupple of months ago we activated UEFI boot on our Templates in our Nutanix Environment to be able to benefit from Secure Boot and vTPM witch was newly introduced to the Nutanix platform, and as a step to enable UEFI boot we need to convert the disks to GPT using the MBR2GPT.exe cmdlet in windows.

One sideaffect with enableing this on a already running system is that windows is totaly rubbish in placeing the EFI partition and the EFI partition is created right behind the C: (system partition).

The problem is, as you can see, if we want to expand the C: volume because of growing windows updates etc, nutanix adds space in the end of the disk. We cant perform that operation due to the EFI partition is in a wierd place.

So, this is what i came up with, follow along.

  • Open a CMD window as administrator.
  • Open Diskpart.

  • Run the following commands
// Select the disk, usaly disk 0 but to be sure, use list disk:

list disk

//You sould se all your disks, select the disk containing the Windows installation:

select disk 0

//Now we need to figure out what partition id the C: drive have by using the command list partition:

list partition

//Select the partition containing the C: in this case it was partition 2:

select partition 2

//Shrink the size of partition 2 with 100mb by typeing:

shrink desired=100

//Now you sould have a 100MB of unallocated space right after the C: if you take a look in disk manager. 
Diskpart commands with comments
  • Now mount the Live-ISO for the tool gParted (can be downloaded here)
  • Shutdown the server. Take a snapshot (just in case)
  • Power on the server
  • Follow the onscreen instructions to boot in to the GUI of gparted.
  • Select the partition that contains C: and klick "resize/move"
  • You should se that there is 100MB of unallocated space right after the partition. and 0MB of space infromt of the C: partition.
  • Set that you want 100MB of space before the C partition and 0MB of space after the partition.
  • Click Apply
  • Click The green checkmark in the ribbon in top of the window
    The progress of moving the partition 100MBs to the right starts
gParted move initiated
  • Once done, eject the gParted ISO and reboot the machine, it will now boot in to windows again. Run CMD as administrator and open DISKPART just as you did in the previous step.
  • Run the following commands in DISKPART
//First we select the disk:

select disk 0

//Then we create a new efi partition with the command:

create partition efi size=100

//Make sure that that partition is selected by running: 

list partition

//If its not, select the partition by running select part <nr of newly created partition>, otherwise continue by formatning the partition with fat32 by running the command:

format quick fs=fat32

//Once the format is done, assign a letter to the disk by running:

assign letter=X

//exit diskpart by running:

exit
  • Now you should have an EFI partition right before the C: partition. Now we need to move the Windows boot files in to this EFI partition by doing the following in a CMD windows (opened as administrator)
bcdboot C:\Windows /s X:
  • The boot files should be writen to the new EFI partition.
  • Reboot the server.
  • After the reboot, you sould now be able to delete the old EFI partition by running the below commands in diskpart:
//First we need to select the disk by running:

select disk 0

//Then we need to list the partitions in order to se what partition the old EFI partition have:

list partition

//In this case it was partition 5, lets select that:

select partition 5

//Then delete the partition by running:

delete part OVERRIDE

//Now the old EFI partition is deleted, lets extend C: to take up that extra space. To do this, we need to list the volumes:

list volume

//Examine the output, and in my case C: was Volume 2, so lets select that volume:

select volume 2

//Now, lets expand that disk:

expand 
  • You're now done, and you sould have the following layout:
ℹ️
A few things to consider, if you prior to creating the new EFI partition have unallocated space after the OLD EFI Partition, you need to allocate that space with a dummy partition, otherwize diskpart will create the new EFI partition right after the OLD EFI partition. Alltough you have 100MB of unallocated space before the C: Volume/Partition.

Thanks for reading :)