Bootloader

From NixOS Wiki
Revision as of 05:00, 5 May 2018 by imported>Gnidorah

FAQ

Am I booted in Legacy or UEFI?

The following command will print which boot mode you are using. This can be used on the NixOS installation image to determine which steps to follow in the guide.

[ -d /sys/firmware/efi/efivars ] && echo "UEFI" || echo "Legacy"

How do I remove older generations from the bootloader?

First, collect garbages in your system, then rebuild. The scripts will collect leftover files.

The first command, in the example below, removes everything older than 14 days.

sudo nix-collect-garbage --delete-older-than 14d 
sudo nixos-rebuild boot

How to deal with full /boot in case of EFI

systemd-boot (gummiboot) can't store kernels, initrd and other big stuff on root partition, so switch to grub

/etc/nixos/hardware-configuration.nix
fileSystems."/boot/efi" = ...
/etc/nixos/configuration.nix
boot.loader = {
  efi = {
    canTouchEfiVariables = true;
    efiSysMountPoint = "/boot/efi";
  };
  grub = {
     efiSupport = true;
     #efiInstallAsRemovable = true; # in case canTouchEfiVariables doesn't work for your system
     device = "nodev";
  };
};

Limiting amount of entries with grub

The grub module has an option to limit the number of configurations made available in the boot partition, boot.loader.grub.configurationLimit. Setting this to a lower amount than the default may help reduce the occasions where too many different kernels and initrds are added to the /boot partition or ESP.

Troubleshooting

Re-installing the bootloader

  • Something happened, and the bootloader doesn't work as expected.
  • The ESP was re-made and nothing was kept
  • The ESP wasn't mounted and I want to re-generate the menu entries

Booting from the installation media, mount the root partition, and the boot partition under /mnt. Next, run the command that the installer would run. This will re-install the bootloader.

mount /dev/[root partition] /mnt
mount /dev/[boot partition] /mnt/boot
NIXOS_INSTALL_BOOTLOADER=1 chroot /mnt \
    /nix/var/nix/profiles/system/bin/switch-to-configuration boot

New generations are not in the boot menu

The most common cause for this situation is when the ESP isn't mounted where NixOS expects it to be on UEFI systems. NixOS assumes the ESP is mounted under /boot and that it is on the ESP that NixOS will install the files needed for the boot process for UEFI systems.[1] This issue should affect all supported UEFI bootloaders equally for NixOS.

The usual fix for this problem is to add the missing entry for fileSystems."/boot" in hardware-configuration.nix (or where your mount points are defined).

If for some reason it is impossible to boot the existing generations, follow the steps in #Re-installing the bootloader to re-generate the menu entries, then boot in your system to add the missing configuration. The next generations should work as expected in your bootloader.

Wrangling recalcitrant UEFI implementations

Some UEFI implementations are just bad™. Some symptoms include:

  • Losing bootloader configuration choices either randomly, or on disk disconnection.
  • Not being able to manually edit the bootloader configuration.
  • Not being able to save the bootloader configuration.
  • Not being able to boot arbitrary bootloader configuration.

For those problematic EFI setup, or for a portable NixOS setup, it is possible to make use of the default path of the OS loader.

  • For an x86_64 computer, this path is /EFI/BOOT/BOOTX64.EFI. Try this one first.
  • For extremely problematic EFI implementations, an alternative path can be used, the default Windows bootloader location: /EFI/Microsoft/Boot/bootmgfw.efi.[2]

As a recommendation, you can either copy the default NixOS bootloader (which will be in the /EFI/NixOS-boot/ folder) or install an secondary bootloader like rEFInd. A copied NixOS bootloader will not be updated by the NixOS configuration. Using a secondary bootloader will add an intermediary step during the boot process, which can be customized to be as short as wanted, but should allow selecting EFI programs, even on different disks.

Alternatively, when using grub, using the boot.loader.grub.efiInstallAsRemovable option will install the bootloader at the default /EFI/BOOT/BOOTX64.EFI location.