2

I'm doing an ssh to a PC that no one can actually physically reach, yet. Said PC was made after 2011, so it defintely has UEFI.

The issue is that every posts on the web is about checking if the PC has a UEFI or BIOS (e.g. How to know if I'm booting using UEFI?), which is not what I'm trying to find out.

 

My question is then pretty simple: How do I tell if a PC with UEFI, booted with CSM/Legacy/BIOS Mode enabled or not ?

 

Update 1: There's lot of ways to tell if it's UEFI or not, but none of them can definitely tell since they all contradict themselves.

Details:

  • The drive is MBR
  • There's no sign of an ESP partition at all (fstab, etc)
  • There's no sign of EFI files on /boot at all
  • cat /sys/firmware/efi/fw_platform_size gave 64, which wouldn't work at all if it was in CSM Mode on another PC.
  • update-grub gave Adding boot menu entry for EFI firmware configuration
  • efibootmgr gave me a boot order, which usually shows when there's a UEFI.
X.LINK
  • 1,288
  • 9
  • 18
  • 1
  • Do you know what keywords I must look after ? – X.LINK Jun 25 '21 at 12:09
  • @Freddy: This is the kind of posts that didn't helped. It's more about if your PC has UEFI or BIOS only, instead of if I'm using CSM mode on a UEFI motherboard or pure UEFI mode. I do have the `/sys/firmware/efi/*` folders, that still doesn't tell me if I'm running CSM mode or not. – X.LINK Jun 25 '21 at 13:38
  • 2
    If ssh'd does this show that system? Check UEFI boot mode `[ -d /sys/firmware/efi ] && echo EFI || echo Legacy` You can also look at ESP, if you have ESP with /EFI/ubuntu folder it probably is UEFI. If drive is gpt partitioned and no bios_grub for BIOS boot, only an ESP it is UEFI. And does fstab show mount of ESP- efi system partition. – oldfred Jun 25 '21 at 15:19
  • @oldfred Ok that's weird, the command clearly says `EFI`, but there's no ESP partition nor `/boot/EFI` folders at all on the drives for sure. – X.LINK Jun 25 '21 at 15:22
  • Even with SSH, it may be showing your system? Having ESP & mount of ESP in fstab would then be main indicators. Is drive gpt or MBR? But Ubuntu will let you install Ubuntu to MBR drive in UEFI mode (and probably should not like Windows). And you an boot Ubuntu in BIOS mode from gpt ( I have since 2010). – oldfred Jun 25 '21 at 17:35
  • @oldfred 100% sure it's not showing my system. fstab didn't snow any sign of ESP partition and the drive is MBR. I've updated my post and added more details. – X.LINK Jun 29 '21 at 00:01
  • Show us `gdisk -l /dev/sdX` (where sdX is your actual device), rather than simply stating that the disk is MBR. The presence of ESP is not signified by the presence of relevant mount points or fstab entries. You can well omit the ESP mount point and fstab entry altogether and still have a working system. It is *only* signified by the presence of actual partition. There is a possibility to have both partition tables at once, and it is even possible make it so the ESP will be presen in GPT and not present in the MBR, while other partitions agree in both tables. So just show us what gdisk says. – Nikita Kipriyanov Jun 29 '21 at 09:28

4 Answers4

1

Seems reasonable to try:-

dmesg | grep efi: which will produce sensible output for an efi boot.

Jeremy Boden
  • 1,290
  • 11
  • 21
  • This command returned: `[ 0.000000] efi: EFI v2.70 by American Megatrends [ 0.000000]` `efi: ACPI 2.0=0x9b233000 ACPI=0x9b233000 SMBIOS=0x9b8b4000 SMBIOS 3.0=0x9b8b3000 MEMATTR=0x95de1198 ESRT=0x97aca418` Would these `SMBIOS` values tells that I'm running on CSM mode on a UEFI motherboard ? I'm tempted to say yes, but I'm still unsure. – X.LINK Jun 25 '21 at 15:08
  • 1
    Well, I get the same values - efi: EFI v2.70 by American Megatrends; efi: ACPI 2.0=; SMBIOS 3.0= (different addresses) and I know I have an efi boot and I did a fresh install to an empty NVME device only 3 months ago. – Jeremy Boden Jun 25 '21 at 15:34
  • Run the efibootmgr command - without any parameters it will show your efi boot order. – Jeremy Boden Jun 25 '21 at 15:36
  • Here's the order: `HDD`, `UEFI: USB key`, `USB Key` I see where we're going, if a USB key got its UEFI way of booting first vs its "BIOS" mode of booting, this would mean that it's in UEFI mode right ? But there's a catch: I don't have any ESP partition or `/boot/EFI` on the HDD. Which makes everything weird. – X.LINK Jun 25 '21 at 15:55
  • The lack of the ESP partition looks pretty damning. – Jeremy Boden Jun 25 '21 at 16:22
  • As per Artem S. Tashkinov answer and my comment, `cat /sys/firmware/efi/fw_platform_size` gave me `64` on the ssh'd PC, even if I don't have the ESP partition. – X.LINK Jun 25 '21 at 17:03
1

I've found nothing in dmesg which indicates that the system has actually booted in EUFI mode as opposed to BIOS/CSM but here's a way to be absolutely sure:

Run sudo efibootmgr, if it complains EFI variables are not supported on this system then try sudo mount -t efivarfs none /sys/firmware/efi/efivars.

If you succeed, you'll see something like this:

$ sudo efibootmgr 
BootCurrent: 0002
Timeout: 1 seconds
BootOrder: 0002,0000,0001,0003,0004
Boot0000* Windows Boot Manager
Boot0001* UEFI:CD/DVD Drive
Boot0002* Fedora
Boot0003* UEFI:Removable Device
Boot0004* UEFI:Network Device

And even without this, I guess

# show the bitness of the internal EFI firmware
cat /sys/firmware/efi/fw_platform_size

could be enough.

Artem S. Tashkinov
  • 26,392
  • 4
  • 33
  • 64
  • Managed to get a laptop that does 64 bit UEFI, CSM mode and have an ESP partition, and a chinese PC that only do 32 bit UEFI. In CSM mode, `/sys/firmware/efi/*` is missing and trying to mount it fails, which `cat /sys/firmware/efi/fw_platform_size` will obviously give nothing, but will say `64` in UEFI mode, while the chinese PC will get `32`. So it means `cat /sys/firmware/efi/fw_platform_size` should do it, but since UEFIs implementations are a mess, I'm still unsure about if that's the definite way to tell... because the ssh'd PC gave `64` while the HDD don't have an ESP partition... – X.LINK Jun 25 '21 at 17:04
  • Ok it's really weird. I'm 100% sure I don't have an ESP partition and nothing about EFI's files on `/boot`, but doing an `update-grub` gave me `Adding boot menu entry for EFI firmware configuration`. What the hell... – X.LINK Jun 28 '21 at 22:52
1

If /sys/firmware/efi/ directory exists, it means the firmware has provided UEFI Runtime Services to the kernel, which necessarily means you have booted in UEFI mode.

If the system is booted in BIOS-compatible mode (CSM), then the UEFI programming interfaces, including UEFI Runtime Services, will not be available to the kernel, and /sys/firmware/efi will not appear.

telcoM
  • 87,318
  • 3
  • 112
  • 232
0

dmesg | grep efi: which will produce sensible output for an EFI boot.

Only if the boot was recent. The dmesg buffer is of limited size, a server that's been running for a while will before long rotate the boot-time messages away.

AdminBee
  • 21,637
  • 21
  • 47
  • 71