ESP and GRUB instalation
The aim is to install Debian using debootstrap. First I want to install all system on a small 32GB flash disk.
And concepts of GPT partition tables and GRUB is quite clear: There is a table of partitions. Each partition has uniq ID. Further on each partition a filesystems created. FileSystem itself is the way to store files, journal, dirs and so on, it is a DataSturture.
Now there is a ESP. A partition where the BOOTLoader is stored. And it must be FAT32 is not it?
Now I need to get kernel, ramdisk. Create a ESP on a FlashStick. And install GRUB so it going to be on the ESP and select appropriate Kernel and Ramdisk. And here I am stuck.
- How to create ESP? Is it a simple partition that further formated to FAT32?
- How to tell GRUB where to be installed? How to configure it? I know about
grub-mkconfig– and I know that need to set linux and initrd but still a little bit confusing.
So here a problems begins.
How to connect ESP with a rest of FileSystem?
How kernel knows where to search for all files and configurations?
That jump from starting GRUB and starting kernel passing parameters and mounting ESP into FileSystm looks weird and awkward.
How to create ESP? Is it a simple partition that further formated to FAT32?
Yes, it is a simple partition, formatted to FAT32 (newer UEFI versions may accept other forms of FAT too), and the partition type UUID of a GPT-style partition table set to indicate it’s an EFI System Partition (or ESP for short). If you are booting UEFI-style from a MBR-partitioned disk, the partition type code of the ESP should be set to
0xef instead of a regular FAT32 partition type code.
How to tell GRUB where to be installed? How to configure it?
To install GRUB, the
grub-install command is used. It takes as a parameter the device name of the disk or partition to where GRUB should be installed.
If there is only one ESP on the disk (as is generally recommended), you can just specify the whole-disk device, e.g.
/dev/nvme0n1, just like you would do when installing a legacy BIOS-style GRUB. It will automatically find the ESP and write
grubx64.efi in there, and also register it into UEFI NVRAM firmware variables (which you can view with
If you are installing to a removable flash disk, you should also specify the option
grub-install. If the disk is not removable as such, but you plan to move or clone it to another system, you should probably use the
--force-extra-removable option instead.
Once GRUB is installed,
grub-mkconfig – or a Debian-specific
update-grub wrapper for it – can be used to create a GRUB configuration file.
In Debian, the standard mount point for the ESP is
/boot/efi. Other distributions may do things differently.
When the system is booting UEFI-style, the firmware will first check its NVRAM boot variables for a boot order. A UEFI-style boot variable will specify a device, the ESP partition on it (identified primarily by the unique PARTUUID of the ESP), and a boot file to use within that ESP. In the case of a permanently-installed Debian distribution, the boot file pathname will be (Windows style, like the firmware will usually represent it)
EFIdebianshimx64.efi if a Secure Boot compatibility is also desired and the
grub-efi-amd64-signed packages have been installed.
If there is no boot variable (e.g. because a removable media was selected for booting), a 64-bit x86 UEFI system will look for a pathname (in Windows style)
EFIBOOTBOOTx64.efi. If GRUB was installed using the
--force-extra-removable options, this will actually be a copy of
So, the firmware will start GRUB, and then GRUB will read
EFIdebiangrub.cfg from the ESP. It will normally contain just a
search command that will tell GRUB to find whatever partition contains
/boot/grub using its UUID, and then the commands required to read
/boot/grub/grub.cfg from there. (Depending on how the system is set up, this could refer to the root filesystem, or a separate
/boot filesystem – either way is fine.)
After reading the real configuration from
/boot/grub/grub.cfg, GRUB will know where to find the kernel and initramfs files, and what menu items to present to the user. GRUB will then load the selected kernel and initramfs files, pass the specified kernel boot options to the kernel command line, and then it will start the kernel. At this point, the boot-time jobs of GRUB, the ESP, and the
/boot directory are all done – from this point onward, the boot can proceed without them.
The kernel will find the root filesystem based on the
root= kernel boot option and any scripts within the initramfs, and once the root filesystem is located, checked (if necessary) and mounted, the boot process will be able to access the real
/etc and proceed according to the information found in there.
At boot time, the kernel will never need to access
/boot nor the ESP – when the kernel starts up, the bootloader and the firmware will have already read all they need from there. The ESP is mounted to
/boot/efi only to allow for easy updates of the bootloader and its configuration. If you plan to never do that (e.g. in an embedded appliance system that will receive any updates by a total reimaging), you could leave the ESP completely unmounted.