]> git.proxmox.com Git - grub2.git/commit
Minimise writes to EFI variable storage
authorColin Watson <cjwatson@ubuntu.com>
Mon, 11 Mar 2019 11:17:43 +0000 (11:17 +0000)
committerColin Watson <cjwatson@debian.org>
Fri, 24 Sep 2021 23:37:54 +0000 (00:37 +0100)
commit3b015f7892fd7955b5f2db2e9e8cf26a699b4434
tree62a8fa69dba61816e92d66b3ea62e40d0dc3ab8e
parent084242e163042ca380e2d8d519648b2efb4cec65
Minimise writes to EFI variable storage

Some UEFI firmware is easily provoked into running out of space in its
variable storage.  This is usually due to certain kernel drivers (e.g.
pstore), but regardless of the cause it can cause grub-install to fail
because it currently asks efibootmgr to delete and re-add entries, and
the deletion often doesn't result in an immediate garbage collection.
Writing variables frequently also increases wear on the NVRAM which may
have limited write cycles.  For these reasons, it's desirable to find a
way to minimise writes while still allowing grub-install to ensure that
a suitable boot entry exists.

Unfortunately, efibootmgr doesn't offer an interface that would let
grub-install do this.  It doesn't in general make very much effort to
minimise writes; it doesn't allow modifying an existing Boot* variable
entry, except in certain limited ways; and current versions don't have a
way to export the expected variable data so that grub-install can
compare it to the current data.  While it would be possible (and perhaps
desirable?) to add at least some of this to efibootmgr, that would still
leave the problem that there isn't a good upstreamable way for
grub-install to guarantee that it has a new enough version of
efibootmgr.  In any case, it's cumbersome and slow for grub-install to
have to fork efibootmgr to get things done.

Fortunately, a few years ago Peter Jones helpfully factored out a
substantial part of efibootmgr to the efivar and efiboot libraries, and
so it's now possible to have grub-install use those directly.  We still
have to use some code from efibootmgr, but much less than would
previously have been necessary.

grub-install now reuses existing boot entries where possible, and avoids
writing to variables when the new contents are the same as the old
contents.  In the common upgrade case where nothing needs to change, it
no longer writes to NVRAM at all.  It's also now slightly faster, since
using libefivar is faster than forking efibootmgr.

Fixes Debian bug #891434.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Bug-Debian: https://bugs.debian.org/891434
Forwarded: https://lists.gnu.org/archive/html/grub-devel/2019-03/msg00119.html
Last-Update: 2019-03-23

Patch-Name: efi-variable-storage-minimise-writes.patch
INSTALL
Makefile.util.def
configure.ac
grub-core/osdep/efivar.c [new file with mode: 0644]
grub-core/osdep/unix/efivar.c [new file with mode: 0644]
grub-core/osdep/unix/platform.c
include/grub/util/install.h
util/grub-install.c