3

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.

2 Answers 2

2

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.

4
  • Pretty cool findings! I'll look into this more tomorrow. Also, to find out partitions UUID's the blkid command (if you have it) is another option.
    – Deleted
    Oct 21, 2012 at 4:30
  • 1
    As I specifically stated, a partition GUID is not the same thing as a filesystem UUID. There's no such thing as a "partition UUID." The blkid command returns the filesystem UUID, so it won't help with this task -- at least, not in conjunction with efibootmgr.
    – Rod Smith
    Oct 21, 2012 at 16:37
  • Ah, sorry, I missed that when I read it casually. :-) I intended to read it again (now) when trying it out.
    – Deleted
    Oct 22, 2012 at 15:33
  • Because I was wondering, and somebody else might be too: efibootmgr -v may print some info like this: HD(<partition number>,<start sector [hex]>,<size [hex]>,<partitions unique GUID>)
    – Jook
    Aug 24, 2014 at 11:16
0

Once Ubuntu has started, and if grub-efi has been installed in several disks, I think you can't. (it is the same problem as with Legacy/mbr boot, AFAIK it wasn't possible to determine from which mbr the pc had started if grub was installed in several MBRs)

1
  • I was afraid so. I'll leave the question for a week and see if someone else steps in. Otherwise I'll mark your answer as correct! Thanks for helping out!
    – Deleted
    Oct 19, 2012 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .