NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.61k stars 13.77k forks source link

Stuck with grub as the bootloader, contrary to configuration.nix #114827

Open cmm opened 3 years ago

cmm commented 3 years ago

Describe the bug Unable to get rid of grub

To Reproduce Steps to reproduce the behavior:

  1. Set boot.loader.systemd-boot=false and boot.loader.grub=true (and configure it sensibly so it works, of course), nixos-rebuild switch. The boot loader is now grub
  2. Flip the settings around so now the bootloader is supposed to be systemd-boot. nixos-rebuild switch.
  3. Observe that the active bootloader is still grub -- which, due to the discrepancy between what nixos thinks and the reality, means that nixos-rebuild switch no longer actually switches (well, it does, but only until reboot)

Expected behavior nixos-rebuild switch should [de]activate bootloaders according to the settings.

Additional context It's a seemingly-normal and reasonably modern EFI minicomputer with a standard NixOS 20.09 on it (first installed 20.03, no installation tweaks that I remember), boot is its own vfat partition and has plenty of free space. I think it was on the unstable channel for a little while, not sure.

Metadata Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
Patagonicus commented 3 years ago

I think you need to use nixos-rebuild switch --install-bootloader (or nixos-rebuild boot --install-bootloader). Without that flag it should still switch the current system, but that will most likely be lost on reboot as it will update the config for systemd-boot, but not for Grub, but Grub is still installed.

nixos-rebuild does not reinstall the bootloader by default.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

Atemu commented 1 year ago

I think what's happening is that when you switch bootloaders, the old one always remains installed. It's not part of the new closure, so NixOS does not know to explicitly uninstall it.

You need to switch your firmware to the new bootloader too or manually uninstall the old bootloader.

Uninstalling all bootloaders on every boot would be the solution but that probably is not the best idea. We'd have to mark NixOS-installed bootloaders somehow and only uninstall those (unless activated in the current generation) to not disturb other distros installed besides NixOS.

Even that has problems though if you dual-boot NixOS as we wouldn't want to uninstall the other NixOS installation's bootloaders.
To do that we'd have to mark all of our bootloaders with an installation-specific ID somehow. I'm not sure that's possible.