Overclock.net banner

Guide: GRUB Recovery / How-To Reinstall GRUB

534 Views 0 Replies 1 Participant Last post by  Particle
# First you must mount the needed partitions.
# -> An MBR system probably has just one partition: "/"
# -> An EFI system probably has two partitions: "/" and "/boot/efi"
# -> Some weird systems have three: "/", "/boot", and "/boot/efi"

# This example assumes a system with a single boot device having two partitions:
# -> /dev/sda1 = "/boot/efi"
# -> /dev/sda2 = "/"

# If your system has a different partition layout, you'll need to adjust the mount and umount commands accordingly. This guide covers the most common case.

# Boot with a Live USB stick so that you have a system to work in.

# Make mount dir
sudo mkdir /media/system

# Mount system and EFI partitions
sudo mount /dev/sda2 /media/system
sudo mount /dev/sda1 /media/system/boot/efi

# Mount special devices for system we're recovering now that they're available
sudo mount --bind /dev /media/system/dev
sudo mount --bind /proc /media/system/proc
sudo mount --bind /sys /media/system/sys

# Enter system we're recovering
sudo chroot /media/system

# <<< do stuff inside chrooted system >>>

# Example: Install GRUB onto disk if the boot loader is missing on a disk
grub-install --target=x86_64-efi /dev/sda

# Example: Update the GRUB configuration file in case UUIDs or something changed

# Example: Add new fs modules to initramfs config (you'll have to update the image later too)
echo "xfs ext4 f2fs" >> /etc/initramfs-tools/modules

# Example: Update initramfs image to ensure boot process has all the modules and configs it needs
update-initramfs -u

# Exit recovery

# Unmount special devices (in reverse order)
sudo umount /media/system/sys
sudo umount /media/system/proc
sudo umount /media/system/dev

# Unmount system and EFI partitions (in reverse order)
sudo umount /media/system/boot/efi
sudo umount /media/system

# Done

# Reboot and check your boot order. You're finished.