[CentOS] Upgrading (?) from legacy boot to UEFI

Fri Aug 27 10:51:26 UTC 2021
Rob Kampen <rkampen at kampensonline.com>

After three days of effort I have failed to find a way of shifting a 
server from legacy boot to UEFI boot.

I have made my way through the 400+ pages of RH installation manual for 
EL7, plus their similarly large system administrators manual. Dozens of 
pages searched via google and yet none of the layouts for the /boot and 
/boot/efi have worked in my case.

System is a Lenovo 3650 M5 with UEFI bios.

Due to RH / CentOS design my initial install onto the two 600GB HDD 
partitioned these using MBR and legacy boot.

I have just obtained two SAS SSD drives of 3.8TB and thus MBR is no 
longer an option.

I have successfully migrated all the system and data from the HDD to the 
SSD, complete with GPT and RAID1 and all works as expected - except the 
HDD was still needed to boot the system.

That's when the fun / agony started. Each system reboot is almost five 
minutes just to get to the <F1> for system setup option. Thus testing is 
a very slow process.

I am now at the point where I have a "bios boot" partition (1024K type 
ef02) as the first partition on each GPT partitioned SSD and have 
grub2-install onto the drives the bios boot junk needed for legacy boot.

Thus I can at least legacy boot from one of the SSD and all comes up as 
expected. (no idea yet why it only works from one of the SSD and not the 

Unfortunately the server is remote and the CentOS7 USB device I left 
plugged into the machine refuses to boot from UEFI mode. Thus a rescue 
mode boot has not been possible.

I have two 300MB partitions, one on each SSD suitably formatted (type 
ef00 and vfat) and set up with the files as follows:

-rwx------. 1 root root      134 Aug  1  2020 BOOT.CSV
-rwx------. 1 root root      134 Aug  1  2020 BOOTX64.CSV
drwx------. 2 root root     4096 Aug 27 16:22 fonts
-rwx------. 1 root root     6597 Aug 27 21:33 grub.cfg
-rwx------. 1 root root     1024 Aug 26 23:22 grubenv
-rwx------. 1 root root  1122120 Mar 17 07:24 grubx64.efi
-rwx------. 1 root root 19378672 Aug 26 20:29 initramfs-3.10.0-1160.36.2.el7.x86_64.img
-rwx------. 1 root root  1154640 Aug  1  2020 mmx64.efi
-rwx------. 1 root root  1154640 Aug  1  2020 MokManager.efi
-rwx------. 1 root root  1243864 Aug  1  2020 shim.efi
-rwx------. 1 root root  1237824 Aug  1  2020 shimx64-centos.efi
-rwx------. 1 root root  1243864 Aug  1  2020 shimx64.efi
-rwx------. 1 root root  6777448 Aug 26 20:27 vmlinuz-3.10.0-1160.36.2.el7.x86_64.efi

unfortunately grub2-mkconfig sets up the grub.cfg as for legacy boot 
because the /sys/firmware/efi does not exist, thanks to running from a 
legacy boot.

I tried a few manual edits to the grub.cfg to deal with linux16 -> 
linuxefi and initrd16 -> initrdefi but to little avail.

Can someone point me to what needs to happen for UEFI boot to work 

I am unsure what file I need to point the UEFI bios disk manager setup 
at, I have tried shim.efi and shimx84-centos.efi

The message I get is that linux16 and initrd16 cannot find their files. 
The change to linuxefi and initrdefi also fail but the system reboot 
happens before I can see what flashes on screen.

Is a USB based UEFI booted rescue mode the only way I can fix this?

TIA for your pointers / suggestions.