How to configure boot mounting device independent?


I want to move my boot partition into another device. If I understand correctly, you can do it with nixos-rebuild --install-bootloader boot, where you have to partition the new device and mount it into /boot before the command.

But you also have to change the hardware-configuration.nix with the new device id:

fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/<UUID>";
        fsType = "vfat";

Is it possible to configure it in a way that I could use both boot devices without a configuration change? I know it’s not that useful, it’s just in case if anything goes wrong with moving or losing the boot device.

All this does in practice is configure which filesystem gets mounted at /boot in the resulting configuration, mostly by writing the fstab file, and perhaps some service dependencies if relevant (like it’s mounted from a zpool or other device that needs extra setup steps).

It doesn’t actually matter for much other than where the next lot of bootloader configuration will be added in future updates. Notably, it doesn’t mean much of anything about which device you actually boot from.

So therefore it doesn’t really matter much if that mount fails (it happens long after booting, perhaps from somewhere else) until it comes time to do that next update. If it fails to mount, you just deal with it like any other failed mount: ignore the issue, mount something else in its place, fix the device, etc.

As an example, if you happen to be using grub, there are a set of options under boot.loader.grub.mirroredBoots.* that will write those updates into multiple locations (that you mount wherever you need), and you can boot from any of them via whatever bios options are available. Nothing is particularly special about the /boot path, other than as a default.

For just moving to another partition, you can make the new device, mount it at the right location, and build a new config with the new device name, just as you mention. Then reboot, choosing the new device. All the old configs will still be on the old boot partition, and if you boot one of those or roll back it will mount from the old location that was in that config generation.

If you want the old configs to all work (you want to roll back to something previous, for reasons other than the hardware change), you will need to make the new filesystem with the same UUID as the old, copy everything from the old to the new, and ensure only one is online at a time when booting so the by-uuid path is unambiguous. One way to do this is to then change the UUID of the original filesystem.

I see, mounting /boot is not even needed to actually boot the system. I can mount it afterwards in the case if an update is needed.


1 Like