Create zfs.service to Load Kernel Modules · Issue #6083 · openzfs/zfs

In the current implementation, the ZFS kernel drivers are loaded in the following two systemd unit files:

  • zfs-import-cache.service (won't run if /etc/zfs/zpool.cache doesn't exist)
  • zfs-import-scan.service (disabled by default)

Since an /etc/zfs/zpool.cache file doesn't exist after installation and the zfs-import-scan.service is disabled (by default), the kernel drivers are not loaded after reboot of a new install.

Recommend to add a new oneshot systemd unit called zfs.service specifically to load the kernel modules which is enabled by default and has no conditions. This unit can be RequiredBy=zfs.target and Before:zfs-import-cache.service, zfs-import-scan.service, etc.

It is a source of great confusion when people install ZFS, restart the computer and then it doesn't work (because the kernel drivers weren't loaded because zfs-import-scan.service is disabled and zfs-import-cache.service doesn't run because it is conditional on the existence of the /etc/zfs/zpool.cache file).

This is a chicken and egg situation where the zfs kernel modules are not loaded because there are no pools, but the user can't create a new pool because the zfs kernel modules are not loaded. Of course the user can manually load the kernel drivers, but for me this turned into a two day R&D session because there is no documentation on the ZoL site for how the systemd modules work.

The benefit of the existing approach is that if there are no ZFS pools the kernel modules won't be loaded, but the downside is that it is very confusing for new users (there are alot of "ZFS doesn't mount on reboot" questions on the internet which are related to this issue).

The benefit of the proposed approach is that on a fresh install with no modifications to the upstream source the zfs kernel modules will be loaded every time.

If a package manager deems this is not the desired behavior they can customize it when they build their package, but for everyone else this is probably the expected behavior.

Also, if somebody is installing something it is a fair assumption that they want it loaded and working so there isn't much sense in installing ZFS and then not loading the kernel drivers (unless it is part of a linux distribution package, but again, in that case the package maintainer should document for the user whatever customizations they made and how it should be used).