Fixing a corrupted GRUB

Hello. I was refactoring parts of my Nix config and rebuilded. Went to sleep and woke up next day, booted my PC and encountered, what to me seems like, a broken or corrupted GRUB.

The GRUB is unusable and I’m bit sure how to get out of this mess.

I did try to mount my system using a live USB and reinstalling the bootloader. And I also tried resetting my BIOS.

Any help would be greatly appreciated.

System:
UEFI + systemd-boot
NixOS 25.05/Windows 11 dualboot

Don’t try to repair it, just delete all the GRUB files in the EFI system partition and re-run nixos-install from the live NixOS installer.

Hi and thank you for replying. Your suggestion did work, although I might have done it a bit differently than what I’m guessing you intended.

I didn’t reinstall NixOS, as I didn’t want to wipe my root partition, so I used this post as guidance.

Anyway here’s what worked for me:

  1. Boot a live NixOS USB and mount root and boot partitions:
    sudo mount /dev/sda5 /mnt
    sudo mount /dev/sda1 /mnt/boot

  2. Back up old bootloader (or alternatively delete it, if you are missing space):
    sudo mv /boot/EFI/nixos /boot/EFI/nixos.bak

  3. Enter:
    sudo nixos-enter
    unset SUDO_USER

  4. Disable logrotate in /etc/nixos/configuration.nix by adding:
    services.logrotate.enable = false;

  5. Rebuild and install new bootloader:
    nixos-rebuild boot -I nixos-config=/etc/nixos/configuration.nix --install-bootloader

  6. Reboot and you should be able to enter the bootloader normally like me. Make sure to now delete /boot/EFI/nixos.bak so that your /boot has space for rebuilding.

  7. Done !

I didn’t reinstall NixOS, as I didn’t want to wipe my root partition

You don’t have to wipe the root partition for that. The nixos-install command is idempotent: you can re-run it as much as you want and it will just make sure the system is in a consistent state.

So, in your case it would only rebuild the bootloader files, since you deleted them.

Huh, I didn’t realise. Oh well

Sidenote, if your kernels were at /boot/EFI/nixos, I’m pretty sure that’s systemd-boot, not grub. I believe NixOS’s grub module installs kernels in /boot/kernels or something like that. This is a good thing; NixOS maintainers generally recommend systemd-boot over grub. Just something worth noting. Also, you didn’t actually delete the systemd-boot loader, so I’m guessing --install-bootloader (which triggers bootctl install instead of bootctl update) probably just always overwrites it.

You are right, I was using systemd-boot, but for some reason I was sent into GRUB. Not sure why.