问题描述

如何确定是否使用EFI /UEFI或BIOS引导了特定的正在运行的Ubuntu系统?

 

最佳解决办法

最简单的方法是检查/sys/firmware/efi是否存在。如果您使用传统BIOS启动,则不会显示。

#!/bin/bash
[ -d /sys/firmware/efi ] && echo UEFI || echo BIOS

 

次佳解决办法

Deprecated

The answer below is a method that may not always work.
Instead use Colin’s answer based on /sys/firmware/efi.


很容易判断一个系统是否在EFI中启动(或者不是,在这种情况下,它必须是BIOS):

只需使用dmesg | grep "EFI v"

  • 如果系统从EFI启动,这将返回这样一行:[0.000000] American Megatrends的EFI v2.00

  • 如果不是,则不返回任何内容,在这种情况下,它是从BIOS启动的

基于grep退出代码的bash脚本使用示例:


...
dmesg | grep -q "EFI v"    # -q tell grep to output nothing
if [ $? -eq 0 ]      # check exit code; if 0 EFI, else BIOS
then
    echo "You are using EFI boot."
  else
    echo "You are using BIOS boot"
fi
...

Source: For how to determine if an EFI system is using legacy-BIOS emulation or not, as well as more information on testing for EFI and EFI compatibility, along with the strings for a number of EFI vendors/versions, please see this page from the Ubuntu Developer Summit for Precise.

Logo

更多推荐