Ubuntu – Standalone Grub2 EFI installation – grub.cfg placement

bootgrub-efigrub2uefi

I'm trying to use Grub2 as the boot manager on an EFI system in standalone mode. (The only persistent harddisk has OS X on it; Linux and Windows drives may or may not be present at times, hence the standalone mode.)

I'm using SuperGrub2Disk, which is one EFI executable, and as I understand it Grub2's executable in this mode has an embedded disk image that it mounts for its root partition, with a copy of its own config file inside.

I'd like to override or amend this config file with an external grub.cfg. I've tried placing it next to the grub EFI executable or in the root of the ESP partition, but it's not being recognized. I've also tried to load it from a grub command line by the following command:

configfile (hd3,gpt1)/grub.cfg

This seems to have no effect other than clearing the screen – even though the config file is there as confirmed by ls.

Could anyone tell me if there's a way to use an external config file with an EFI standalone blob?

Best Answer

GRUB 2 binaries include hard-coded references to their configuration files. I haven't really been keeping track of all the gory details, but as I understand it, there are two EFI GRUB 2 binaries for Ubuntu on AMD64/x86-64 systems:

  • grub2-efi-amd64 -- This is the version of GRUB 2 that's used on computers that do not use Secure Boot. As I understand it, the binary itself is linked on your computer from pre-compiled components included in the package. The resulting binary refers to a grub.cfg file on your Linux installation's /boot/grub directory. Thus, you can't use the grubx64.efi binary installed from this package on one computer on another one, because the binary is customized for the computer on which it was created.
  • grub2-efi-amd64-signed -- This version of GRUB 2 is compiled and linked on a Canonical system so that it can be signed with a Secure Boot key. One side effect of the requirement that the binary be signed is that it cannot be customized for your system, and as a result, this version of grubx64.efi looks in the same directory as the binary for grub.cfg. On an Ubuntu system, this grub.cfg file searches for /boot/grub/grub.cfg, but in principle it could be customized to do something else.

Thus, in your case you can't use the unsigned GRUB 2 binary; if you want to use a stock Ubuntu GRUB 2 binary, you must use the signed one. Alternatively, you could build your own binary, as described here, among other places.

In your case, though, I don't think GRUB 2 is really optimal. Both rEFIt (which is now abandoned) and my fork of it, rEFInd, feature dynamic scanning for available boot loaders. Thus, if you install rEFIt or rEFInd to your internal disk's EFI System Partition (ESP) and put the boot loaders for your OSes on their respective removable media, rEFIt/rEFInd will provide you with options to boot those OSes if and only if the appropriate disk is plugged in. This behavior, however, will depend on proper management of your boot loaders, placing each one on the ESP of its respective disk; if your boot loaders are all stored on your internal disk's ESP, rEFIt/rEFInd will show non-functional OS options at all times, just like GRUB 2 would. In either case, using rEFIt or rEFInd will obviate the need to delve into the morass of manual GRUB 2 configuration.