Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 771  / 2 Years ago, thu, january 27, 2022, 5:08:08

In a system with x identically partitioned HDD's each drive has a UEFI boot partition with the bootable flag set. During power on I'm able to select any of the HDD's to boot from using UEFI.



Once Ubuntu has started. How do I determine which HDD the system was booted from?



An incorrect answer is: The one containing the partition mounted at /boot/efi. It is incorrect as that is written to /etc/fstab when installing Ubuntu. It's not dynamic and does not point to the UEFI partition I actually used to boot.


More From » uefi

 Answers
1

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(EFIBOOTBOOTX64.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.


[#34884] Thursday, January 27, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kneducator

Total Points: 226
Total Questions: 111
Total Answers: 108

Location: Mexico
Member since Sun, Jul 25, 2021
3 Years ago
kneducator questions
Tue, Dec 6, 22, 09:22, 1 Year ago
Sun, Apr 30, 23, 23:26, 1 Year ago
Tue, Jun 8, 21, 01:25, 3 Years ago
Sun, Mar 12, 23, 10:51, 1 Year ago
;