3

My hard-drive on Ubuntu running laptop died because of age and extensive use in the past, but before it died completely I managed to create persistent live-usb pendrive to use as temporally system. This solution worked and I run system from usb stick for month or so. Now I got 1000GB external hard drive and wanted to install fresh and fully functional system on it. Because I had persistent live-USB stick already, it was my main option to install new system, so I run live usb mode, plugged in external drive, and allocated partitions as follows:
Gparted window

I made installation (Ubuntu MATE 16.04), shutdown after completion, removed USB-stick but kept external HDD and turned laptop on. After checking bios settings and making sure it detected external drive and can load from it, I put it on top of boot priority and restarted.
Nothing happened, system did not load, it was just blackscreen and it looked like it tried to load from broken old HDD instead of new one. I plugged in USB stick, loaded Grub from flash drive, entered console mode and tried manually booting from external HDD to check if it installed properly, by running those commands in grub console:

set root=(hd0,msdos5)
linux /vmlinuz root=/dev/sda5 libata.force=1:disable
initrd /initrd.img
boot

libata.force is to disable old dead harddrive, because otherwise it will just keep slowing things down, as well as wasting itself.
After running those commands system loaded perfectly and as expected from external harddrive, so I figured that problem is somewhere in bootloader\grub. I did some googling, tried to comment grub menu skipping in /etc/defaults/grub:

#GRUB_HIDDEN_TIMEOUT=0 
#GRUB_HIDDEN_TIMEOUT_QUIET=false

and running update-grub, but it did not help.
I tried running grub-install as well, but it had no effect - system refused to load grub from external HDD.
I could not understand what is the problem, because laptop could run from USB stick with same version of system just fine, so I cracked open EFI partition from USB stick and tried to look what is different, and live-usb EFI partition had structure like this:

boot
    > grub
        [more files]
    > memtest
        [more files]
EFI
    > BOOT
        bootia32.efi
        bootx64.efi
    > ubuntu
        [more files]

While EFI partition on external HDD after installation looked like this:

EFI
    > ubuntu
        [same files as in EFI/ubuntu on live-usb]

So on HDD after installation there was no BOOT folder. After googling about UEFI I wound this in wikipedia:
https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface#Booting

This automated detection relies on standardized file paths to the OS loader, with the path varying depending on the computer architecture. The format of the file path is defined as /BOOT/BOOT.EFI;

So I've just copied BOOT folder from live-usb to my mounted /boot/efi partition into same EFI folder, removed usb stick and restarted.

After that step laptop actually booted from external harddrive and I was greet by grub console without anything else. By manually running linux-initrd-boot chain as before from usb-stick I was able to launch Ubuntu with no issues whatsoever.
That left me with actually working boot into linux from that external HDD, but no understanding of what is wrong and how to fix it. After looking on boot/grub content of efi on stick, I realized that it is pretty where it locates grub.cfg and all, so considering I've copied booting efi file from it, I created boot folder in my EFI partition and copied content of /boot from installation on external HDD to it, so my /boot/efi/boot was copy of /boot. After restarting system, it actually worked as it supposed to, it loaded standard ubuntu themed grub with option to load Ubuntu, and system worked with no issues at all.
While it leaves me with working system, fact that I had to manually tinker with it and way it all works is no good at all.

So my question is, what is wrong with UEFI installation in my case, why it does not load without /EFI/BOOT, why installation does not create it, and how do I fix this all properly?

Esuil
  • 371
  • 3
  • 13
  • How did you ran grub-install – Arun Jun 15 '17 at 01:43
  • @Arun I just run: sudo grub-install /dev/sda because I do not know that much about grub and that is what grub wiki told me to do. – Esuil Jun 15 '17 at 01:49
  • Great question! – fosslinux Jun 15 '17 at 02:56
  • UEFI only boots external installs from /EFI/Boot/bootx64.efi. We normally have to manually copy /EFI/ubuntu/shimx64.efi to be bootx64.efi. But you still need the ubuntu folder as the version of grub with a full install expects more support & boot files in /EFI/ubuntu folder.The version of grub in installer is a limited version with just the needed support to boot the live installer. Also: https://askubuntu.com/questions/559007/is-it-still-possible-to-install-ubuntu-to-an-external-harddrive-with-uefi – oldfred Jun 15 '17 at 03:57
  • @oldfred Thank you, I just deleted all files I created manually (folder /boot/efi/BOOT/ and /boot/efi/boot, after that I run grub install as follows:

    sudo grub-install --efi-directory=/boot/efi --boot-directory=/boot --removable
    Installing for x86_64-efi platform.
    Installation finished. No error reported.

    – Esuil Jun 15 '17 at 11:01
  • Well, it did create /EFI/BOOT, but system still can not load from it for some reason. I will try to see what is wrong with it. – Esuil Jun 15 '17 at 11:30
  • @oldfred This should not be happening, but for some reason "bootx64.efi" installed by grub-install does not load. When I replace it with one from usb-live, it does load grub console. But one from grub-install does nothing. What could be the problem? – Esuil Jun 15 '17 at 11:48
  • I think when you do the direct install, you do not get the grub.cfg and have to manually create grub.cfg and it will only be manually maintained. I have when only installing grub to a flash drive to boot ISO. You want to copy the grub/shim files from the /EFI/ubuntu folder from a full install to the /EFI/Boot & rename shim. And then you have all the normal grub files in /EFI/ubuntu. You may be able to do a full reinstall of grub2 using Boot-Repair. – oldfred Jun 15 '17 at 12:52

0 Answers0