diff --git a/README.md b/README.md new file mode 100644 index 0000000..13411d0 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Grub reinstallation hook for pacman + +This hook would re-install and re-configiure grub after any changes on Grub package in Arch Linux repository, such as **upgrade** or **reinstallation** + + + + +Parch Linux [website](https://parchlinux.com) diff --git a/hooks/90-grub-disk-type.hook b/hooks/90-grub-disk-type.hook new file mode 100644 index 0000000..398e273 --- /dev/null +++ b/hooks/90-grub-disk-type.hook @@ -0,0 +1,9 @@ +[Trigger] +Operation = Upgrade +Operation = Install +Type = Package +Target = grub +[Action] +Description = Reinstall and remake GRUB configuration +When = PostTransaction +Exec = /bin/bash -c '/etc/pacman.d/hooks/90-grub-disk-type.sh' diff --git a/hooks/90-grub-disk-type.sh b/hooks/90-grub-disk-type.sh new file mode 100755 index 0000000..e090615 --- /dev/null +++ b/hooks/90-grub-disk-type.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Check if the system is running in UEFI mode +if [[ -d "/sys/firmware/efi" ]]; then + # UEFI mode detected + echo "UEFI system detected. Reinstalling GRUB for UEFI..." + grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB +else + # Legacy (BIOS) mode detected + echo "Legacy (BIOS) system detected. Reinstalling GRUB for BIOS..." + + # Find the primary disk for MBR installations + primary_disk=$(lsblk -o NAME,SIZE,MOUNTPOINT -nl | awk '$3=="/" {print $1}' | sed 's/[0-9]//g') + + if [[ -n "$primary_disk" ]]; then + grub-install --target=i386-pc --recheck "/dev/$primary_disk" + else + echo "Error: Unable to determine primary disk. Check your configuration." + exit 1 + fi +fi + +# Generate GRUB configuration +grub-mkconfig -o /boot/grub/grub.cfg +