Skip to content

Instantly share code, notes, and snippets.

@noslin005
Created February 28, 2020 15:21
Show Gist options
  • Save noslin005/03d126b5a042a8fc613407ee2bd2dfdc to your computer and use it in GitHub Desktop.
Save noslin005/03d126b5a042a8fc613407ee2bd2dfdc to your computer and use it in GitHub Desktop.
Reinstalling grub-efi on your hard drive
[ -d /sys/firmware/efi ] && echo "EFI boot on HDD" || echo "Legacy boot on HDD"
mkdir /target

# list drives
fdisk -l

# find each partition, i.e, /, /boot, /boot/efi and /home

# mount them
mkdir /target
mount /dev/sda3 /target
mount /dev/sda2 /target/boot
mount /dev/sda1 /target/boot/efi
ount /dev/sda4 /target/home

for i in /sys /proc /dev /dev/pts; do mount --bind $i /target$i; done
chroot /target /bin/bash

apt-get install --reinstall grub-efi
grub-install /dev/sda
grub-install --target=x86_64-efi /dev/sda
update-grub

# If gub install fails with error "grub-install: warning: Cannot read EFI Boot* variables"
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
grub-install --target=x86_64-efi /dev/sda
update-grub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment