Configure grub on EFI system

I’m having difficulties installing the grub bootloader on an efi system. Can’t find instructions for this. Does anyone know how it’s done?

Link to a reddit thread about the issue (https://www.reddit.com/r/NixOS/comments/bocx57/how_to_do_an_efi_boot_from_grub/)

Errors I’ve seen so far:

  1. ‘will not proceed with blocklists’
  2. uefi interactive shell after boot: https://i.imgur.com/Cbl2H2y.png
  3. /boot doesn’t look like an efi partition

I’m performing this install on a virtualbox image with nothing else installed atm. I’ve failed in just about every way possible, lol. What do?

3 Likes

So, uh, I got this to work but surely there’s a better way.

2 Likes

boot.loader.grub.device has to be set to nodev, otherwise the grub installer will assume it has to install the Legacy (MBR) bits too. When doing so, it will either embed itself into the “unused” part of an MBR formatted disk, or require that bios boot partition.

That is, assuming you indeed want to install grub only to boot using UEFI.

4 Likes

I tried setting boot.loader.grub.device = "nodev"; Both times I’ve done that have resulted in a reboot to the uefi interactive shell after install.

I’ve also stumbled onto another…er, thing. Imgur: The magic of the Internet

The install also works if I use "nodev" and remove the canTouchEfiVariables option. This time it works without the bios_grub partition. I see this as an absolute win.

However, I don’t understand entirely what happened. Or, rather, I don’t understand the nomenclature. Why does "nodev" mean uefi only? Why isn’t efiSupport = true sufficient?

Absolute fucking mysteries.

But the nixos user community seems pretty awesome. A couple of folks offered persistent help on the subreddit and @samueldr replied here. So, guess I’ll keep plugging.

1 Like

The main thing is that “nodev” means “don’t install grub to a device”, which is only a thing that can be done for legacy boot. Not sure why efiSupport isn’t sufficient, but the behaviour should make it possible to install grub both as UEFI and MBR at once, which is likely the reason for some of its idiosyncracies.

2 Likes

I was on that same problem in my personal notebook. After some experimentation, this is my configuration. I think it can be useful for you:

{ config, pkgs, ... }:

{
  boot.loader.grub.forceInstall = false; # RISKY!

  boot.loader.grub.enable                = true;
  boot.loader.grub.copyKernels           = true;
  boot.loader.grub.efiInstallAsRemovable = true;
  boot.loader.grub.efiSupport            = true;
  boot.loader.grub.fsIdentifier          = "label";
  boot.loader.grub.splashImage           = ./backgrounds/grub-nixos-3.png;
  boot.loader.grub.splashMode            = "stretch";

  boot.loader.grub.devices               = [ "nodev" ];
  boot.loader.grub.extraEntries = ''
    menuentry "Reboot" {
      reboot
    }
    menuentry "Poweroff" {
      halt
    }
  '';

Most important are the lines efiInstallAsRemovable and devices:

  • Using device as “nodev” (look!), GRUB will not be installed in a disk;
  • Setting efiInstallAsRemovable as true (look!), GRUB will be installed “regardless of the NVRAM state of the computer”
2 Likes

Isn’t there a way to tell nix to read a file into a string for eg the rvalue in extraEntries?

1 Like

Yes, builtins.readFile path documented in Introduction - Nix Reference Manual.

2 Likes

Are you doing this in virtualbox? Virtualbox doesn’t persist NVRAM, so boot.loader.grub.efiInstallAsRemovable has to be true, and/or boot.loader.efi.canTouchEfiVariables has to be false. That should work on any system. Setting the inverse should work on any system with working NVRAM though, and allow multiple OSes in the ESP.

2 Likes

Just chiming in to say that @ElvishJerricco’s suggestion about VirtualBox applies to Parallels, as well. I set boot.loader.grub.efiInstallAsRemovable to true and my virtual machine now works.

It’s possible that the hardware.parallels.enable option configures this, as well, but I don’t have it set as it’s currently broken.

1 Like