Monday 5 October 2020

agFM v1.61 released (improves UEFI boot support when using .imgPTN23 files)

Taylor contacted me yesterday to ask how to switch back the original E2B partition after successfully managing to UEFI64-boot and switch in a new WinPE .imgPTN23 file.

My answer was to use the BIOS Boot menu to boot to the agFM Partition 2 and then pick the 'Restore E2B partitions' menu option from the agFM menu...

However, it seems the reason that Taylor was having problems, was that his/her Thinkpad T470s BIOS was only listing the first WinPE Partition 1 in the Boot Menu - the 2nd agFM partition was not listed in the boot menu!

No USB UEFI Ptn2 option!
No UEFI Boot option listed for Partition 2!

It seems that the UEFI BIOS only listed the first partition that it found that has a readable (usually FAT) partition and that contains a valid UEFI boot file - in this case \EFI\BOOT\BOOTX64.EFI in the WinPE Partition 1.

The solution was to move the EFI boot file(s) up a level from the \EFI\BOOT folder to the \EFI folder.

How a UEFI BIOS looks for EFI boot files

All UEFI BIOSes should be able to access files on a FAT partition because this is mandatory in the UEFI Specification. Some UEFI BIOSes also include other filesystem drivers. For instance Asus UEFI Firmware often includes an EFI NTFS filesystem driver, so not only can the Asus BIOS UEFI-boot from FAT12/FAT16/FAT32 volumes, but also from NTFS volumes.

Secondly, the default UEFI boot file is always in the \EFI\BOOT folder (unless you have a MAC!), but the filename will depend on the system architecture. For instance, a typical modern PC may contain an x86-compatible CPU and the Firmware will be a 64-bit UEFI BIOS (UEFI64). In this case, the EFI boot file that the BIOS will look for will be named \EFI\BOOT\BOOTX64.EFI. This file will be loaded into memory and executed when selected from the boot menu.

Some systems have a 32-bit UEFI BIOS (UEFI32) - even if they have a 64-bit CPU. In this case, the UEFI boot file will be BOOTIA32.EFI. If the system had an ARM CPU and UEFI32 firmware, it would be looking for and loading a BOOTARM.EFI file - or if it had a UEFI64 BIOS, then it would look for a BOOTAA64.EFI file (don't ask me how they decided on these filenames, it seems very illogical and haphazard to me!).

A UEFI BIOS boot menu should list all 'readable' partitions that contain a valid boot file. So if we want to prevent a BIOS from seeing the first partition as a valid UEFI-bootable partition, all we have to do is make sure that the \EFI\BOOT folder does not contain the EFI boot file that it is looking for.

Of course, the UEFI Firmware can be 'programmed' by an OS or utility to look in different partitions and folders for an EFI boot file, so the BIOS boot menu may well provide other choices (e.g. 'Windows Boot Manager' which may be pathed to boot from a different .EFI file).

agFM v1.61

So there is now a small addition to the agFM initial grub2 boot menu, \boot\grubfm\startup_default.cfg. It will now also list a 'Boot Partition 1' menu entry - but only if the file \EFI\BOOTX64.EFI or \EFI\BOOTIA32.EFI exists on Partition 1.

If you also have the problem of your BIOS not listing the second agFM partition in it's initial BIOS boot menu after switching to a .imgPTN23 file, here is what you need to do:

1. First run \e2b\Update agFM\Download and update agFM_v2.cmd from the 2nd partition of your E2B USB drive to update to v1.61.
2. Ensure all your .imgPTN files are renamed as .imgPTN23 so that partition 2 is preserved when it is switched in.
3. Switch in a .imgPTN23 file (either by booting to E2B or using SWITCH_E2B.exe)
4. Find the \EFI\BOOT folder on the first partition and move the two EFI boot files BOOTX64.EFI (and BOOTIA32.EFI if it exists) up to the \EFI folder. Do NOT move any of the other files!

You should now find that whenever you switch in that .imgPTN23 file, it will first UEFI boot to the agFM menu. The UEFI BIOS boot menu should now only list one USB UEFI boot option which will boot to the agFM grub2 menu.

The SAMPLE_startup_menu.txt file has also been updated, so if you are using a \boot\grubfm\startup_menu.txt file of your own, you may like to add in the extra menu so that you also get the 'Boot Partition 1' menu entry listed in your start menu.

# Hide partition 1 from computer BIOS Boot menu by moving EFI boot file
# If UEFI BIOS does not display agFM partition boot option when switching in .imgPTN23 file
# Move file ptn1:\EFI\BOOT\BOOTX64.EFI up to folder \EFI
# BIOS will then boot to agFM and you can use this menu to UEFI-boot to partition 1
if $EFI64 ; then
if [ -f "(${bootdev},1)/EFI/BOOTX64.EFI" ] ; then 
menuentry "Boot Partition 1 (UEFI64)" --class=uefi {
set grubfm_file="(${bootdev},1)/EFI/BOOTX64.EFI"
grubfm_open "${grubfm_file}"
if $EFI32 ; then
if [ -f "(${bootdev},1)/EFI/BOOTIA32.EFI" ] ; then 
menuentry "Boot Partition 1 (UEFI32)" --class=uefi {
set grubfm_file="(${bootdev},1)/EFI/BOOTIA32.EFI"
grubfm_open "${grubfm_file}"


  1. Ok, Cool
    But there is F3 option in agfm mainmenu,
    which is capable of search and find valid bootable EFI OS in all partitions, So is (F3) method useful to find and boot from partition 1.imgPTN23 EFI file ????

    1. The problem is you cannot boot to agFM if there is a 'valid' EFI boot file on partition 1!