IBM Support

Using grub2 on UEFI Systems

How To


Summary

This document shows information and usage of grub2 on x86_64 (Intel) UEFI firmware-based systems.

Environment

Intel or AMD based x86_64 systems, running Linux, under UEFI firmware.

Steps

There are some differences between grub on a system using UEFI firmware as opposed to a BIOS system. 
In this document I will highlight some of the differences seen on a Red Hat 8.10 system.  I hope this helps debug issues in the future.
A problem such as this can be resolved by information in this document:
 
# mount /boot/efi/
  mount: unknown filesystem type 'vfat'
Or this failure to regenerate the grub2 menu:

# grub2-mkconfig -o /boot/grub2/grub.cfg
/usr/bin/grub2-editenv: error: cannot rename the file /boot/grub2/grubenv.new to /boot/grub2/grubenv: No such file or directory.
Generating grub configuration file ...
/usr/bin/grub2-editenv: error: cannot rename the file /boot/grub2/grubenv.new to /boot/grub2/grubenv: No such file or directory.
How can I tell if I'm running under UEFI or BIOS?
There will be a UEFI directory under /sys/firmware containing some data:

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

RPM packages necessary to help grub on UEFI
grub2-efi-x64-2.02-156.el8.x86_64
efibootmgr-16-1.el8.x86_64
shim-x64-15.8-2.el8_10.x86_64

Shim is also installed on BIOS systems.

Notice that the default grubenv actually redirects to the EFI one:
# ls -l /boot/grub2/grubenv 
lrwxrwxrwx. 1 root root 25 Feb 21  2024 /boot/grub2/grubenv -> ../efi/EFI/redhat/grubenv

At this point I should mention the /boot/efi/EFI directory.  You won't see this on a BIOS system, but it is essential for grub2 in the UEFI environment.

This is actually stored on a separate filesystem, in a partition on the boot drive. (In my example I'm on a KVM guest)

# parted /dev/vda print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start   End     Size    File system  Name                  Flags
 1      1049kB  630MB   629MB   fat32        EFI System Partition  boot, esp
 2      630MB   1704MB  1074MB  xfs
 3      1704MB  21.5GB  19.8GB                                     lvm

 

So here /dev/vda1 is the EFI partition.  Note that it is formatted as fat32.  We'll see later that this is important to remember.

Both the boot and EFI partitions are mounted in normal operation:
 

# grep efi /etc/fstab
UUID=031B-53EF          /boot/efi               vfat    umask=0077,shortname=winnt 0 2


df output:
/dev/vda2               1038336  273724    764612  27% /boot
/dev/vda1                613184    5940    607244   1% /boot/efi

mount output:
/dev/vda2 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/vda1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=winnt,errors=remount-ro)

 

In order to insure they are mounted, make sure the fat, vfat and msdos modules exist and are not blacklisted:

First, check if they exist for your current kernel:

# cd /lib/modules/$(uname -r)/kernel/fs/fat
# ls -l
total 56
-rw-r--r--. 1 root root 36260 Dec  6 12:15 fat.ko.xz
-rw-r--r--. 1 root root  6536 Dec  6 12:15 msdos.ko.xz
-rw-r--r--. 1 root root  8880 Dec  6 12:15 vfat.ko.xz

 

Now, make sure they are not blocked:
# cd /etc/modprobe.d
# grep -E "fat|msdos" *

OK, so no config file has them blocked out.

We can also check that they are loaded into memory:
# lsmod | grep fat
vfat                   20480  1
fat                    86016  1 vfat

 

If you need to recreate the grub menu, there is no special EFI option necessary.  The links created in the system, along with the shim, will allow y ou to use regular grub commands, such as:

# grub2-mkconfig -o /boot/grub2/grub.cfg

Also, if you need to recreate the initrd and recreate the grub menu, this is a good all-in-one line to use:

# dracut --regenerate-all -f && grub2-mkconfig -o /boot/grub2/grub.cfg

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB69","label":"Storage TPS"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SGMV157","label":"IBM Support for Red Hat Enterprise Linux Server"},"ARM Category":[{"code":"a8m0z000000Gnl7AAC","label":"Red Hat Enterprise Linux"}],"ARM Case Number":"","Platform":[{"code":"PF097","label":"x86_64"}],"Version":"8.0.0;and future releases"}]

Document Information

Modified date:
07 January 2025

UID

ibm17180423