Booting EFI

Booting EFI

Last days I told myself I need to take a look at UEFI booting process since it became standard and knowing legacy process (and MBR) is not enough when dealing with troubleshooting processes.

EFI partition has to be formatted in FAT32 filesystem and GPT partition table. Usually this partition is mapped to /boot/efi. So first you need to create new partition and make filesystem on it.

mkfs.fat -F32 /dev/sdb1

Than copy the original /boot/efi directory there and create a record. First we can list current efi boot table.

efibootmgr -v
efibootmgr --create --disk /dev/sdb1 --label "My EFI_boot" --loader /EFI/centos/grubx64.efi

To change the order and records you can with commands below:

efibootmgr -o  3,1,2,0
efibootmgr -Bb 6

Other things when making a filesystem boot stays the same like in legacy. Mount /dev, /proc, /sys to the copied filesystem, chroot into it and make grub2-mkconfig. Check the partition, edit /etc/fstab and don’t forget to replace linux{16}, or initrd{16} with linuxefi and initrdefi keywords. Than you are done and system should be booting.

If you end in the EFI shell you can navigate simalarly like in grub. „cd“ to the correct boot directory and then run the correct „*.efi“ file.

PS Regenerating initramfs:

When you want to boot another kernel as the one which was deployed during the installation you need to copy underlying kernel files from /boot directory, „/lib/modules“ directory and than regenerate initramfs. Default behavior in centos 7 is that it generates „–host-only“ ram filesystem, so in case of any troubles us „-N“ switch and check if all needed rd were regenerated. The system should than boot other kernel as well.

dracut -vf --regenerate-all