From: Heinrich Schuchardt Date: Fri, 18 Mar 2022 14:21:33 +0000 (+0100) Subject: [PATCH 1/1] efivar: check that efivarfs is writeable X-Git-Tag: archive/raspbian/2.12-8+rpi1~9 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=59f40b0df1d8b57393905ac0f790105425cbd047;p=grub2.git [PATCH 1/1] efivar: check that efivarfs is writeable Some UEFI implementations (notably U-Boot) don't implement the SetVariable() runtime service. On these systems the GRUB installation must be completed manually. Write a warning in this case but avoid throwing an error. (LP: #1965288) Signed-off-by: Heinrich Schuchardt Gbp-Pq: Name efivar-check-that-efivarfs-is-writeable.patch --- diff --git a/grub-core/osdep/unix/efivar.c b/grub-core/osdep/unix/efivar.c index 4a58328..b53f32d 100644 --- a/grub-core/osdep/unix/efivar.c +++ b/grub-core/osdep/unix/efivar.c @@ -37,7 +37,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -398,6 +401,29 @@ err: return NULL; } +/** + * efivar_is_rw - detect if the efivar file system exists and is writeable + * + * Return: true if efivarfs is writeable + */ +static bool +efivar_is_rw (void) +{ + int ret; + const char *mount = "/sys/firmware/efi/efivars"; + struct statfs stat; + + ret = statfs(mount, &stat); + if (ret == -1) + return false; + if (stat.f_type != EFIVARFS_MAGIC) + return false; + if (stat.f_flags & ST_RDONLY) + return false; + + return true; +} + int grub_install_efivar_register_efi (grub_device_t efidir_grub_dev, const char *efifile_path, @@ -410,6 +436,14 @@ grub_install_efivar_register_efi (grub_device_t efidir_grub_dev, int entry_num = -1; int rc; + /* Check if EFI variable can be written */ + if (!efivar_is_rw ()) + { + grub_util_warn ("EFI variables cannot be set on this system"); + grub_util_warn ("You will have to complete the GRUB setup manually"); + return 0; + } + efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk); efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1;