GRUB Bootloader Reinstallation from a Live Environment
Overview
Use this procedure to reinstall GRUB on a Linux system that is unable to boot. The process uses a live boot environment, mounts the target system, enters a chroot environment, and reinstalls GRUB on the target disk.
Prerequisites
- Boot the server using a Linux live environment (example: R1Soft BMR boot CD).
- Log in as the root user:
sudo -i
Procedure
1. Create a Mount Point
mkdir /r1soft
2. Mount the Target Filesystem
Standard Root Partition
mount /dev/sda1 /r1soft
LVM Root Partition if applicable
First, scan for volume groups and activate them with:
vgscan
vgchange -ay
Next, mount the logical volume with:
mount /dev/vgname/lvname /r1soft
Separate Boot Partition if applicable
mount /dev/sda2 /r1soft
mount /dev/sda1 /r1soft/boot
3. Prepare the Chroot Environment
mount --bind /proc /r1soft/proc
mount --bind /sys /r1soft/sys
mount --bind /dev/pts /r1soft/dev/pts
mount --bind /dev /r1soft/dev
mount --bind /run /r1soft/run
4. Enter the Chroot Environment
chroot /r1soft
5. Back Up Existing GRUB Directory
Debian-Based Systems
mv /boot/grub /boot/grub_bak
AlmaLinux/RHEL-Based Systems
mv /boot/grub2 /boot/grub2_bak
6. Reinstall GRUB
Debian-Based Systems
grub-install /dev/sda
AlmaLinux/RHEL-Based Systems
grub2-install /dev/sda
Replace /dev/sda with the appropriate boot disk if different.
7. Regenerate GRUB Configuration
Debian-Based Systems
update-grub
AlmaLinux/RHEL-Based Systems
grub2-mkconfig > /boot/grub/grub.cfg
8. Reboot and Validate
- Exit the chroot environment.
- Reboot the server.
- Remove the live media.
- Confirm the operating system boots successfully.
Labels:
None