nixos/zfs: improve forceImportRoot docs #590151
I don't think we should have any text recommending using this
Thanks for following up!
I didn't understand you'd include the full comment, and I think this is a bit long and buries the lede.
Here's what I had come up with in parallel:
Forcibly import the ZFS root pool(s) during early boot (zpool import -f).
> It is highly recommended to keep this option disabled as it bypasses ZFS safeguards.
> Instead of enabling this option, if NixOS fails to boot because a pool was "previously in use
from another system", you can boot once with the zfs_force=1 kernel parameter
(e.g. added interactively in your bootloader menu).
You should only need to usezfs_force=1if the pool was last imported by a different host (see {option}networking.hostId).
This can happen after using the pool from a different host (e.g. a live ISO) and forgetting to export it (see {manpage}zfs-export(1)).
---
I think improving the docs is good. Additionally, I'm in favor of fully removing this in the next NixOS cycle as I can't come up with any use case for having this enabled all the time.
The only close to be use-case is sharing a pool, which you'd better be served by always exporting on shutdown, to keep this safety mechanism functional.
@ThinkChaos I am definitely not in favour of removing this option, because while learning more about this, I concluded that I actually want to have this option on at all times on my servers.
The situation ZFS protect against here is extremely unlikely, especially on servers, and the situation that will be broken by it is very likley (every time some NixOS upgrade messes up and breaks booting, I have to shut down the AWS machine, attach the disk volume to another running disk, mount it, fix its contents, and reattach to the original machine), so I figured there will actually be a group of users for which this option being true is the most sensible setup.
That situation you're mentioning should happen rarely, and if it does running zfs export is easy. Then reboot without -f will just work<sup>TM</sup>.
To make that even less of an issue, I think the live ISO should auto zpool export -a as was discussed previously.
Agreeing on how to use -f doesn't matter for this specific change, you do you, but I do think it matters we don't recommend anything potentially unsafe. IMO, if a user wants to make that decision they should understand the ins and outs, and not do it because the docs said so.
We should not give a recommendation contrary to upstream, as the default is not -f upstream, and afaik neither upstream’s docs nor any other distro’s docs recommend it as the default. If it should be recommended in some cases, IMO that should go in upstream’s docs or perhaps the wiki.
This makes the option docs far too verbose. Almost no one should really be enabling this option, instead they should be (as already in the doc) using zfs_force=1 to temporarily enable it on an as-needed basis.
And really we should fix (at least) the installer to export the pool on shutdown to avoid the most common innocuous case.
---
The main issue with the existing doc is that “You should only need to do this after unclean shutdowns.” is incorrect, and we should just fix that, and ThinkChaos’s comment does that and clarifies the situation that causes this. Perhaps a reference that it is the equivalent of zpool import -f and to see man zpool-import would be helpful to defer to upstream’s docs a bit.
This makes the option docs far too verbose.
The point is to describe what the NixOS option does. It took me half an hour to really figure out what it does and what ZFS's idea is here; I shouldn't have to, and writing a couple sentences will save many other people this time. The wiki is not the place to document NixOS options; it inevitably gets out of date, which is why option descriptions are better.
Saying "it passes -f" is clearly not enough, as the zpool-import man page only describes what it does, not in which situation one would need it.
If there's a clear upstream explanation that explains the same thing, we can refer to that instead (please post a link).
Almost no one should really be enabling this option, instead they should be (as already in the doc) using zfs_force=1 to temporarily enable it on an as-needed basis.
There are people with swathes of servers for whom the declarative point of NixOS is that they do not need to press buttons on as-needed basis. Other file systems don't require you to do this extra dance on shutdown, so it makes sense that NixOS allows to declare it away.
---
Anyway, I have removed the block about in which situations one might want to use this (even though I think people would be abel to make better decisions with it).
I removed this part.
How about something like this. I think there's still a bit too much narration.
Forcibly import the ZFS root pool(s) during early boot.
ZFS pools are tied to a single hostid. This means that moving
ZFS pools between systems or hostid without first running `zfs export`
will require manual intervention in order for import to succeed.
This NixOS-only option overrides that default ZFS behavior by forcibly
importing any ZFS root pools on every boot.
Preferably, setting {option}`networking.hostId` instead of enabling
this option will provide a NixOS managed persistent hostid.
Recovery from boot failures when this is disabled can be achieved by
adding `zfs_force=1` to kernel parameters in your bootloader for a single boot.
I feel it's premature to discuss removing this, and would probably not support doing so even though I wouldn't use it. We haven't even shipped the default change in a stable release yet.
I opened https://github.com/NixOS/nixpkgs/pull/590221 to add an option to export on shutdown and enable it in the installer by default. I think this should resolve the main use case for force import (forgetting to zpool export after a new installation) and give opt-in to always export, which is better than forced import. It doesn’t obviate the need for force import entirely, but probably by default it does.
(I also did minimal reword of these docs there…but see comment on that PR)
This NixOS-only option
@adamcstephens what's a non-NixOS-only option? We're in a NixOS option description here.
I think there's still a bit too much narration.
I think it should definitely say
ZFS has a feature to protect users from accidentally mounting the same file system
on multiple machines simultaneously (which leads to pool corruption).
This can usually only happen through
* hibernation, and then booting another OS that wants to use the same file system
* shared VM images or shared network-attached drives
as that was the main point from https://github.com/NixOS/nixpkgs/pull/495581#pullrequestreview-5963341796. The first thing any user will think when reading "ZFS pools are tied to a single hostid" is "... OK, why? My other FS don't need this." We should make clear that this is some ZFS extra protection against a specific type of mistake, and when that mistake can happen.
Rest looks also OK to me.
@adamcstephens what's a non-NixOS-only option? We're in a NixOS option description here.
I'm well aware. My point here was to call out this is a behavior that diverges from upstream and every other distro. I don't feel strongly about this.
I think it should definitely say
I don't think we should explain and try to enumerate the upstream why behind this. Options don't need to explain all of upstream's reasoning behind their decisions. How about skipping this entire why and linking this instead. https://openzfs.github.io/openzfs-docs/Basic%20Concepts/Operations/Boot%20Process.html
"... OK, why? My other FS don't need this."
ZFS isn't another FS and I don't agree it's the job of a NixOS option description to describe why and in what scenarios upstream was designing for. It's not necessary to explain to users why nginx and traefik configs are different and the same should hold for ZFS and ext4.
We don't have official documentation for how to set up a root filesystem with ZFS so I think it's fair to put responsibility on users for learning and understanding of ZFS behaviors outside of the option description. The two locations I found (upstream and our wiki) both document using networking.hostId which avoids users even looking at this option (and is required by this assertion).
@adamcstephens The https://openzfs.github.io/openzfs-docs/Basic%20Concepts/Operations/Boot%20Process.html#hostid-and-importing-on-the-wrong-machine section looks good, I pushed a shorter version that links to it.
@amarshall @adamcstephens @ThinkChaos Please take another look at my admendments
I would vouche against keeping this option disabled with the current form of things.
No one I know does zpool export by hand after debugging a boot failure or something else in a live ISO and afterwards the machine silently no longer boots. Nothing in console hints at this and after debugging for an hour and getting helpful hints like install Debian, eventually someone thinks about this.
If this should be kept, then we should definitely prominently document to always do ZFS export in an ISO and definitely add a shutdown unit that does that automatically, because why would you want to do an unlcean shutdown?
Also why is this import failure silent in the console? Can't we print an informative message when the pool failed to import because of that?
This conflicts with the security recommendation to disable editing boot parameters 😅
This is also my opinion (see https://github.com/NixOS/nixpkgs/pull/590151#discussion_r4622876067).
@amarshall @adamcstephens @ThinkChaos Would you be OK with
-Thus it is recommended to keep this option disabled, keeping the protection.
+This option is controversial, see https://github.com/NixOS/nixpkgs/pull/590151?
?
My main interest in this PR is to fix current wording which is just misleading.
@SuperSandro2000 Which ones, can you link?
Also sounds a bit dubious to me whether such a disabling would really be effective vs people with physical access to a computer.
definitely prominently document to always do ZFS export in an ISO
Export is documented in every install guide I reviewed recently. There is no official NixOS documentation on setting up zfs root so nothing to update.
Regarding auto export, amarshall already has a PR for that.
No, I don’t think it’s appropriate to call this controversial. I’m sorry if Sandro doesn’t like the way zfs works but I think following upstream and other distros is appropriate here.
If someone has locked their bootloader they hopefully know how to unlock it to change these. It’s not a default configuration either.
ThinkChaos
nh2
Fixes:
FYI @ThinkChaos
Things done
<!--
Please check what applies. Note that these are not hard requirements but merely serve as information for reviewers.
Entries that cannot apply to your change may be left unchecked or removed if your summary reads better without them, for example NixOS tests when the change does not touch NixOS.
You are welcome and encouraged to add new entries if they are relevant to your change, e.g. stdenv or specific subsystems testing instructions.
Please keep the section headings and do not remove the template as a whole, even when nothing is checked.
-->
- [x] x86_64-linux
- [ ] aarch64-linux
- [ ] aarch64-darwin
- [ ] Basic functionality of all binary files, usually in
./result/bin/.- [ ] Ran
nixpkgs-reviewon this PR. See [nixpkgs-review usage].- [ ] [Package tests] at
passthru.tests.- [ ] [NixOS tests] in [nixos/tests].
- [ ] Tests in [lib/tests] or [pkgs/test] for functions and "core" functionality.
- [ ] Package update: when the change is major or breaking.
- [ ] Module addition: when adding a new NixOS module.
- [ ] Module update: when the change is significant.