#!/bin/bash set -e echo "=== Checking EFI directories ===" ls /boot/efi/EFI || { echo "EFI partition not mounted!"; exit 1; } echo "EFI entries found:" ls /boot/efi/EFI/ echo "=== Reinstalling GRUB to EFI partition ===" sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Debian echo "=== Updating GRUB ===" sudo update-grub echo "=== Fixing boot order (setting Debian to first) ===" # Find Debian boot entry number DEBIAN_BOOTNUM=$(sudo efibootmgr | grep -i debian | grep -oP 'Boot\K[0-9A-Fa-f]{4}') if [ -z "$DEBIAN_BOOTNUM" ]; then echo "Error: Could not find Debian entry in efibootmgr!" sudo efibootmgr exit 1 fi echo "Found Debian entry: Boot$DEBIAN_BOOTNUM" echo "Setting Debian as first boot option..." sudo efibootmgr -o $DEBIAN_BOOTNUM echo "=== Done! ===" echo "Reboot your system and GRUB should load first."