Could not prepare Boot variable: No space left on device grub-install: error: efibootmgr failed to register the boot entry: Input/output error

getting below error. But I think available space is enough for this (use% is 9%) Can you please help us to resolve this ?

lab@lab:~$ sudo -E apt-get install subversion apache2-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
subversion is already the newest version (1.9.7-4ubuntu1).
apache2-utils is already the newest version (2.4.29-1ubuntu4.3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up grub-efi-amd64-signed (1.93.4+2.02-2ubuntu8.3) ...
Installing for x86_64-efi platform.
Could not prepare Boot variable: No space left on device
grub-install: error: efibootmgr failed to register the boot entry: Input/output error.
dpkg: error processing package grub-efi-amd64-signed (--configure):
installed grub-efi-amd64-signed package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent processing triggers for shim-signed:
shim-signed depends on grub-efi-amd64-signed; however:
  Package grub-efi-amd64-signed is not configured yet.

dpkg: error processing package shim-signed (--configure):
dependency problems - leaving triggers unprocessed
Errors were encountered while processing:
grub-efi-amd64-signed
shim-signed
E: Sub-process /usr/bin/dpkg returned an error code (1)

lab@lab:~$ df -k .
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2      479152840 37427836 417315612   9% /

Solution 1:

There have been a number of reports that if the NVRAM is more than 50% used, the efibootmgr will fail because there's a concern about being able to garbage collect EFI variables properly, or some such. Unfortunately, I couldn't find a clear way to determine the used/free space in NVRAM, so I'm going on suspicion.

There are a number of potential solutions to this:

  1. Clear the dump files

    grub stores efi logs in /sys/fs/efi/efivars/dump-*

    Try deleting these to see if that's enough to bring the used space down. Then run apt -f install to see if the error has changed.

  2. BIOS upgrade

    If your hardware provider has a BIOS/EFI upgrade, then I'd recommend doing that also, then try apt -f install again.

  3. LAST RESORT - DISABLE EFI CHECK

    It's a little dangerous, because you could technically fill your NVRAM to a point were it's unbootable. However, I have used this process successfully on a Dell R420.

    To override the check, add "efi_no_storage_paranoia" to the kernel option. To do this:

    1. Append "efi_no_storage_paranoia" to the GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX variables in /etc/default/grub
    2. Update grub by running sudo update-grub
    3. Reboot
    4. Run apt -f install

For safety, I reverse this process afterward also. Kernel safety override parameters are not something you want to leave lying around!