diff --git a/simple_grub_repair.sh b/simple_grub_repair.sh new file mode 100755 index 0000000..5c40bbd --- /dev/null +++ b/simple_grub_repair.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# Simple GRUB Boot Repair Script +# Direct GRUB repair without chroot complications + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +VG_NAME="system-vg" +EXTERNAL_DRIVE="/dev/sda" + +log() { echo -e "${BLUE}[$(date '+%H:%M:%S')]${NC} $1"; } +error() { echo -e "${RED}[ERROR]${NC} $1" >&2; exit 1; } +success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; } +warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; } + +echo -e "${GREEN}=== Simple GRUB Boot Repair ===${NC}" +echo + +# Check if running as root +if [ "$EUID" -ne 0 ]; then + error "This script must be run as root. Use: sudo $0" +fi + +log "Mounting external system..." +mkdir -p /tmp/ext-boot /tmp/ext-efi + +# Mount the boot and EFI partitions +mount "/dev/$VG_NAME/boot" /tmp/ext-boot || error "Failed to mount boot" +mount "${EXTERNAL_DRIVE}1" /tmp/ext-efi || error "Failed to mount EFI" + +success "Mounted external boot partitions" + +log "Installing GRUB to external drive..." + +# Install GRUB directly to the external drive +grub-install --target=x86_64-efi \ + --efi-directory=/tmp/ext-efi \ + --bootloader-id=debian \ + --boot-directory=/tmp/ext-boot \ + --recheck \ + "$EXTERNAL_DRIVE" || error "GRUB installation failed" + +success "GRUB installed successfully" + +log "Checking installation..." + +# Check if GRUB EFI file was created +if [ -f "/tmp/ext-efi/EFI/debian/grubx64.efi" ]; then + success "GRUB EFI bootloader created successfully" +else + error "GRUB EFI bootloader not found after installation" +fi + +# List EFI directory contents +log "EFI boot entries after repair:" +ls -la /tmp/ext-efi/EFI/ || warning "Could not list EFI entries" + +log "Cleaning up..." +umount /tmp/ext-boot +umount /tmp/ext-efi +rmdir /tmp/ext-boot /tmp/ext-efi + +success "GRUB repair completed!" + +echo +echo -e "${GREEN}=== Next Steps ===${NC}" +echo "1. Reboot your system" +echo "2. Enter BIOS/UEFI settings" +echo "3. Set boot order to prioritize external M.2 SSD" +echo "4. Look for 'debian' entry in boot menu" +echo "5. Boot from external drive" +echo +echo -e "${YELLOW}BIOS Settings:${NC}" +echo "• Disable Secure Boot (if enabled)" +echo "• Enable UEFI mode (disable Legacy/CSM)" +echo "• Set external M.2 as first boot device" +echo +success "External M.2 should now boot properly!" \ No newline at end of file