Boot partition is too small and becoming full

After running Windows for years I decided I wanted to try out NixOS. I don’t want to lose Windows so I created an extra partition and installed NixOS on it. But after trying it out for a few days I keep running into issues with the boot partition of 100 MB becoming full. After running only 2 or 3 generations the partition is usually close to or at 100%. In the latter case I can’t build a new generation. With only my latest generation its at 60%. That is after garbage collecting.

This is what my partition table looks like according to GParted.

How can I properly clean it up or increase the size of the boot partition? With my limited knowledge I found 2 solutions for increasing the boot partition:

  • Move the boot partition to a new bigger partition. I’ve never done this, but with a clear guide I’m sure I’ll be able to do it.
  • Reinstall Windows and NixOS. A bit drastic maybe, but I don’t mind starting fresh. To me my current table partition looks like a mess and with NixOS in mind I can setup the partitions correctly from the start. In that case is there someone who can give a recommended partition table setup and some high level steps?
1 Like

The reason you are running into a full boot partition is, because you are accumulating multiple kernels from various older generations, which require them.

To save space you could reduce the number of generations you keep, and enable automatic garbage collection.

https://search.nixos.org/options?channel=23.05&from=0&size=50&sort=relevance&type=packages&query=configurationLimit

https://search.nixos.org/options?channel=23.05&from=0&size=50&sort=relevance&type=packages&query=nix.gc

1 Like

I will enable these options, but as I mentioned, even with 1 generation it’s already at 60% and that is after garbage collecting. So there should be only 1 kernel. And only having 2 or 3 generations during an evening of tinkering, is not much right?

In most cases multiple generations on the same evening will share the same kernel. Kernel updates happen roughly weekly.

You could try creating another EFI partition specifically for NixOS.

It’s also possible to use GRUB, which takes less than 1M of space on EFI partition and can read kernel files from the root filesystem. Replace your systemd-boot options with something like this:

boot.loader.grub.enable = true;
boot.loader.grub.efiSupport = true;
boot.loader.grub.device = "nodev";
boot.loader.efi.canTouchEfiVariables = true;
boot.loader.efi.efiSysMountPoint = "/boot/efi";

Don’t forget to remount and change your EFI mount point from “/boot” to “/boot/efi” in hardware-configuration.nix

1 Like

I haven’t run into this issue since my boot partition is large enough but I thought about that…

In case my boot is full but my root has still plenty of space, will nixos-rebuild fail (assuming that there is a kernel update)? Is then the recommendation to look into /boot/kernels and remove generations that use old *initrd (in case I want to remove the minimal number or generations that needs to be removed).

(I can’t store kernels on root since root is LUKSed)

Thank you.

1 Like

if /boot is completely full, rebuild will at the end fail once it tries to add the generation to the boot entries, if theres no new kernel and the the inputs for the kernel havent changed u can have multiple generations in very little space, if the kernel changes a new generation takes a lot more space, old boot entries/kernels are automatically deleted on rebuild, after you deleted the generations

1 Like

Using GRUB sounds like a nice solution. I wanted to experiment with it anyway. A few question though:

  • Which setting causes GRUB to read kernel files from the root filesystem? Or is this default GRUB behavior?
    Edit: from what I understand kernels are read from /boot, which is part of the main partition if the actual boot partition is mounted to /boot/efi?
  • Will garbage collection clean up kernel files from the boot partition? And clean up the old ones in root?
  • Would this be the right order and the right commands to remount the boot partition?
    1. Update configuration
    2. umount /boot
    3. mkdir -p /boot/efi
    4. mount /dev/nvme0n1p2 -o auto /boot/efi
  • I notice I already have /boot/EFI. Not sure if that is an issue?
  • In hardware-configuration.nix I just have to change the /boot path to /boot/efi?
  • After this just a nixos-rebuild switch to apply the changes, and reboot to confirm?

On BIOS systems:

You can have a single partition (root) and /boot is just a directory. Or you can have more partitions and one of them is mounted to /boot - that is requirement if your main partition is LUKS encrypted.

UEFI firmware systems:

You need to have EFI partition (FAT):

  • You can have root partition, and EFI mounted to /boot
  • You can have root partition, boot mounted to /boot and EFI mounted to /boot/efi

Edit: from what I understand kernels are read from /boot , which is part of the main partition if the actual boot partition is mounted to /boot/efi ?

Yes

Will garbage collection clean up kernel files from the boot partition? And clean up the old ones in root?

With grub the esp should not contain kernels

Would this be the right order and the right commands to remount the boot partition?

Yes, but you’ll also have to clean up the esp before installing grub, e.g. rm -rf /boot/efi/*

I notice I already have /boot/EFI. Not sure if that is an issue?

See above

In hardware-configuration.nix I just have to change the /boot path to /boot/efi?

Yes

After this just a nixos-rebuild switch to apply the changes, and reboot to confirm?

Use sudo nixos-rebuild switch --install-bootloader to install new boot loader

Thanks! Grub is installed successfully. However the Windows 11 option is not available. I tried the boot.loader.grub.useOSProber = true; but without success. Would it require a manual GRUB entry like it’s suggested on the wiki under EFI > Grub?

If I change this would it require another rm -rf /boot/efi/* and sudo nixos-rebuild switch --install-bootloader?

I’ve backed-up my original /boot directory just in case.

I don’t use windows but I think it should work

sudo nixos-rebuild switch should be enough

Ah, yes, if you are dual booting windows its bootloader should be on esp too. Try restoring /EFI/Microsoft, useOSProber would likely work then

Thanks, that did the trick :slight_smile: