zfs module not loaded on CentOS 7

Created on 2 Apr 2017  路  9Comments  路  Source: openzfs/zfs

zfs-import-scan.service should "modprobe zfs" but it does not.

[root@testserver123 ~]# grep modprobe  /lib/systemd/system/zfs*
/lib/systemd/system/zfs-import-cache.service:ExecStartPre=/sbin/modprobe zfs
/lib/systemd/system/zfs-import-scan.service:ExecStartPre=/sbin/modprobe zfs
[root@testserver123 ~]# 
[root@testserver123 ~]# systemctl list-unit-files | grep zfs
zfs-import-cache.service                      disabled
zfs-import-scan.service                       enabled 
zfs-mount.service                             enabled 
zfs-share.service                             disabled
zfs-zed.service                               disabled
zfs.target                                    disabled
[root@testserver123 ~]# 

After manually running "modprobe zfs" if works.

[root@testserver123 ~]# dmesg | grep -i zfs
[   11.282952] ZFS: Loaded module v0.6.5.9-1, ZFS pool version 5000, ZFS filesystem version 5
[root@testserver123 ~]# modinfo zfs | grep -iw version
version:        0.6.5.9-1
[root@testserver123 ~]# modinfo spl | grep -iw version 
version:        0.6.5.9-1

I am using it with zfs-kmod.

See also: https://github.com/zfsonlinux/zfs/issues/5191

I am using this workaround:

1) First I disable mongod:

# systemctl disable mongod.service

2) Make empty directory for the database (/var/lib/mongo) because it will not mount the zfs otherwise. Permissions/owner/group should be correct.

3) Add to /etc/rc.local:

/sbin/modprobe zfs
/usr/sbin/zpool import -d /var/zfs-images/ zfs_tank

if mount | grep -q "zfs_tank/mongo on /var/lib/mongo"; then
  systemctl start mongod.service
  echo "running mongod.service...."
else
  echo "Error: /var/lib/mongo is not mounted!"
fi

With this workaround it works.

The same should be done for all services that should be started after importing and mounting ZFS.

ZFS will refuse to mount filesystems if mount paths are not empty directories.

Note: The above script is specific to my system (it searches for the string "zfs_tank/mongo on /var/lib/mongo" in order to determine if it is safe to run mongod; also it is importing zfs from files in specific directory: /var/zfs-images/).

Most helpful comment

I consider this a bug too...

I had to manually run systemctl enable zfs.target after initial installation on CentOS 7.5. The docs do not mention this.

All 9 comments

Enabling zfs.target does not help:

#  systemctl enable zfs.target
[root@testserver123 ~]# zpool status
The ZFS modules are not loaded.
Try running '/sbin/modprobe zfs' as root to load them.
[root@testserver123 ~]# 

I expect zfs modules to be loaded on boot. But they are not.

I consider this a bug.

@vstoykovbg to always load the modules on boot remove the comment from the /etc/modules-load.d/zfs.conf config file.

It looks like the problem was that I did not enabled zfs.target.

# systemctl enable zfs.target
# systemctl enable zfs-import-scan.service

After reboot:

# systemctl list-unit-files | grep zfs | grep enabled
zfs-import-scan.service                       enabled 
zfs.target                                    enabled 
# lsmod | grep zfs
zfs                  2709477  0 
zunicode              331170  1 zfs
zavl                   15236  1 zfs
zcommon                55411  1 zfs
znvpair                93227  2 zfs,zcommon
spl                    92225  3 zfs,zcommon,znvpair
# 

Like expected, it works.

There is no file /etc/modules-load.d/zfs.conf and no need to add the module there, because it is loaded by zfs-import-scan.service (ExecStartPre=/sbin/modprobe zfs) if enabled:

# cat /usr/lib/systemd/system/zfs-import-scan.service
[Unit]
Description=Import ZFS pools by device scanning
DefaultDependencies=no
Requires=systemd-udev-settle.service
After=systemd-udev-settle.service
After=cryptsetup.target
ConditionPathExists=!/etc/zfs/zpool.cache

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/sbin/modprobe zfs
ExecStart=/sbin/zpool import -aN -o cachefile=none

[Install]
WantedBy=zfs-mount.service
WantedBy=zfs.target

It does not work with above configuration if the file /etc/zfs/zpool.cache exists, because of:

ConditionPathExists=!/etc/zfs/zpool.cache

(The ! symbol means that the unit is started if the file does not exist.)

Solution:

rm /etc/zfs/zpool.cache

I consider this a bug too...

I had to manually run systemctl enable zfs.target after initial installation on CentOS 7.5. The docs do not mention this.

This seems to be missing from newer versions of ZFS, from a 0.7.12 system:

[root@photosCent ~]# cat /usr/lib/systemd/system/zfs-import-scan.service
[Unit]
Description=Import ZFS pools by device scanning
DefaultDependencies=no
Requires=systemd-udev-settle.service
After=systemd-udev-settle.service
After=cryptsetup.target
Before=dracut-mount.service
Before=zfs-import.target
ConditionPathExists=!/etc/zfs/zpool.cache

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=-/sbin/modprobe zfs
ExecStart=/sbin/zpool import -aN -o cachefile=none

[Install]
WantedBy=zfs-import.target

On a 0.8.2 system:

[root@wp-km system]# cat /usr/lib/systemd/system/zfs-import-scan.service
[Unit]
Description=Import ZFS pools by device scanning
Documentation=man:zpool(8)
DefaultDependencies=no
Requires=systemd-udev-settle.service
After=systemd-udev-settle.service
After=cryptsetup.target
Before=zfs-import.target
ConditionPathExists=!/etc/zfs/zpool.cache

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/zpool import -aN -o cachefile=none

[Install]
WantedBy=zfs-import.target

None of the systemd units seem to be loading the modules on boot. Does this mean nothing is loading the modules automatically during boot?

If so, this needs to be either changed to be similar to what 0.7.x did or updated in the documentation.

A simple workaround for this is editing the zfs-mount unit:

systemctl edit zfs-mount

And adding:

[Service]
ExectStart=/sbin/modprobe zfs

Then:

systemctl daemon-reload

None of the systemd units seem to be loading the modules on boot. Does this mean _nothing_ is loading the modules automatically during boot?

Just installed zfs 0.8.3 and found the following:

  • zfs module gets loaded automatically when there is a pool in the system
  • with no pool available, the zfs related services fail, and the zfs module isn't loaded

Just installed zfs 0.8.4 on CentOS 7.8 and, even with a pool created, the module was not loaded at boot.

Was this page helpful?
0 / 5 - 0 ratings