Go to file
Colin Watson 3b015f7892 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
2021-09-25 00:37:54 +01:00
asm-tests asm-tests/i386-pc: Check that movl is 5 bytes. 2016-09-28 20:31:04 +03:00
build-aux Import grub2_2.04~rc1.orig.tar.xz 2019-05-14 10:20:03 +01:00
conf gnulib/regcomp: Fix uninitialized re_token 2021-03-02 15:54:16 +01:00
docs Add GRUB_RECOVERY_TITLE option 2021-09-25 00:37:38 +01:00
grub-core Minimise writes to EFI variable storage 2021-09-25 00:37:54 +01:00
include Minimise writes to EFI variable storage 2021-09-25 00:37:54 +01:00
m4 Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
po Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
tests Skip flaky grub_cmd_set_date test 2021-09-25 00:37:54 +01:00
themes/starfield Starfield theme. 2012-02-23 17:21:38 +01:00
unicode * unicode: Import Unicode 6.0 data. 2011-12-25 16:17:25 +01:00
util Minimise writes to EFI variable storage 2021-09-25 00:37:54 +01:00
ABOUT-NLS Import grub2_2.04~rc1.orig.tar.xz 2019-05-14 10:20:03 +01:00
acinclude.m4 kern/efi: Add initial stack protector implementation 2021-03-02 15:54:19 +01:00
aclocal.m4 Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
AUTHORS 2005-09-03 Yoshinori K. Okuji <okuji@enbug.org> 2005-09-03 16:54:27 +00:00
autogen.sh autogen: Replace -iname with -ipath in find command 2020-05-15 15:35:59 +02:00
BUGS * BUGS: New file. 2011-01-11 00:06:01 +01:00
ChangeLog Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
ChangeLog-2015 Autogenerate ChangeLog from git changelog. 2015-01-24 17:29:50 +01:00
config-util.h.in Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
config.h.in Add configure option to reduce visual clutter at boot time 2021-09-25 00:37:38 +01:00
configure Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
configure.ac Minimise writes to EFI variable storage 2021-09-25 00:37:54 +01:00
COPYING 2007-07-22 Yoshinori K. Okuji <okuji@enbug.org> 2007-07-21 23:32:33 +00:00
coreboot.cfg * coreboot.cfg: Add missing file. 2013-11-20 00:52:23 +01:00
geninit.sh automake commit without merge history 2010-05-06 11:34:04 +05:30
gentpl.py build: Fix GRUB i386-pc build with Ubuntu gcc 2020-03-31 12:17:02 +02:00
INSTALL Minimise writes to EFI variable storage 2021-09-25 00:37:54 +01:00
linguas.sh linguas: Don't skip ko.po. 2017-02-04 00:06:57 +01:00
Makefile.am Makefile: Make libgrub.pp depend on config-util.h 2020-03-10 21:39:53 +01:00
Makefile.in Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
Makefile.util.am Import grub2_2.06.orig.tar.xz 2021-09-24 10:34:42 +01:00
Makefile.util.def Minimise writes to EFI variable storage 2021-09-25 00:37:54 +01:00
Makefile.utilgcry.def Import grub2_2.02~beta3.orig.tar.xz 2016-09-18 17:40:00 +01:00
NEWS Release 2.06 2021-06-08 16:28:15 +02:00
README SECURITY: Add SECURITY file 2021-06-08 14:24:34 +02:00
stamp-h.in Import grub2_2.02~beta3.orig.tar.xz 2016-09-18 17:40:00 +01:00
THANKS 2009-12-11 Robert Millan <rmh.grub@aybabtu.com> 2009-12-11 22:44:47 +00:00
TODO TODO: Remove obsolete link 2016-02-12 17:51:52 +01:00

This is GRUB 2, the second version of the GRand Unified Bootloader.
GRUB 2 is rewritten from scratch to make GNU GRUB cleaner, safer, more
robust, more powerful, and more portable.

See the file NEWS for a description of recent changes to GRUB 2.

See the file INSTALL for instructions on how to build and install the
GRUB 2 data and program files.

See the file MAINTAINERS for information about the GRUB maintainers, etc.

If you found a security vulnerability in the GRUB please check the SECURITY
file to get more information how to properly report this kind of bugs to
the maintainers.

Please visit the official web page of GRUB 2, for more information.
The URL is <http://www.gnu.org/software/grub/grub.html>.

More extensive documentation is available in the Info manual,
accessible using 'info grub' after building and installing GRUB 2.

There are a number of important user-visible differences from the
first version of GRUB, now known as GRUB Legacy. For a summary, please
see:

  info grub Introduction 'Changes from GRUB Legacy'