Sunday, March 18, 2018

Fixing grub2 on windows 10

Problem: Installed Linux on a external HDD connected to windows 10 using live CD and Grub got installed on internal HDD pointing to grub.cfg on external HDD. So if I remove the external HDD, grub.cfg is not found and can't boot windows.

Resolution:
1. Boot Linux by connecting the external HDD.
2. Mount the efi partition (Lets say its /dev/sda1. In my case it was first partition on internal HDD, about 256M in size)
  #mkdir /tmp/efi
  #mount /dev/sda1 /tmp/efi
3. Install grub.
  #grub-install --boot-directory /tmp/efi/grub --efi-directory /tmp/efi --uefi-secure-boot

4. Create the cfg file
  #grub-mkconfig > /tmp/efi/grub/grub/grub.cfg
 
 
Not tried but may be useful:
when you have grub prompt, try this:
echo $prefix

By default grub will look for $prefix/grub.cfg. If you can copy your grub.cfg from external HDD to the default location, that may work.