Multiple EFI System Partitions on a single disk

Multiple EFI System Partitions on a single disk

·

4 min read

What is ESP?

EFI System Partition or ESP is a special partition on a disk that contains executables and associated files required to boot up a machine. The executables in this partition are '.efi' files that set up an environment for the rest of the OS to boot. This can be filesystem drivers, USB plugins, ACPI assistance etc. There will be an "EFI" directory within in the ESP that contains the efi executables. Below is the contents of the ESP for Windows 11 operating system.

image.png

The firmware loads the bootx64.efi (because the machine architecture is x64) and jumps to it.

ESPs are small (20 - 300 MB typically) partitions formatted as FAT with a GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B. When the OS finds a partition with this GUID, it chooses to not mount this partition and hides it from the user. The partition can be mounted manually but not recommended unless you need to modify the boot environment.

Disk managers or the OS, when formatting a disk for installation, create a single ESP to hold its boot files. The ESP typically sits at the beginning of a disk. As in, it would be the first partition in the partition map.

It might seem like the ESP is unique to a disk and there can be only one ESP for a disk based on the way the OS treats the ESP. Unlike MBR, on GPT, the ESP doesn't have to be at the beginning of the disk and there can be many ESPs for a single disk. This will allow you to have multiple boot environments with different configurations on a single disk. You can have Debian EFI and Windows EFI on the same disk, isolated from each other, without having to chainload boot executables. You can even have another ESP with some other boot environment like Ventoy on the same disk, allowing you too boot linux live environments without an external storage ( I will write another article on this).

Let's take a look at how you can create ESPs on a GPT disk.

Creating GPT and ESP

*I'm using the BSD flavor of the gpt tool on macOS. The filesystem formatting tools I use are also for macOS. However, the idea remains the same and you can use replacement tools on other operating systems to get the same results. *

First, find the right device location for your device. In my case, it's /dev/disk9 on macOS. Be very careful when performing below operations as it will destroy data on target disk.

image.png

This disk currently has an EFI partition and an ExFAT partition. I'm going to re-create its GPT.
gpt destroy disk9
This will remove the disk's GPT

gpt show disk9

     start      size  index  contents
         0  62333952

The size here is shown in sectors. A single sector is 512 bytes. Now let's create a new GPT.

gpt create disk9
gpt show disk9

image.png

Now we have a GPT. Let's create an ESP of 200 MB
gpt add -b 34 -s 390625 -t C12A7328-F81F-11D2-BA4B-00A0C93EC93B disk9

image.png

-b - beginning sector for the partition
-s - size (count) of the partition in sectors
-t - type of the partition. We have provided the GUID for ESP.

Here, the -b parameter is 34 because the free space begins at 34 as shown by gpt show
-s is 390625 because (390625 * 512 bytes = 200000000 bytes = 200 MB)
The new partition is now available as disk9s1

Now create the filesystem for the partition
newfs_msdos -v "My EFI 1" disk9s1

Let's add a 8 GB partition for some OS files
gpt add -b 390659 -s 15625000 -t windows disk9

image.png

Here, I specified -t as "windows" because exfat, ntfs, fat etc have the same GUID (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7) in GPT.

The new partition is available as disk9s2.
Format the partition as exfat
newfs_exfat -v "OS Files" disk9s2

Now let's create another ESP for another boot environment with 200 MB size
gpt add -b 16015659 -s 390625 -t C12A7328-F81F-11D2-BA4B-00A0C93EC93B disk9

image.png

newfs_msdos -v "MY EFI 2" disk9s3
Notice how I changed -b based on how the beginning of free space changed.

Adding another ESP with 500MB size
gpt add -b 16406284 -s 976562 -t C12A7328-F81F-11D2-BA4B-00A0C93EC93B disk9

image.png

newfs_msdos -v "MY EFI 3" disk9s4

Now I'm going to use the remaining free space to create a partition to hold other files
gpt add -b 17382846 -s 44951073 -t EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 disk9

image.png

newfs_msdos -v "my files" disk9s5

Now on the same disk, there are 3 ESPs and 2 partitions for other files. The ESPs can be loaded with boot files and the other partitions can be filled with OS files or other miscellaneous files. You can create as many ESPs as you want anywhere you want on the disk. You can delete partitions and add ESPs in between, just like you can with regular partitions.