grub-restore-script/README.md

190 lines
3.2 KiB
Markdown

# 🛠️ GRUB EFI Repair Script
If you run Windows on Dual Boot with Linux, you may have faced issues like your windows partition overwrites the linux boot loader forcing user to log in on windows.
This script was created to solve that issue in UEFI based Linux systems.
A simple Bash script to reinstall GRUB on UEFI-based Linux systems and set the correct boot order.
---
## ⚠️ Requirements & Conditions
Before running this script, ensure your system meets **all** of the following conditions.
### **1. UEFI System Required**
This script works **only on UEFI systems**.
Legacy BIOS systems are **not supported**.
It uses:
```
grub-install --target=x86_64-efi
```
---
### **2. EFI Partition Must Be Mounted at `/boot/efi`**
Your system must have an EFI System Partition (ESP) mounted at:
```
/boot/efi
```
The script expects this directory to exist:
```
/boot/efi/EFI
```
If your distribution uses a different mount point (such as `/efi` or `/boot`), adjust the script accordingly.
---
### **3. GRUB Must Be Installed and Used**
This script only works with **GRUB**.
It does **NOT** support:
* systemd-boot
* rEFInd
* LILO
* vendor-specific boot managers
Running it on these setups will result in errors.
---
### **4. `update-grub` Must Exist**
The script uses:
```
update-grub
```
This command is available only on **Debian-based** systems:
* Debian
* Ubuntu
* Linux Mint
* Kali
* MX Linux
It will **not** work on:
* Fedora / RHEL / CentOS / Rocky / AlmaLinux
* Arch Linux / Manjaro
* OpenSUSE
Those use `grub2-mkconfig`.
---
### **5. Bootloader ID Defaults to “Debian”**
The GRUB installation uses:
```
--bootloader-id=Debian
```
Different distros use different EFI bootloader IDs:
* Ubuntu → `ubuntu`
* Fedora → `fedora`
* Linux Mint → `LinuxMint`
* Arch Linux → `arch`
Update this value if needed.
---
### **6. Requires `efibootmgr` Support**
The script modifies UEFI boot order using:
```
efibootmgr -o
```
This requires:
* Firmware that allows BootOrder modification
* Root access
Some cloud/VPS providers restrict this capability.
---
### **7. Must Be Run as Root**
You must run the script with `sudo` or as root because it executes privileged commands:
* `grub-install`
* `update-grub`
* `efibootmgr`
---
### **8. Multi-Boot Systems**
If multiple OSes are installed (e.g., Windows + Linux), this script will set **Debian GRUB as the first boot entry**, overriding others.
---
### **9. Risk Warning**
Changing GRUB/EFI settings can make a system unbootable if misconfigured.
Recommended:
* Keep a bootable USB handy
* Confirm your EFI mount point
* Back up important data
---
## 📜 Usage
Make the script executable:
```
chmod +x grub-fix.sh
```
Run the script:
```
sudo ./grub-fix.sh
```
Reboot when done.
---
## ✔ What the Script Does
1. Verifies EFI directory presence
2. Lists available EFI boot entries
3. Reinstalls GRUB to the EFI System Partition
4. Updates GRUB configuration
5. Detects the Debian boot entry
6. Sets Debian as the first boot option
7. Completes cleanly
---
## 📌 Notes
This script is designed for **Debian-based Linux systems** with a standard EFI layout.
It is **not guaranteed to work on all Linux distributions**.
---