# No space left on /boot

**URL:** https://discourse.nixos.org/t/no-space-left-on-boot/24019
**Category:** Help
**Created:** [December 14, 2022, 10:17pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019 "2022-12-14T22:17:34Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![noblman](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/n/b487fb/32.png) [@noblman](https://discourse.nixos.org/u/noblman)
#### Post date: [December 14, 2022, 10:17pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/1 "2022-12-14T22:17:34Z")

</div>

Help!

```auto
building the system configuration...
ignoring default profile in the list of boot entries because of the following error:
[Errno 28] No space left on device: '/nix/store/s3pyaxds208immg12b07v2j7wpbgl768-initrd-linux-6.0.12/initrd' -> '/boot/efi/nixos/s3pyaxds208immg12b07v2j7wpbgl768-initrd-linux-6.0.12-initrd.efi'

```

df -h:

```auto
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.6G 0 1.6G 0% /dev
tmpfs 16G 400M 16G 3% /dev/shm
tmpfs 7.8G 8.2M 7.8G 1% /run
tmpfs 16G 432K 16G 1% /run/wrappers
/dev/mapper/enc 899G 673G 221G 76% /
/dev/mapper/enc 899G 673G 221G 76% /home
/dev/nvme0n1p1 511M 511M 0 100% /boot
tmpfs 3.2G 20K 3.2G 1% /run/user/1000

```

Tried `nix-collect-garbage -d`, but it didn’t help.

---

<div class="post-metadata">

### Author: ![uep](https://discourse.nixos.org/user_avatar/discourse.nixos.org/uep/32/5167_2.png) [@uep](https://discourse.nixos.org/u/uep)
#### Post date: [December 14, 2022, 10:23pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/2 "2022-12-14T22:23:34Z")

</div>

`nix-collect-garbage -d` will remove old generations and clean up the nix store

The boot entries for those kernels / generations don’t get updated until the next rebuild, when they all get put in place and a new grub menu (or whatever bootloader) is generated.

If you’re stuck at that step because it can’t start, you can just manually delete a few kernels and initrd’s

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixos.org/u/NobbZ)
#### Post date: [December 14, 2022, 10:27pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/3 "2022-12-14T22:27:10Z")

</div>

You need to remove some of the not needed anymore kernels and initrd images from the boot partition. One or 2 are usually enough.

Then rebuild and switch.

The activation script performs the following scripts in that order to remain consistent:

1, copy new kernel and image  
2. update menu  
3, delete kernels and images that are not in the new menu anymore

There is also an option that will make sure that the number of boot entries does not exceed a certain number, though I do not remember nor can I find it

---

<div class="post-metadata">

### Author: ![noblman](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/n/b487fb/32.png) [@noblman](https://discourse.nixos.org/u/noblman)
#### Post date: [December 14, 2022, 10:58pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/4 "2022-12-14T22:58:56Z")

</div>

> [@NobbZ](#):
>
> You need to remove some of the not needed anymore kernels and initrd images from the boot partition.

How do I do this? I’m using systemd boot. When I delete items from `/boot/EFI/nixos` and `/boot/loader/entries`, they are just recreated when I run `nixos-rebuild switch`.

---

<div class="post-metadata">

### Author: ![uep](https://discourse.nixos.org/user_avatar/discourse.nixos.org/uep/32/5167_2.png) [@uep](https://discourse.nixos.org/u/uep)
#### Post date: [December 14, 2022, 11:04pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/5 "2022-12-14T23:04:49Z")

</div>

The only ones that should be recreated are the ones for current generations, which should have been reduced by your garbage collect.

How many `system-*-link` entries do you have in `/nix/var/nix/profiles`?

Do you have something else taking up space in boot?

---

<div class="post-metadata">

### Author: ![noblman](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/n/b487fb/32.png) [@noblman](https://discourse.nixos.org/u/noblman)
#### Post date: [December 14, 2022, 11:11pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/6 "2022-12-14T23:11:29Z")

</div>

> [@uep](#):
>
> How many `system-*-link` entries do you have in `/nix/var/nix/profiles` ?

About 100 dating back to July. Shouldn’t they be getting deleted with garbage collect?

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 14, 2022, 11:13pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/7 "2022-12-14T23:13:29Z")

</div>

Only if your user has permission to delete them; i.e. you need to run `nix-collect-garbage -d` as root to cause those to be deleted.

---

<div class="post-metadata">

### Author: ![uep](https://discourse.nixos.org/user_avatar/discourse.nixos.org/uep/32/5167_2.png) [@uep](https://discourse.nixos.org/u/uep)
#### Post date: [December 14, 2022, 11:24pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/8 "2022-12-14T23:24:16Z")

</div>

Oof, yeah. Though a this point something less drastic than `-d` will be fine, say `--delete-older-than 10d`. Since these are gc roots, your store will also get a big clean after this.

Once you’re up and going again, I suggest adding something like this to your config, and never thinking about it again (because it will run with the right perms)

```nix
  nix.gc = {
    automatic = true;
    randomizedDelaySec = "14m";
    options = "--delete-older-than 10d";
  };

```

---

<div class="post-metadata">

### Author: ![noblman](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/n/b487fb/32.png) [@noblman](https://discourse.nixos.org/u/noblman)
#### Post date: [December 14, 2022, 11:25pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/9 "2022-12-14T23:25:52Z")

</div>

Crap. How stupid of me. Sorry to waste your time.

After doing a `sudo nix-collect-garbage --delete-older-than 30d`, `/boot` was still 100% full, but `sudo nixos-rebuild switch` was able to run and when finished, `/boot` was only 60% full. All good.

I have set `nix.gc.automatic = true;`, so obviously I don’t quite have it right. I remember thinking I would set this without options and see what it does. It looks like it needs options?

---

<div class="post-metadata">

### Author: ![uep](https://discourse.nixos.org/user_avatar/discourse.nixos.org/uep/32/5167_2.png) [@uep](https://discourse.nixos.org/u/uep)
#### Post date: [December 14, 2022, 11:28pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/10 "2022-12-14T23:28:05Z")

</div>

Right, without the options it’s just removing stray garbage (from ephemeral nix-shell invocations and the like), no gc roots.

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 14, 2022, 11:28pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/11 "2022-12-14T23:28:41Z")

</div>

Right, `nix.gc.automatic = true;` will only configure it to automatically run the GC, not to include a `--delete-older-than` option or anything. So paths in the store with no GC roots will get deleted, but all the existing GC roots will remain. So you want something like `nix.gc.options = ["--delete-older-than 30d"];` as well.

---

<div class="post-metadata">

### Author: ![uep](https://discourse.nixos.org/user_avatar/discourse.nixos.org/uep/32/5167_2.png) [@uep](https://discourse.nixos.org/u/uep)
#### Post date: [December 14, 2022, 11:30pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/12 "2022-12-14T23:30:05Z")

</div>

Honestly, this feels like a case of “there should be a better default”.

---

<div class="post-metadata">

### Author: ![noblman](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/n/b487fb/32.png) [@noblman](https://discourse.nixos.org/u/noblman)
#### Post date: [December 14, 2022, 11:30pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/13 "2022-12-14T23:30:06Z")

</div>

Awesome. You guys are so helpful. This really is a great community. I am going to make those changes to my `configuration.nix`.

---

<div class="post-metadata">

### Author: ![kwbauson](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kwbauson/32/2266_2.png) [@kwbauson](https://discourse.nixos.org/u/kwbauson)
#### Post date: [December 15, 2022, 2:23pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/14 "2022-12-15T14:23:23Z")

</div>

Another option if you’re using systemd-boot is you can set `boot.loader.systemd-boot.configurationLimit`. The number you set it to depends on your setup, e.g. I have it set to just 2 on my desktop because I’m dual-booting Windows which takes some space, and I’m loading gpu drivers into the initrd which makes my boot images bigger and fill up the partition.

---

<div class="post-metadata">

### Author: ![noblman](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/n/b487fb/32.png) [@noblman](https://discourse.nixos.org/u/noblman)
#### Post date: [December 15, 2022, 7:41pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/15 "2022-12-15T19:41:41Z")

</div>

That looks interesting. So, does it garbage collect as well, or just remove generations from the systemd boot list? I assume it removes kernels and initramfs from /boot, but without also doing a garbage collect, won’t those /boot items be recreated at next nixos-rebuild? The docs aren’t clear on this.

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 15, 2022, 7:49pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/16 "2022-12-15T19:49:16Z")

</div>

It will not garbage collect. It will make it so that `nixos-rebuild` will only allow there to be a maximum number of boot entries created in `/boot`. So the oldest generations are truncated and removed from `/boot` after the limit during `nixos-rebuild`.

---

<div class="post-metadata">

### Author: ![noblman](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/n/b487fb/32.png) [@noblman](https://discourse.nixos.org/u/noblman)
#### Post date: [December 15, 2022, 7:55pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/17 "2022-12-15T19:55:59Z")

</div>

So then the number of boot entries will be out-of-sync with the garbage collection? Why keep old store paths not refered to by any old generations?

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 15, 2022, 7:56pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/18 "2022-12-15T19:56:58Z")

</div>

The old generations still exist, they just aren’t in the boot menu. You can still switch to them from a running system.

---

<div class="post-metadata">

### Author: ![noblman](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/n/b487fb/32.png) [@noblman](https://discourse.nixos.org/u/noblman)
#### Post date: [December 15, 2022, 8:18pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/19 "2022-12-15T20:18:59Z")

</div>

Ahh… Wow. So much to learn. So, presumably, from the command line if you switch to an old generation that is no longer listed in the boot menu, the appropriate kernel and initramfs gets built on-the-fly?

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 15, 2022, 8:37pm UTC](https://discourse.nixos.org/t/no-space-left-on-boot/24019/20 "2022-12-15T20:37:18Z")

</div>

Here’s what happens when you do `nixos-rebuild`.

1. The NixOS system derivation is evaluated and built.
2. The `/nix/var/nix/profiles/system` profile is set to a new generation, pointing at that system derivation’s store path.
3. The system generation has a script called `switch-to-configuration` that gets run to actually do the switch. This has a few modes that are relevant to us; `switch`, `test`, and `boot`.
4. In the `switch` and `boot` modes, the boot loader is reconfigured. Up to a limit of `boot.configurationLimit`, other system generations as well as the new one have their kernels and initramfs copied to the `/boot` partition while obsolete generations or generations beyond the `configurationLimit` cutoff have theirs removed; by now these have already long-since-been built, residing in their `/nix/var/nix/profiles/system-*-link/` store path. The new generation is made the default boot entry.
5. In the `switch` and `test` modes, system services are reconfigured to match those of the new generation, and are stopped, started, and restarted to match. Note that the kernel and initramfs don’t come into play here. Those are only relevant when booting a generation.

The case where this isn’t _quite_ accurate is when switching to an entirely different generation. This can be done with `nixos-rebuild --rollback` or by manually issuing some of the steps above. In this case, the “new” generation is whatever you’ve picked. And even if it’s your oldest generation, it will be included on `/boot`.

[Next page](https://discourse.nixos.org/t/no-space-left-on-boot/24019.md?page=2)
