I only changed my motherboard and cpu. I can’t see boot option for nixos on my motherboard at all. I have 2 ssd, one windows other is nixos and their bootloader is different. Windows is able to boot when I changed my motherboard out of the box but I can’t see any uefi bios option on nixos. I was remember I was installed nixos with gnome iso and enabled systemd-boot on configuration.nix
users says because of initramfs but I have no idea how can I solve this on nixos. It would be great if you guys now how to do it or how to use ubuntu solution on nixos.
I was using 23.11 and upgraded new version 24.05. I am thinking about the reinstalling from scratch but I prefer not to.
Maybe the boot order got messed up. From a live ISO, you can use efibootmgr to find out the current order:
nix-shell -p efibootmgr --run "efibootmgr -v"
It should give you BootOrder: YYYY,XXXX,ZZZZ and a description of each entry, for example BootXXXX* Linux Boot Manager and BootYYYY* Windows Boot Manager.
If the bootloader for linux does not come first (left has most priority), you need to change it with:
Even though there are no errors when running such a command, that doesn’t work, unfortunately, because it doesn’t set the necessary EFI variables.
There’s a much simpler solution:
Boot a live ISO
Mount the ESP to say, /boot
Run bootctl --path=/boot install
Reorder the entries using efibootmgr to put the NixOS-managed bootloader up first
Currently this last step doesn’t work, because the version of efibootmgr in nixpkgs is broken, however, this should be fixed if the relevant PR is merged (EDIT: PR’s merged now.)
It was a solution for me when I did it that time, and I used NixOS until then, never experiencing any errors due to boot issues. For future usage, are you insistent on reinstalling the bootloader in your way, or is it okay to use the working command from @hexa?
Well, empirically, it’s inadequate somehow. I just had a motherboard firmware update after which bootctl worked and NIXOS_INSTALL_BOOTLOADER=1 did not.
That’s not really possible, because NIXOS_INSTALL_BOOTLOADER=1 literally causes it to run bootctl install. So either you made a mistake or there’s some obscure bug.
For all I know, bootctl doesn’t work in nixos-enter. I’m just reporting my observations for the sake of the next person who runs into this, not trying to debug why nixos’ cursed perl scripts may or may not work.
(And by the way, I happened to find out that envvar from reading the code in the first place, not from this thread.)
Well, empirically, it does, because I’ve done it a few dozen times by now. I also know why it works. The nixos-enter program creates a mount namespace and rbind mounts the API filesystems, including everything under /sys which includes the efivarfs. The systemd-boot-builder would fail at the bootctl install step if this wasn’t working.
Seriously, I’m fairly sure you simply made a mistake, such as running NIXOS_INSTALL_BOOTLOADER=1 sudo /run/current-system/bin/switch-to-configuration boot, which wouldn’t work because the sudo would wipe the environment variable.
That’s very strange, and is definitely a bug that I’ve never seen after doing this and helping others with it many times. If you have the ability to reproduce that on a system, it would be useful to file an issue so we can fix it.
Also, I’m not calling you “a complete idiot.” I’m trying to understand something that doesn’t make sense to me given how I know these things work. I’m sorry if I came off as offensive. The advice you gave about bootctl install is not as generally applicable, as it doesn’t generate boot entries, so it would be better if we understood why the more comprehensive solution didn’t work for you. The only explanation I’ve thought of so far is that you made a mistake, which is not a criticism; we all make mistakes. If you didn’t, then we’ve got a bug on our hands that doesn’t yet make sense to me and seemed rather unlikely before.
Another possibility is that you didn’t have boot.loader.efi.canTouchEfiVariables set, since it defaults to false, which causes systemd-boot-builder.py to pass --no-variables to bootctl. But then I’m not sure how the system would have booted before the firmware update, unless the update caused it to stop respecting the BOOTX64.EFI fallback loader… I dunno, this is confusing.
Yes, my suggested solution is only applicable when the bootloader’s state itself is correct, and the only change needed is to get the firmware to recognise said bootloader. (Although I’d question how that generation would be the “current system” if it was never activated and didn’t generate the corresponding boot entry.)
The default might be false but n-g-c sets it to true when booting under EFI:
As does the graphical installer:
So any relatively recent config would have this set to true, as I do:
Yea. A lot of people handroll their configs though so I had to ask. Again, I’m not trying to tell you that you don’t know what you’re doing. As a member of the NixOS teams for systemd and the installer, my responsibility is to fix these things when people have issues like you did. Based on how all the relevant code is written and how it’s expected to work, I can’t find an edge case to explain what happened in your experience. So I’d really like to find what I’m missing, if you can think of any details that would help.