Reinstall Grub on a dual boot when Windows wipes it - lmmx/devnotes GitHub Wiki

Windows (8.1, but probably others) has wiped GRUB twice now when I ran it. To fix (via):

  • insert Linux Mint live CD
  • restart
  • hit F12 to enter manual BIOS boot select
  • select the CD ROM drive (below the Windows boot)

This will run the 'trial CD' of a Linux Mint operating system, with access to a shell from which to chroot into the system and install GRUB.

Partitions are observed by running gparted on the Linux Mint OS.

NB my Linux system partition is sda6 - change as appropriate. NB I have an EFI System Partition (ESP) - a boot partition - if you don't, omit the line using sda3

In general only view this as a guide, see the Ubuntu help page

From the terminal:

  • sudo mkdir /mnt/boot
  • sudo mount /dev/sda6 /mnt
  • sudo mount /dev/sda3 /mnt/boot
  • for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
  • sudo chroot /mnt
  • grub-install --target=x86_64-efi --efi-directory=/boot/efi /dev/sda

Edit 2021:

  • my OS disk is /dev/nvme0n1 (replaces /dev/sda)
  • Linux system partition is now nvme0n1p3 (replaced sda6)
  • boot partition is nvme0n1p1 (replaces sda3)

From the terminal:

  • sudo mkdir /mnt/boot
  • sudo mount /dev/nvme0n1p3 /mnt
  • sudo mount /dev/nvme0n1p1 /mnt/boot
  • for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
  • sudo chroot /mnt
  • grub-install --target=x86_64-efi --efi-directory=/boot/efi /dev/nvme0n1

If you receive any errors (use man pages/Google to resolve them), next time ensure to run grub-install using the --recheck flag, which deletes a 'device map' (see full workflow explanation here)

  • update-grub

All done. You may want to have a look at the results with ls /boot/efi before exiting chroot.

  • (Ctrl + D out of chroot or) exit
  • sudo reboot

(Not necessary to unmount things)

  1. First attempt to do this did not work :disappointed:
  2. Second attempt adding --root-directory=/mnt/ (via) did not work :disappointed:
  3. Third attempt adding mkdir /mnt/boot (via)

NB the Arch installation wiki goes into the details of the flags (such as grub-install's --efi-directory, without which I received an error "cannot find EFI directory"). However, the wiki implies this flag should be /boot, whereas it is specified explicitly in this Arch user thread as /boot/efi

  • Side note: I ran the Startup Disk Creator tool in Ubuntu to make a Mint boot live USB, and while running grub-install the installer was erroring due to trying to include this live USB in the grub config!
    • (remove your live USB when running the grub-install step above)
    • the error was grub-probe: error: cannot find a GRUB drive for /dev/sdc1. Check your device.map
      • (N.B. grub2 doesn’t actually use a device.map any more, it doesn’t exist under /boot/grub/)

Further troubleshooting

After doing this, if you still don’t see grub it may be due to the defaults: to inspect your settings, open the text file /etc/default/grub and compare the values configured there to the docs from info -f grub -n 'Simple configuration'

  • I’ve come across GRUB_TIMEOUT_STYLE=hidden which will change the timeout setting from “how long to wait before closing grub and booting the default” to “how long to wait for the Esc key to be pressed to show the grub boot menu”. When this is used in combination with GRUB_TIMEOUT=0 it means that there is an immediate selection of the default (GRUB_DEFAULT=0 will make this default the 0’th i.e. first item in the list)
  • If you’re trying to catch grub in a short time frame you may want to add GRUB_INIT_TUNE="480 440 1" to get a beep at grub start
  • As the header comment says in /etc/default/grub:

If you change this file, run update-grub afterwards to update /boot/grub/grub.cfg