Bug 271384 - zfs_load is not suitably documented
Summary: zfs_load is not suitably documented
Status: Open
Alias: None
Product: Documentation
Classification: Unclassified
Component: Books & Articles (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-doc (Nobody)
URL:
Keywords: needs-patch
Depends on:
Blocks: 261212
  Show dependency treegraph
 
Reported: 2023-05-13 02:53 UTC by phryk-ports
Modified: 2023-05-13 18:32 UTC (History)
7 users (show)

See Also:
grahamperrin: maintainer-feedback? (fs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description phryk-ports 2023-05-13 02:53:47 UTC
Without `zfs_load="YES"` and `zpool_cache_*` (presumably both, but haven't
tested in isolation) in `loader.conf`, zpools don't get imported during
init – even if `/etc/rc.conf` contains `zfs_enable="YES"`.

This means that on setups with zfs-independent boot, at least automatic
mounting doesn't work – but probably also that mounting zfs datasets
via fstab becomes impossible.

There is an `/etc/rc.d/zpool` that does the import, but it only seems to be
invoked by `/etc/rc.d/zfskeys` which seems to be for a completely different
use-case. I fixed this on my system by adding this to `/etc/rc.d/zfs`:

```
start_precmd="zfs_prestart"

zfs_prestart(){
    if checkyesno zpool_enable; then
        /etc/rc.d/zpool start
    fi
}
```

And then `zpool_enable="YES"` to my rc.conf.

There might be a more elegant way of checking whether the `zpool start`
should be invoked than introducing a new variable to `rc.conf` and there
probably should also be a poststop command to do `zpool stop` but I'm
migrating away from zfs, it's already over 10 hours after I wanted to be
done with the initial migration and I'm definitely not pouring more time
into this – just wanted to hand this over on my way out the door.
Comment 1 Graham Perrin freebsd_committer freebsd_triage 2023-05-13 04:44:33 UTC
zfs_load is mentioned obscurely under <https://docs.freebsd.org/en/articles/remote-install/#_post_installation_steps> in 'Remote Installation of the FreeBSD Operating System Without a Remote Console', however: 

* it's nowhere in the FreeBSD Handbook.

We should document that zfs_load: 

* is automatically enabled (set to "YES") if ZFS is chosen when installing FreeBSD

* can be manually enabled for atypical use cases, such as the one described in 
  comment 0

* must be "NO" when using the port of OpenZFS, i.e. sysutils/openzfs-kmod.


Also – maybe a question for fs@ – should zfs_load be mentioned in loader.conf(5)?


----

<https://github.com/freebsd/freebsd-src/commit/6e15678a470671d454dba52e195c4167b8d63c06#diff-566a1b9d6ad5ce6df61a53416b8d7c690b67d0a53c667a1000a45042131f6e95R39>

<https://man.freebsd.org/cgi/man.cgi?query=loader.conf&sektion=5&manpath=freebsd-release>

<https://www.freshports.org/sysutils/openzfs-kmod/#message>
Comment 2 Warner Losh freebsd_committer freebsd_triage 2023-05-13 04:50:33 UTC
in loader.conf foo_load=ANYTHING -> load foo.ko (or more pedantically, load the foo module which by convention is foo.ko)

from loader.conf(5):

     *_load        If set to “YES”, that module will be loaded.  If no name is
                   defined (see below), the module's name is taken to be the
                   same as the prefix.

So, yes, it is documented.
Comment 3 Mina Galić freebsd_triage 2023-05-13 07:34:59 UTC
why is zpool started / why are zpools imported with just `zfs_load="YES"` in loader.conf?
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2023-05-13 13:29:42 UTC
(In reply to phryk-ports from comment #0)

> … `/etc/rc.d/zpool` 

> And then `zpool_enable="YES"` to my rc.conf. …


Note, 

% grep rcvar /etc/rc.d/zpool
rcvar="zfs_enable"
%
Comment 5 Graham Perrin freebsd_committer freebsd_triage 2023-05-13 14:10:48 UTC
(In reply to Mina Galić from comment #3)

It might help to think about behaviours when booting in single user mode. 

For a typical FreeBSD on ZFS, you'll find just one ZFS mount 
    / 
according to the bootfs property of the pool; and (if I recall correctly)
no other pool imported.
Comment 6 Kyle Evans freebsd_committer freebsd_triage 2023-05-13 14:13:37 UTC
IIRC with Solaris ZFS we had to preload the cachefile in loader, but ZoL had changed it to autoload the cachefile at module startup and import any other pools in the root pool's cachefile.
Comment 7 Graham Perrin freebsd_committer freebsd_triage 2023-05-13 16:53:20 UTC
(In reply to Graham Perrin from comment #5)

> … single user mode 

> … (if I recall correctly) no other pool imported.

True. 

An extract from /var/log/console.log – automated import of the pool named Transcend (in use before the restart of the system) did not occur until the exit to multi-user mode: 


…
Enter full pathname of shell or RETURN for /bin/sh: # zpool list
NAME     SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
august   912G   720G   192G        -         -    65%    78%  1.00x    ONLINE  -
# exit
Fast boot: skipping disk checks.
Key file /usr/home/grahamperrin/Documents/personal/VirtualBox.key not found, empty or unreadable. Skipping Transcend/VirtualBox..
Loading key for Transcend/VirtualBox from file:///usr/home/grahamperrin/Documents/personal/VirtualBox.key..
Loading kernel modules:
…


<https://openzfs.github.io/openzfs-docs/man/7/zpoolprops.7.html#cachefile>

<https://openzfs.github.io/openzfs-docs/Project%20and%20Community/FAQ.html#the-etc-zfs-zpool-cache-file>

<https://docs.freebsd.org/en/books/handbook/basics/#consoles-singleuser> might be improved, to mention that the cachefile is not used in single user mode (or words to that effect).