I tried to install nixos to dual-boot with windows (pre-installed) on a new laptop. Since I’m fairly new to nixos (but with 10 years arch experience), I only allocated one partition for it, and there is a default 260M ESP created already which I cannot really change.
I formatted the new partition as btrfs, and installed nixos. I used grub as the bootloader. Everything works fine here.
But later I wanted to make grub remember the last chosen entry. I found this post, and configured my configuration.nix
accordingly. Doing nixos-rebuild
also works fine.
But then, whenever grub wants to boot into an entry, I see this error message from grub:
Error sparse file not allowed
The system does boot up, though. But grub won’t remember the entry.
After search this error, I found a discussion in manjaro forum, saying this is due to grub unable to save files on btrfs by default. The solution on manjaro is to reinstall grub with btrfs
and zstd
modules, using the following command:
sudo grub-install --recheck --no-rs-codes --modules="btrfs zstd part_gpt"
sudo update-grub
However, I feel this is not the way I should do it in nixos, as probably a configuration variable should be there for this purpose. But I cannot find it anywhere. Does anyone have suggestions?
Which partition is btrfs, the ESP? The ESP should always be some FAT variant like FAT32.
No. It’s the new partition, allocated for nixos’s root. I know ESP should be FAT, and, as said already, I did not change it, otherwise Windows boot would be broken.
As said, only this partition is new, so /boot
and /home
are also under it.
Why would grub need to write to anywhere outside of the ESP then? That should be where all of its configuration is stored.
EDIT: I would expect the ESP to be mounted at /boot
, so your response confuses me even more.
I’m not mounting ESP as /boot
, because it’s only 260MB. It’s mounted under /boot/efi
, so writing to ESP is still supported.
See also this post for an example configuration, which I followed.
To be fair, I’m not entirely sure if I should worry about the space. But I don’t see why this would be a problem or worth debating, as apparently nixos supports this and I can boot into the system.
I’m not debating anything, you just didn’t provide that information up-front, so we must of course ask for basic information.
What I did was expand the ESP to 500 MiB and mount ESP at /boot
.
If you want /boot
on a btrfs partition, you’d have to use boot.loader.grub.extraGrubInstallArgs
to pass the --modules
flag (though I don’t use grub and don’t know if that’s sufficient).
1 Like
Unfortunately, I cannot expand the ESP as it’s before the Windows partition, which is bitlock encrypted. I do have a last resort which is to create a separate partition for /boot
, but I’m refrained to do it as it’s quite an overkill just for Grub (as nixos won’t put kernels into /boot
, right?).
And thanks for the suggestion. It looked promising. But after trying it out, it did not solve the issue, at least not with the additional modules mentioned above.
Do you happen to know how to inspect what commands have been executed when doing nixos-rebuild switch
? I’d like to make sure the args are respected and correct sequence of commands have been executed.