I've not tested this experimentally, so it may not work in practice, but the efibootmgr
utility does return a variable called BootCurrent
that should identify the boot loader that the EFI launched. For instance:
$ sudo efibootmgr -v
BootCurrent: 0001
Timeout: 3 seconds
BootOrder: 0000,0001
Boot0000* EFI DVD/CDROM ACPI(a0841d0,0)PCI(14,1)ATAPI(0,1,0)
Boot0001* OsLoader0000 ACPI(a0841d0,0)PCI(11,0)03120a00000000000000HD(1,800,5ede2,2c47c282-ee6e-45de-a5ad-e8658ca67de6)File(\EFI\BOOT\BOOTX64.EFI)
This output indicates that the system was booted via entry 0001 (Boot0001
). The -v
option to efibootmgr
used here adds verbose information, which includes the GUID of the partition on which this boot loader was stored -- 2c47c282-ee6e-45de-a5ad-e8658ca67de6 in this case. Note that this is a partition GUID, not a filesystem UUID. AFAIK, the only way to extract partition GUID data in Linux is via gdisk
, cgdisk
, or sgdisk
. For instance:
$ sudo sgdisk -i 1 /dev/sda
Partition GUID code: C12A7328-F81F-11D2-BA4B-00A0C93EC93B (EFI System)
Partition unique GUID: 2C47C282-EE6E-45DE-A5AD-E8658CA67DE6
First sector: 2048 (at 1024.0 KiB)
Last sector: 390625 (at 190.7 MiB)
Partition size: 388578 sectors (189.7 MiB)
Attribute flags: 0000000000000000
Partition name: 'EFI System'
Note the Partition unique GUID
line, which matches the value included in the efibootmgr
output (aside from case, which varies). Given the input to sgdisk
in this example, it means that partition 1 on /dev/sda
(that is, /dev/sda1
) held the system's first boot program. You may need to scan all your partitions, or at least all the ones on which EFI boot loaders might be present, to be sure of finding a match. Even then, you might not find a match -- for instance, if the boot loader was on a USB flash drive that's since been removed from the computer, or if you've changed the partition's GUID.
Based on my check on the system at which I'm sitting, it appears that the efibootmgr -v
output reports the boot loader program that the EFI launched. This may not be the same as the one that launched Linux, since the program the EFI launched may have been a boot manager that in turn launched another boot loader. If your system's boot process is simple, this may not matter; but if your boot process includes the possibility of cross-disk redirection, this technique won't be reliable.