Reinstall Grub

Get to a shell

If you are installing Linux

Installing Grub happens at the end of a Linux installation, and if it fails, the installation usually aborts. It’s important to realise that at this point your Linux installation is fine you don’t need to go through the installer again. Hopefully your installer will handle this sensibly and not crash out to a wall of error messages. You need the installer to finish setting up your system.

Depending on your installation, you might be presented with the option to skip installing Grub and to continue. Choose that option if you can, otherwise leave the installer alone for the moment and try to switch into another shell by pressing ctrl-alt-F1 (or F2, F3, whichever gives you a login prompt), or see if there’s a way to go into a shell without quitting the installer.

If you are booting from a rescue CD/USB

Just get to a root shell, it doesn’t matter whether it’s booted your system or not. Any Linux shell will do.

Mount your installation

With a shell - any shell - you first need to mount all the filesystems needed. We’re going to chroot into your installation to fix this.

Mount your root partition

This is the partition that would be mounted as / in Linux. It might be /dev/sda1.

mount /dev/sda1 /mnt

Mount the system paritions

Linux has several virtual filesystems that need mounting

mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

Mount the EFI partition

Find out which parition is your EFI system partition. fdisk will tell you. It might be /dev/sda2. In a multi-drive system it could be on another drive. If you’re dual-booting Windows, and installed that first, it’ll be on your Windows drive.

mount /dev/sda2 /mnt/boot/efi
mount -o remount,rw /dev/sda2 /mnt/boot/efi

Also mount the /run filesystem

mkdir /mnt/hostrun mount –bind /run /mnt/hostrun

Chroot into the system

Now go into your Linux installation using chroot /mnt

You are now inside the Linux installation. Anything you type will be as if you’d booted your machine into the Linux installation on your hard disk.

If you used LVM, set that up

If your disks were set up using LVM, follow this too

mkdir /run/lvm
mount --bind /hostrun/lvm /run/lvm

Run the grub installer

Finally, now we’ve dug right down into our Linux installation, we can run the Grub installer by hand

grub-install /dev/sda

Note, there are no partition numbers on the end of /dev/sda, and it refers to the drive Linux is installed onto.

This should work, and there should be no errors(!) If there are, hopefully they’re more detailed than the errors given by the Linux installer.

Unmount everything

Now, just exit the chroot environment and unmount everything

umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
umount /mnt/boot/efi
umount /mnt/hostrun
umount /mnt/run/lvm
umount /mnt

Continue with the installer

If you need to, figure out how to tell your Linux installer to finish. Alternately, if you can’t, sit through the whole installation again. The fixes done in the previous section should be enough to let the installer put Grub on itself.