I want to reinstall Grub2 and I found these instructions: http://howtoubuntu.org/how-to-repair-restore-reinstall-grub-2-with-a-ubuntu-live-cd In my case, the bootloader is installed into the EFI partition. If I use the commands listed in this guide, will be the grub reinstalled into the EFI partition automatically, or will it be installed into the partition where Ubuntu is installed (obviously I don't want this)? Thank you very much!

share|improve this question
1  
The instructions in the provided link are valid for reinstalling GRUB in legacy BIOS mode only, this will not work in your case. To reinstall GRUB to an Ubuntu installation in EFI BIOS mode, please read my answer. :) – cl-netbox Sep 29 '16 at 16:36
    
Thank you very much! :) I have some questions: when I installed Ubuntu in my UEFI system, I found two entries in the bios. Is there a way to have a unic ubuntu entry? In case of MBR partition table (so no EFI or any other boot partition), can I use the same commands except for: sudo mount /dev/sd** /mnt/boot/efi ? – Generoso Sep 30 '16 at 10:11
    
You can try to remove the second Ubuntu entry with : sudo efibootmgr (lists all entries) | sudo efi bootmgr -b <entry-number> -B .... and to reinstall GRUB in legacy BIOS mode execute these commands : sudo mount /dev/sd** /mnt | sudo grub-install --boot-directory=/mnt/boot /dev/sd* (* = disk | ** = system partition) ! :) – cl-netbox Sep 30 '16 at 10:54
    
Perfect :) Anyway, having a UEFI system and so a EFI partition, is there a way to avoid getting grub overriden when I perform a new Windows installation? – Generoso Sep 30 '16 at 12:18
    
Well, Microsoft doesn't take care for anything else but their own products, so you can install Linux systems without doing any harm to Windows - unfortunately this isn't the case the other way around - so when you install Windows after you have installed Ubuntu, you have to restore the GRUB boot loader afterwards. :) – cl-netbox Sep 30 '16 at 13:23
up vote 14 down vote accepted

Reinstall the GRUB boot loader to your Ubuntu installation in EFI mode this way.
Boot from the Ubuntu installation media and select 'Try Ubuntu without installing'.
Once you're on the Live desktop, open a terminal and execute these commands :

sudo mount /dev/sdXXX /mnt
sudo mount /dev/sdXX /mnt/boot/efi
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt
grub-install /dev/sdX
update-grub  

Note : sdX = disk | sdXX = efi partition | sdXXX = system partition
To identify the partitions use GParted (included in the install media).
After completion GRUB will be installed in the separate EFI partition.

share|improve this answer
    
+1 but why don't you install from Ubuntu itself? – Mark Yisri Nov 8 '16 at 13:55
1  
@MarkYisri : Thank you very much ! :) Because it is the safest way to reinstall the GRUB boot loader without corrupting things and in case the system does not boot properly ... the only way to do it ! :) – cl-netbox Nov 8 '16 at 13:58
    
After exchanging an Intel NUC the new device didn't start from the old HDD. This fixed it. You made my day - thanks a lot! – Möhre Oct 8 '17 at 19:06
    
In this solution, how does 'grub-install' know it is supposed to install in EFI mode? – user334639 Oct 12 '17 at 0:38
    
@user334639 This happens right because the EFI partition gets recognized automatically ... :) – cl-netbox Oct 12 '17 at 10:23

in addition to ci-netbox answer.
If your pendrive OS version does not match the one that is installed on the disk, grub-install may have difficulties to identify the right grub installation:

$ sudo chroot /mnt
# grub-install /dev/sdX
grub-install: error: /usr/lib/grub/i386-pc/modinfo.sh doesn't exist. 
Please specify --target or --directory.

Try to identify manually the installation to use

# ls /usr/lib/grub/
grub-mkconfig_lib  x86_64-efi  x86_64-efi-signed

Then restart grub-install :

# grub-install --target=x86_64-efi /dev/sdX 
Installing for x86_64-efi platform.
Installation finished. No error reported.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.