References: grub-install man page; GNU Grub Manual; Ubuntu Help; Arch Wiki.
Simple method. Run sudo grub-install /dev/sdx, where x = device to which installing the boot loader. Works for both BIOS and UEFI. For example, returns control of Grub to the primary system after installing a second as a test box (by default, the last system installed controls Grub). As mentioned, for this to work, you have to be booted into the system you want to control Grub.
Live session method. Works with both BIOS and UEFI, but the commands are a bit different. First you mount the system partition to /mnt. If there is a boot partition, this must be mounted also; insert a new second step: sudo mount sdxn /mnt/boot, where sdxn is the boot partition's ID. Then, in UEFI, you mount the EFI partition. The command to install Grub is very simple because it invokes a script which does most of the work behind the scenes. Notice the target for grub always is the device, for illustration sda. This is true in UEFI as well as BIOS. See GNU Grub Manual.
For BIOS, assuming the system/root partition is sda1. Modify as appropriate, of course, if the system partition is sda5, sdb1, etc.
Code: Select all
sudo mount /dev/sda1 /mnt
sudo grub-install /dev/sda --boot-directory=/mnt/boot
Code: Select all
apt install grub-efi-amd64-signed shim-signed
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot/efi
sudo grub-install /dev/sda --boot-directory=/mnt/boot --uefi-secure-boot
chroot. Mainly useful if for some reason you need to run update-grub, as well as install/reinstall Grub. For that matter, if all you need to do is update Grub from the live session, you do that the same way; just leave out the grub-install line. As with the regular live session method, if you have a boot partition, you need to insert a second step to mount it.
For BIOS, still assuming the system partition is sda1:
Code: Select all
sudo mount /dev/sda1 /mnt
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt
grub-install /dev/sda
update-grub
exit
sudo umount -R /mnt
For UEFI, assuming the system partition is sda2 and the EFI partition is sda1:
Code: Select all
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot/efi
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
sudo cp /etc/resolv.conf /mnt/etc
modprobe efivars
sudo chroot /mnt
apt install grub-efi-amd64-signed shim-signed
grub-install /dev/sda --uefi-secure-boot
update-grub
exit
sudo umount /mnt/boot/efi
sudo umount -R /mnt
Purge-and-Reinstall. It's rare to need to escalate this far. The few cases I've noticed entailed someone or something having bollixed the Grub scripts in /etc/grub.d (yes, I'm looking at you, Grub Customizer). If still able to boot, the commands are simple:
For BIOS: Run apt purge grub-common; will be prompted to confirm removal of boot loader. Then run apt install grub-pc os-prober. Select destination for boot loader when prompted (tap space key to select). Unless you have a very good reason, install to the device, not the system partition.
os-prober is removed by purge but only a recommended package on reinstall, so specifying additionally. Same with shim-signed for UEFI.
For UEFI: Similar, but the packages to install are different. Run apt purge grub-common, then apt install grub-efi-amd64-signed os-prober shim-signed. Select destination for boot loader if prompted (probably won't be).
Purge-and-Reinstall in chroot. This is for the scenario where can't boot. Remember, if you have a boot partition, insert a second step to mount it.
For BIOS, assuming the system partition is sda1:
Code: Select all
sudo mount /dev/sda1 /mnt
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
sudo cp /etc/resolv.conf /mnt/etc
sudo chroot /mnt
apt purge grub-common
apt install grub-pc os-prober
exit
sudo umount -R /mnt
Code: Select all
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot/efi
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
sudo cp /etc/resolv.conf /mnt/etc
modprobe efivars
sudo chroot /mnt
apt purge grub-common
apt install grub-efi-amd64-signed os-prober shim-signed
exit
sudo umount /mnt/boot/efi
sudo umount -R /mnt