Install-grub: a new way to keep your EFI/MBR in-sync with grub package

Some might not know that when updating the grub package you’re actually only update GRUB partly. This also creates some issues with your system if an older grub got installed but doesn’t match configurations and scripts. This script fixes most of our installation cases. If you have a fancy partition layout or some extra stuff ongoing, it may fail as explained here: Re: [Regression] efi: Don't display a uefi-firmware entry if it's not su

You can now install the package install-grub. It comes with a script and hook to detect updates on the grub package. It should cover BIOS/MBR and UEFI installations. SecureBoot, ZFS and a fancy encryption are not yet supported.

A possible output would be then:

$ sudo pacman -S grub
[sudo] password for manjaro: 
warning: grub-2.12-3 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Packages (1) grub-2.12-3

Total Installed Size:  47,86 MiB
Net Upgrade Size:       0,00 MiB

:: Proceed with installation? [Y/n] 
(1/1) checking keys in keyring                     [######################] 100%
(1/1) checking package integrity                   [######################] 100%
(1/1) loading package files                        [######################] 100%
(1/1) checking for file conflicts                  [######################] 100%
(1/1) checking available disk space                [######################] 100%
:: Processing package changes...
(1/1) reinstalling grub                            [######################] 100%
:: Running post-transaction hooks...
(1/4) Arming ConditionNeedsUpdate...
(2/4) Installing Grub to MBR/EFI
Grub will be installed on: EFI
Installing for x86_64-efi platform.
Installation finished. No error reported.
Copying UEFI Fallback file: /boot/efi/EFI/boot/bootx64.efi
Generating grub configuration file ...
Found theme: /usr/share/grub/themes/manjaro/theme.txt
Found linux image: /boot/vmlinuz-6.7-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-6.7-x86_64.img
Found initrd fallback image: /boot/initramfs-6.7-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.6-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-6.6-x86_64.img
Found initrd fallback image: /boot/initramfs-6.6-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.4-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-6.4-x86_64.img
Found initrd fallback image: /boot/initramfs-6.4-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.3-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-6.3-x86_64.img
Found initrd fallback image: /boot/initramfs-6.3-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.1-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-6.1-x86_64.img
Found initrd fallback image: /boot/initramfs-6.1-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.0-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-6.0-x86_64.img
Found initrd fallback image: /boot/initramfs-6.0-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.19-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-5.19-x86_64.img
Found initrd fallback image: /boot/initramfs-5.19-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.18-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-5.18-x86_64.img
Found initrd fallback image: /boot/initramfs-5.18-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.15-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-5.15-x86_64.img
Found initrd fallback image: /boot/initramfs-5.15-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.9-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-5.9-x86_64.img
Found initrd fallback image: /boot/initramfs-5.9-x86_64-fallback.img
Found linux image: /boot/vmlinuz-5.4-x86_64
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-5.4-x86_64.img
Found initrd fallback image: /boot/initramfs-5.4-x86_64-fallback.img
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Adding boot menu entry for UEFI Firmware Settings ...
Found memtest86+ image: /boot/memtest86+/memtest.bin
done
(3/4) Checking which packages need to be rebuilt
(4/4) Updating the info directory file...

Development history

2.12-3.10 - make install-grub.conf optional and set interactive false when run by hook
2.12-3.9 - fixes dependencies and reflect folder naming of Bootloader-ID
2.12-3.8 - checks for current boot entry and searches for Bootloader-ID case insensitive
2.12-3.7 - checks for EFI mountpoint and adds debug and interactivity via config
2.12-3.6 - fix issue when multiple grub versions are installed
2.12-3.5 - add safety checks for Grub2 and enhance for fallback image
2.12-3.4 - add safety checks for fallback image
2.12-3.3 - small fixes
2.12-3.2 - fix typos
2.12-3.1 - small fixes
2.12-3 - add support for /efi folder installs
2.12-2 - don’t check for EFI files on MBR install
2.12-1 - initial version

18 Likes
$ sudo install-grub
Grub will be installed on: EFI
Installing for x86_64-efi platform.
grub-install: error: failed to get canonical path of `'.
Failed: grub-install --target=x86_64-efi --efi-directory= --bootloader-id=manjaro --recheck --force
WARNING: Bootloader is not properly installed, system may not be bootable

Probably related to (at least) this bit:

efi_directory="$(find /boot -name $efi_grub_file | awk -F '/EFI' '{print $1}')"

Because my ESP is /efi as is the modern upstream default/recommend, but it is not included in the search paths of this script.

EDIT.
Yup, augmented that line for

efi_directory="$(find /{boot,efi} -name $efi_grub_file | awk -F '/EFI' '{print $1}')"

And it seemed to run.

$ sudo install-grub2
Grub will be installed on: EFI
Installing for x86_64-efi platform.
Installation finished. No error reported.
Generating grub configuration file ...
Found theme: /usr/share/grub/themes/manjaro/theme.txt
Found linux image: /boot/vmlinuz-linux-amd-znver3
Found initrd image: /boot/amd-ucode.img /boot/initramfs-linux-amd-znver3.img
Found initrd fallback image: /boot/initramfs-linux-amd-znver3-fallback.img
Found linux image: /boot/vmlinuz-6.1-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.1-x86_64.img
Found initrd fallback image: /boot/initramfs-6.1-x86_64-fallback.img
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Found Windows Boot Manager on /dev/nvme0n1p1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings ...
Found memtest86+ EFI image: /boot/memtest86+/memtest.efi
/usr/bin/grub-probe: warning: unknown device type nvme0n1.
Adding reboot option.
Adding poweroff option.
done
1 Like

@philm Why the fallback entry

Copying UEFI Fallback file: /boot/efi/EFI/boot/bootx64.efi

and not the distro specific

/boot/efi/EFI/manjaro/grubx64.efi

p.s. Frohe Weihnachten!

1 Like

Well, that is a disk fallback entry. The main entry should be the one you mentioned (/boot/efi/EFI/manjaro/grubx64.efi).
In UEFI you can also set just a disk as your boot option (as alternative to the normal way of specifying a certain boot entry). When you select that, the ESP’s /EFI/boot/bootx64.efi path is used to boot.

This fallback seems to be installed only if the grub-install command (that installs to the default manjaro path) gives an error.

install-grub 2.12-3.3 should fix your issue @cscs and also fixes some issues I found with MBR install. It should also exit if it doesn’t find the EFI_DIR.

@Teo maybe I should call it Updateing UEFI Fallback file as we copy the manjaro one to the fallback file.

2 Likes

But i thought the point is to update manjaro/grubx64.efi if it is old, for example 2.06?

does I have to switch branch to unstable, install it and then go back again to stable?

Edit:
seems it is in stable from today…

Edit2:
worked well for me :smiley:

What is your experience with install-grub?

  • No issue, everything went smoothly (install and usage)
  • Yes there was an issue. I was able to resolve it myself.(Please post your solution)
  • Yes i am currently experiencing an issue due to the update. (Please post about it)
0 voters

:footprints:

What an amazing little Christmas present! Thanks @philm!

2 Likes

I downloaded the script and it is mostly working on a BIOS/MBR system, except for the message about
“Adding boot menu entry for UEFI Firmware Settings”

Grub will be installed on: MBR
Installing for i386-pc platform.
Installation finished. No error reported.
Generating grub configuration file ...
Found background: /usr/share/grub/background.png
Found linux image: /boot/vmlinuz-6.6-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.6-x86_64.img
Found initrd fallback image: /boot/initramfs-6.6-x86_64-fallback.img
Found linux image: /boot/vmlinuz-6.1-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-6.1-x86_64.img
Found initrd fallback image: /boot/initramfs-6.1-x86_64-fallback.img
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
Found memtest86+ image: /boot/memtest86+/memtest.bin
done

Just a clarification question: install-grub takes into account whether ext4 or btrfs is used?

Thank you for the tool! :+1:

2 Likes

Is it an update to a previously existing package ?

hm install-grub should not be confused with the command grub-install
I guess many will confuse this.

how about naming it like “manjaro-grub-updater” or similar

7 Likes

It was more of a typo on my part because I was in a hurry…

My bad, i looked at the script now, it is actually doing both efi files as it should. Maybe one more echo message with the full install path told to the user, between “installing to efi” and “copying fallback”?

There should be an additional check to see if a grubx64.efi (or any other) boot file already exists at the UEFI fallback location.

In cases where rEFInd is used (previously moved to the fallback location) there is potential for the new Grub to override or take control of a users default preference. This is also a consideration worth addressing.

Well, we can debate how we call the package. In the end it installs grub after all. update-grub was the script we provided by grub and then split out to grub-update. Then I decided to call the package like the script.

What is more important is that this new script works and doesn’t create unbootable systems. Most users don’t even know how grub got installed to begin with.

Via the automated Calamares you mostly install it on EFI systems to /boot/efi. Others prefer /efi however.

grub-install --target=$efi_target --efi-directory=$efi_directory --bootloader-id=$bootloader_id --recheck --force

Ubuntu is calling a more complex script for Grub-EFI installation called grub-multi-install and there is postinst.in which is called after grub got installed. My script is far less complex than those, however we can adopt a little more to make it more robust.

4 Likes

as far as i know the fallback should always be called bootx. It is hardcoded in some more stupid uefis.

No, as $efi_directory/EFI/$bootloader_id/$efi_grub_file is generated via grub-install and needs to been copied over to the UEFI Fallback file …