0

I installed recently Ubuntu 18.04 on a multiboot system in UEFI mode creating the necessary partitions (including EFI) during custom installation, in a separate SSD, selecting the appropriate partition (/dev/sda1) for the bootloader installation.After today's update on reboot I realized that the bootloader's ubuntu folder instead of being in the EFI partition of the ubuntu installation drive appears to be in the EFI partition of the Windows installation drive. However I can boot with either Ubuntu or Windows 10 via Clover bootloader on a third drive. How can I check what the current situation is (where is GRUB installed?) and how can I restore GRUB in the EFI partition of the Ubuntu installation drive without having to reinstall Ubuntu?

Andrew-63
  • 141

2 Answers2

2

Some info here:

How do I install Ubuntu to a USB key? (without using Startup Disk Creator)

Chroot method from live installer. You then mount correct ESP.

Can I install in UEFI mode with the alternate installer?

How can I reinstall GRUB to the EFI partition?

Change mount of ESP in fstab first, as grub-install will use default unless specified. You may have to reboot & ESP must exist or reboot will have issues.

man efibootmgr
man grub-install
sudo grub-install --bootloader-id ubuntu /dev/sda1

Check that fstab & UEFI have correct entries. UUID must be of correct ESP.

lsblk -f
cat /etc/fstab
sudo efibootmgr -v

If you have just copied files from where Ubuntu default installed to the ESP you want to use, you need to edit fstab and use efibootmgr to create new entry to boot from correct ESP. You check GUIDs (aka parttype) to know if that is correct. And then use efibootmgr to delete (-b & -B ) obsolete ubuntu boot entry with old GUID/partuuid. Efibootmgr defaults to sda1 or first drive & partition, you have to specify drive with -d and partition with -p parameters.If UEFI entry not correct you can add new entry.

lsblk -o +parttype
sudo efibootmgr -c -g -w -L "ubuntu" -l "\EFI\ubuntu\shimx64.efi" -d /dev/sda -p 1
sudo efibootmgr -v
sudo efibootmgr -b XXXX -B

This is why using Boot-Repair's advanced mode which walks you thru a simple chroot to re-install grub is easier. You still need to do the housecleaning of duplicate/old ubuntu entry in UEFI.

oldfred
  • 12,100
0

In UEFI the bootloaders are just files on a FAT filesystem. Just copy everything in the sda EFI partition to the (empty) Ubintu disk's EFI. You wont need the Microsoft bootloaders, but copying them is a good backup. The Ubuntu device should now boot (the initial setup used the right UUID for the Ubuntu root, so no changes needed). Select the disk from the EFI boot menu (some function key at power-up). You can remove grub from the first disk by removing its "ubuntu" EFI boot entry with efibootmgr (and then optionally delete the files in the sda EFI/ubuntu (and rename the bkpbootx64.efi to bootx64.efi). Leaving it as is will work, but you the have grub spread across two disks, and both need to be present to boot grub from sda.

See bugs 1396379, 1173457, and 1229488, and add yourself to the "does this affect me" list.


The EFI partition Ubuntu directories

EFI/BOOT/bootx64.efi      (A copy of shimx64.efi)
   |     grubx64.efi      (Must be in the same directory as shimx64.efi)
   |     bkpbootx64.efi   (The old copy of bootx64.efi, probably the Microsoft bootmgfw.efi.)
   |
   |ubuntu/grub.cfg       (grubx64.efi looks here regardless of where it is run.)
   |       shimx64.efi    (Good to have shim/grub copies here in case the ones in BOOT 
   |       grubx64/efi     get overwritten...)
   |
   ...Others, Microsoft...

The EFI/BOOT files are the device boot loaders. They typically do not have a nvram entry, so may boot when attached to any UEFI computer. The shim/grub combination will boot with secure boot both enabled or disabled.
I used to agree with oldfred that grub-install was not the problem, but trying to get the above setup with grub-install indicates I have to file several new bugs. I suppose multiple runs of grub-install will work or combinations of the switches, one with --removable to properly set up the BOOT, one with efi-directory etc. but the default of putting into BOOT shimx64.efi as bootx64.efi without grubx64.efi simply will not boot, as several recent questions about"missing grubx64.efi indicate.

To clean up the original EFI, just mount it and delete the files you don't want (.../EFI/ubuntu/..., and rename(?) the bkpbootx64.efi to bootx64.efi, assuming that's the windows bootmgfw.efi copy.

ubfan1
  • 17,838
  • The install issue is not grub, but Ubiquity. In UEFI mode it only uses the first ESP - efi system partition. Posted work around to manually unmount & mount correct ESP during install https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1396379 You can use Boot-Repair or just a reinstall of grub-efi-amd64 to correct ESP from inside your install. Other work around is to disconnect other drive or turn it off in UEFI so not seen. see also: https://askubuntu.com/questions/1167910/unable-to-properly-boot-linux-from-external-ssd/1167940#1167940 – oldfred Dec 12 '19 at 17:20
  • Please, could You explain how to reinstall grub-efi-amd64 to correct ESP from inside Ubuntu install and, if possible, to remove ubuntu bootloader files from EFI partition on the windows 10 drive? – Andrew-63 Dec 13 '19 at 07:42