29th August 2020

Configure boot settings in UEFI

Main source for trouble-shooting is Arch-Wiki UEFI. It describes the commands:

  1. bcfg within UEFI shell
  2. Linux command efibootmgr

1. It is ighly recommended to install the UEFI-shell, which is in package edk2-shell. On Asrock copy

cp -p /usr/share/edk2-shell/x64/Shell_Full.efi /boot/shellx64.efi

So name of the shell should change to shellx64.efi, at least on Asrock system A300M.

Create UEFI boot entry where boot entry says: Run UEFI-shell with parameter fs0:\\archlinux-fallback.nsh.

efibootmgr -c -d /dev/nvme0n1 -l /shellx64.efi -L Shellx64_u -v -u "fs0:\\archlinux-fallback.nsh"

This script, executed by UEFI-shell, is as follows: cat archlinux.nsh

vmlinuz-linux root=UUID=dac919c6-2f0f-466b-ada8-692ce6d16d91 rw  cryptdevice=/dev/disk/by-uuid/70260d27-bc13-44dd-9b30-168c2be7c72f:nvme0n1p2 ip=192.168.178.20:192.168.178.20:192.168.178.1:255.255.255.0:ryzen:eth0:none initrd=\initramfs-linux.img

This UEFI-shell script is very similar to a GRUB entry. Important to note is that vmlinuz-linux is directly "executable" via UEFI-shell. vmlinuz-linux takes arguments which tell where to find root directory, initial RAM disk, and possibly any information for entering decrypt password for an encrypted boot device.

2. Instead of

efibootmgr -c -d /dev/nvme0n1 -l /shellx64.efi -L Shellx64_u -v -u "fs0:\\archlinux-fallback.nsh"

one could also configure UEFI boot entry as below, although more complicated, but better understanding what exactly is done behind the scenes:

printf "fs0:\\\archlinux-fallback.nsh" | ~klm/c/2ndzero | efibootmgr -c -d /dev/nvme0n1 -l /shellx64.efi -L Shellx64 -v -@ -

C program 2ndzero adds hex 00 every second character. Below program adds 0x00 after each character:

/* Read stdin and insert hex zero after every character */
#include <stdio.h>

int main (int argc, char *argv[]) {
        int c;

        while ((c = getchar()) != EOF) {
                putchar(c);
                putchar('\0');
        }

        return 0;
}

3. Some useful efibootmgr examples. Show all UEFI boot variants:

efibootmgr -v

Looking in hex into boot configuration:

xxd /sys/firmware/efi/efivars/Boot0005-8be4df61-93ca-11d2-aa0d-00e098032b8c

Create an UEFI boot entry with just an UEFI-shell:

efibootmgr -c -d /dev/nvme0n1 -l /shellx64.efi -L uefi_shell -v

Delete an UEFI boot entry, in this case number six:

efibootmgr -B 6

Delete entry #6:

efibootmgr -B -b 6

Delete entry #2:

efibootmgr -B -b 2

Rearrange order of boot entries, and mark entry #9 as active:

efibootmgr -o 5,9,a



Categories: Linux
Author: Elmar Klausmeier