Created
April 11, 2019 20:09
-
-
Save kidmose/a4e63c1a7cc34780f413e006b600df16 to your computer and use it in GitHub Desktop.
reinstall grub2 with EFI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://superuser.com/questions/376470/how-to-reinstall-grub2-efi | |
# and some of mine | |
if ! [ $(id -u) = 0 ]; then | |
echo "I am not root!" | |
exit 1 | |
fi | |
# prepare for chroot | |
mount /dev/sda4 /mnt #sda2 is the root partition | |
mount /dev/sda1 /mnt/boot/efi #sda1 is the efi partition | |
for i in /dev /dev/pts /proc /sys; do mount -B $i /mnt$i; done | |
cp /etc/resolv.conf /mnt/etc/ #makes the network available after chrooting | |
modprobe efivars # make sure this is loaded | |
# dump script to run in chroot, run it - does the install | |
cat <<EOF > /mnt/install_grub_chroot.sh | |
#!/bin/bash | |
apt-get update | |
apt-get install --reinstall grub-efi-amd64 | |
EOF | |
chmod +x /mnt/install_grub_chroot.sh | |
sudo chroot /mnt ./install_grub_chroot.sh | |
# clean up | |
for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done | |
sudo umount /mnt/boot/efi #please do this. Corrupted efi partitions are not nice | |
sudo umount /mnt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment