Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos-generate-config: update default to use grub for UEFI as well #18731

Closed
wants to merge 1 commit into from

Conversation

obadz
Copy link
Contributor

@obadz obadz commented Sep 18, 2016

Also updates & beefs up UEFI installation instructions to close #9096

Currently we default to systemd-boot (previously gumniboot) when the
installation device (on which nixos-generate-config typically runs) is
booted in UEFI mode, and we default to GRUB when the device is booted
in BIOS mode.

This patch attempts to unify the two branches by using GRUB in both
cases. The advantages are:

  • Consistency between the two cases
  • GRUB can create disks that are bootable in both UEFI and BIOS mode
  • GRUB can install itself on a UEFI device while booted in BIOS mode
    (using efiInstallAsRemovable to avoid touching EFI vars)

For systems booted in UEFI mode, it will generate this config:

{
  # Use the GRUB 2 boot loader.
  boot.loader.grub.enable = true;

  # Define which hard drive you want to install GRUB on for BIOS/legacy mode
  # booting (use "nodev" if you don't care to support legacy mode)
  boot.loader.grub.device = "nodev";

  boot.loader.grub.efiSupport = true;
  boot.loader.grub.efiInstallAsRemovable = false;
  boot.loader.efi.canTouchEfiVariables = true;
  # boot.loader.efi.efiSysMountPoint = "/boot/efi";
}

For systems booted in BIOS mode, it will generate this:

{  
  # Use the GRUB 2 boot loader.
  boot.loader.grub.enable = true;

  # Define which hard drive you want to install GRUB on for BIOS/legacy mode
  # booting (use "nodev" if you don't care to support legacy mode)
  # boot.loader.grub.device = "/dev/sda";

  # The following options are only useful if you want to support EFI booting
  # boot.loader.grub.efiSupport = true;
  # boot.loader.grub.efiInstallAsRemovable = true;
  # boot.loader.efi.canTouchEfiVariables = false;
  # boot.loader.efi.efiSysMountPoint = "/boot/efi";
}

The manual post-patch looks like this:


2.1. UEFI Installation

NixOS can also be installed on UEFI systems. The procedure is by and large the same as a BIOS installation, with the following changes:

  • You will need your drive's partition table to be stored using the GPT, rather than MBR, format. (That is likely already the case if your current operating system boots in UEFI mode). Use gdisk rather than fdisk to partition your disk.
  • If you don't have one already, you will need to create a separate partition (called the EFP) with partition code EF00 and the GPT boot flag. It should be formatted as a vfat filesystem and be about ~100-200MB. You set configurations to have it mounted in boot.loader.efi.efiSysMountPoint (/boot by default).
  • If you want your device to be bootable in BIOS (legacy) mode as well, and if you don't have one already, you will need to create a separate "BIOS boot" partition with partition code EF02. This partition does not need to be formatted, or mounted, and can be as small as 1MB.
  • During installation, after mounting your installation partition to /mnt, you must manually mount the EFP partition to /mnt/boot (or your selected mountpoint).
  • You must set boot.loader.grub.efiSupport to true. nixos-generate-config should do this automatically for new configurations when the installation device is booted in UEFI mode.
  • If you have not booted the installation device in UEFI mode, you'll probably need to set boot.loader.grub.efiInstallAsRemovable to true and boot.loader.efi.canTouchEfiVariables to false.
  • You may want to look at the options starting with boot.loader.efi and boot.loader.grub as well.

Also updates & beefs up UEFI installation instructions to close NixOS#9096

Currently we default to systemd-boot (previously gumniboot) when the
installation device (on which nixos-generate-config typically runs) is
booted in UEFI mode, and we default to GRUB when the device is booted
in BIOS mode.

This patch attempts to unify the two branches by using GRUB in both
cases. The advantages are:

- Consistency between the two cases

- GRUB can create disks that are bootable in both UEFI and BIOS mode

- GRUB can install itself on a UEFI device while booted in BIOS mode
  (using efiInstallAsRemovable to avoid touching EFI vars)
@mention-bot
Copy link

@obadz, thanks for your PR! By analyzing the annotation information on this pull request, we identified @thatdocslady, @edolstra and @aszlig to be potential reviewers

@obadz
Copy link
Contributor Author

obadz commented Sep 18, 2016

I do also wonder if we should set the default EFP mountpoint to /boot/efi rather than /boot since GRUB puts stuff in /boot that don't need to be on the EFP.

There's some discussion about this here: https://bbs.archlinux.org/viewtopic.php?id=175376

That's also the default on Ubuntu: /dev/sda1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

@obadz
Copy link
Contributor Author

obadz commented Sep 18, 2016

also cc @shlevy @DamienCassou @domenkozar

@shlevy
Copy link
Member

shlevy commented Sep 18, 2016

IMO grub is overkill given the existence of the EFI boot stub in the kernel and the services EFI provides, plus the integration of systemd-boot with systemd is nice. But I don't feel too strongly about this as long as it works, so I'll leave this to other reviewers.

@obadz
Copy link
Contributor Author

obadz commented Sep 18, 2016

@shlevy, I don't know how I feel about copying kernels on the EFP when they could be in the /nix/store.

Could you describe the benefits of the integration with systemd-boot ?

@obadz
Copy link
Contributor Author

obadz commented Sep 18, 2016

nix-build nixos/release.nix -A tests.boot.biosCdrom and nix-build nixos/release.nix -A tests.boot.uefiUsb pass.

@obadz
Copy link
Contributor Author

obadz commented Sep 18, 2016

IRC log from #grub

<obadz> should /boot be the EFP, or /boot/efi? (I know both work, but what's best practice)
<[anonymized_to_protect_the_innocent]> obadz: /boot/efi
<obadz> do you have any pointers to a doc that could help document that? (I'm packaging for NixOS)
<[anonymized_to_protect_the_innocent]> obadz: not off the top of my head, but basically the contents of the ESP are quite precisely defined in the UEFI specification and not a particularly good fit for the traditional contents of /boot

@cmfwyp
Copy link
Member

cmfwyp commented Sep 18, 2016

Use gdisk rather than fdisk to partition your disk.

This sentence can be removed from the documentation. The fdisk tool supports GPT too, so gdisk is not necessary. There's no reason to recommend a particular partitioning tool: fdisk, cfdisk, gdisk, cgdisk, and parted all support GPT.

@obadz
Copy link
Contributor Author

obadz commented Sep 18, 2016

@cmfwyp, I thought about removing it, but then I couldn't find a way to set the EFI boot flag with fdisk, so left that comment.

@edolstra
Copy link
Member

Not too long ago I would have been all in favor of using grub everywhere, but now I'm not so sure. I kind of appreciate the simplicity of systemd-boot. The other two advantages you listed are about booting in BIOS mode, which don't really matter for modern UEFI systems, so I'm not sure if we should bring back all that grub complexity for those systems.

Also, I don't have the impression that grub is very actively maintained. The last release is from 2012...

@Mic92
Copy link
Member

Mic92 commented Oct 9, 2016

I would also favor systemd-boot over grub.

@grahamc
Copy link
Member

grahamc commented Jul 16, 2017

@obadz I'm inclined to close this. Thoughts?

@grahamc grahamc closed this Jul 26, 2017
@obadz
Copy link
Contributor Author

obadz commented Jul 26, 2017

@grahamc, fine by me 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NixOS UEFI installation instructions incomplete
9 participants