On May 31, 2020, at 04:41, Patrick Dupre <pdupre(a)gmx.com> wrote:
On a multi-boot PC, how grub is updated?
In the past /etc/grub2.cfg was updated.
Specifically, with the legacy bootloader, it was /boot/grub2/grub.cfg that was updated,
and the file in /etc was a symlink.
If you use the legacy bootloader, it remains the same, but any modern x86_64 hardware will
use UEFI. So the grub.cfg is in /boot/efi/EFI/fedora/, along with the .efi executable for
grub (and a signed shim EFI executable, for Secure Boot).
It seems that there are 2 tools: bootctl, and efibootmgr
bootctl is part of systemd-boot, which is a different bootloader than GRUB2. By default
on Fedora x86, GRUB2 is used.
The ‘efibootmgr’ tool is used to interact with the computer’s UEFI firmware. The firmware
is what launches on boot, and it is configured with efibootmgr with what EFI executable to
launch. You need a fat32-formatted partition with the EFI label, which has an /EFI
directory at its root. All UEFI-compatible firmwares can read those volumes and look for
EFI executables within. So you can put a CentOS, Ubuntu, or Microsoft executable (or all
of them!) and configure boot entries for each. There is a BootOrder EFI firmware variable
that stores the order in which it chooses what to boot, depending on which is available.
There’s the BootCurrent variable, as you mentioned, which shows what was last used to
boot, and a BootNext which you can use to (temporarily) boot next boot.
What are the files managed by these tools?
All EFI variables
are stored in the EFI firmware. Linux makes them available as files in /sys/firmware/efi/.
**DO NOT MESS WITH THESE FILES OR DELETE THEM**. You can brick your hardware if you do so.
Just use the efibootmgr tool to change things.
Once grub is launched, it reads the grub.cfg in the EFI directory. Modern Fedora doesn’t
change the grub.cfg anymore, it reads data out of /boot/loader/entries/, where a grub.cfg
fragment exists for each kernel.
Remember when I mentioned that the EFI was a fat32 filesystem? Turns out that it’s a
pretty unreliable filesystem and if the computer makes changes to it and is
unceremoniously powered off, it will have a dirty bit set and the OS can’t even mount it
when you start back up, causing boot errors and dropping you into the rescue shell. By
putting a static grub.cfg into the EFI volume and all the changing entries into
/boot/loader/entries, you’re only writing to a volume that is a journaled ext4 or XFS
volume, which can be easily recovered. I believe that’s why there was the change.
Which tool is run after an update of the kernel?
/bin/kernel-install is run with a bunch of parameters. It handles detection of what
bootloader (grub legacy vs grub efi) and adding all the correct entries and may call tools
such as grubby.
There’s a bit more complexity to this but this is all I can remember off the top of my
head and type on a mobile device. (It’s too nice outside here to get out of my hammock!)
Jonathan Billings <billings(a)negate.org>