3

I'm trying to write a script that runs at initramfs that uses efibootmgr to permanently set the highest boot priority without having to re-assign the boot order.

efibootmgr -n 000A for example is perfect for this as it sets the drive 000A to be the boot priority but for the next boot only. efibootmgr -o requires that we list all drives and re-assign their order, which complicates the script as I would have to grab these values and parse them back to the efibootmgr command to re-order.

Is there a way to change boot priority where I only have to reference the drive of the one I am trying to make priority rather than re-write the hierarchy?

Shiri
  • 131
  • 4

1 Answers1

1

Short answer: No.

Long answer: First, understand that EFI does not boot "drives," except in certain limited senses or under limited circumstances. The most commonly-used boot entries revealed by efibootmgr are for EFI boot loader programs, which are stored as ordinary files on the ESP. This may seem like a subtle distinction, but trying to solve your problem without understanding it is likely to result in a buggy and/or limited solution.

Parsing the efibootmgr output is likely to be required to do what you want to do. This shouldn't really be very difficult; understanding a few common commands used in Bash scripts, like grep and cut, will take you a long way.

Alternatively, if your goal is to restore a boot order that's lost because of a buggy EFI, you might look into the fallback.efi program. AFAIK, it's not available in Ubuntu, but it comes with Fedora. This program will restore a set of NVRAM boot variables from a file if they're lost. It's intended to be placed in the EFI/BOOT directory and launched from Shim (which launches it automatically), so that the firmware's boot entries will be restored should they be lost. This approach has some problems, like cluttering the ESP with yet more files and creating new hoops through which you must jump if you want to change the boot entries, but it may be what you need.

Rod Smith
  • 45,120
  • 7
  • 66
  • 108