Failed rebuild due to not enough space in boot

Hi there

so I seem to have a problem with updating my NixOS due to not enough space in boot. Here is the error I get from sudo nixos-rebuild switch:

OSError: [Errno 28] No space left on device: '/nix/store/kvs8nrbqgvzvmgw6f1fcrxn2gszhcbs8-initrd-linux-6.12.33/initrd' -> '/boot/EFI/nixos/kvs8nrbqgvzvmgw6f1fcrxn2gszhcbs8-initrd-linux-6.12.33-initrd.efi'
Failed to install bootloader
Command '['systemd-run', '-E', 'LOCALE_ARCHIVE', '-E', 'NIXOS_INSTALL_BOOTLOADER', '--collect', '--no-ask-password', '--pipe', '--quiet', '--service-type=exec', '--unit=nixos-rebuild-switc

I have already tried to no avail:

  1. sudo nix-collect-garbage
  2. sudo nix-collect-garbage --delete-older-than 3d

Thanks for any help!

How many generations are on your instance?
nixos-rebuild list-generations

Seems like you’re on the right track, but something from the /boot dir is not yet ready for the garbage collection to be picked up.

Removing the generations, running garbage collection and updating the bootloader (with a rebuild) should clear your problem. Should :tm:

Unfortunately, I believe the standard tools can’t handle the situation where /boot is already full. Because they first move the new data to /boot, update the menu, then remove the data that’s no longer needed. That’s good for atomicity, but bad if /boot is full, since they can’t break out of the error condition.

Afaik the only way to get things working again is to manually delete the kernels/initrds from some old generations out of /boot to make enough space for the script to operate again, then run a rebuild. (After you’ve garbage collected enough generations to avoid a repeat of the same problem.)

There are options that can help you avoid the same thing in the future, like boot.loader.<your_bootloader>.configurationLimit, and/or setting up an automatic gc on a schedule that keeps the number of generations down.

1 Like

Thanks for your help!

After all else failed, I had to sudo rm -rf system-50-link after which I was able to rebuild. The main Problem I think is that my /boot is way to small, this might have to do with the fact that I installed NixOs next to an existing Windows and did not think about the size of /boot while installing NixOs.

I ran into this a while ago. I did the garbage collection and that didn’t help. but I found that garbage collection /plus/ rebooting did help. not sure why. I just assumed that some items were marked as ‘clear’ but not actually removed until the reboot.

I didn’t dig into it more as that fixed my issue.