Automate GRUB install after an update with Pacman hook:

Create a file /etc/pacman.d/hooks/grub-update.hook

$ sudo mkdir /etc/pacman.d/hooks
$ sudo nano /etc/pacman.d/hooks/grub-update.hook

Add the following lines:

[Trigger]
Operation = Upgrade
Type = Package
Target = grub

[Action]
Description = Reinstall grub when it updates...
When = PostTransaction
Exec = /bin/sh -c "/usr/local/bin/grubinstall.sh"

Save and close the file.

The grubinstall.sh script:

# Assign output of findmount to variable

TPDEV=$(findmnt -n -o SOURCE /)

# Function to find mountpoint of / and test if on NvME or Sata device

_findmount () {
  if
    [ -z "${TPDEV##*nvme*}" ]; then
    LRDEV=$(findmnt -n -o SOURCE / | cut -c1-12)
  else
    LRDEV=$(findmnt -n -o SOURCE / | cut -c1-8)
  fi
}

# Test for EFI boot and either run grub-install for EFI or move to findmount

if [ -d "/sys/firmware/efi" ]; then
  grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=ezarcher --recheck
  grub-mkconfig -o /boot/grub/grub.cfg
else
  _findmount
  grub-install --target=i386-pc "${LRDEV}"
  grub-mkconfig -o /boot/grub/grub.cfg
fi

_____
grub-update-hook.txt
# Revision: 2024.03.14 -- by eznix (https://sourceforge.net/projects/ezarch/)
# (GNU/General Public License version 3.0)
