马春杰杰 Exit Reader Mode

The ZFS modules are not loaded ZFS模块无法加载怎么办?

某一次升级了Linux内核之后,发现ZFS存储不能正常使用了。提示:The ZFS modules are not loaded. Try running ‘/sbin/modprobe zfs’ as root to load them.

与 FreeBSD 不同,ZFS 不能本机使用 Linux 内核。Linux 上的 ZFS 开发人员想出了一个相当糟糕的解决方案:通过 DKMSZFS 注入内核。但是这是有个前提的,就是假设你安装了ZFS之后,以后永远不会更新内核,或者重新启动系统(因为有时候系统重启之后会自动更新内核)。所以,一旦内核变了,很可能原本的ZFS就不能用了!难不难受!

目前是有两个步骤来拯救数据,首先删除DKMS模块,如果不起作用,就重新安装ZFS包。下面详细说明步骤:

第 1 步:清理并重新安装 DKMS 模块

大多数时候,Linux 上的 ZFS 在更新后会弄乱 DKMS 模块。我建议再次清理并重新安装 DKMS 模块。自 2018 年 12 月 12 日起,Linux 上的 ZFS 将无故删除所有 DKMS 模块。

首先,检查你的 DKMS 状态。如果 DKMS 为空(未安装任何内容)、孤立(已安装库,但未连接到任何内核)或多个内核(已安装多个内核),则需要清理 DKMS。如果它是干净的(仅是单个内核),你可以跳过此步骤。如果你在 Linux ver 0.7.x (0.6.x也一样)上使用 ZFS,则 DKMS 将包含两个模块(zfs 和 spl)。如果使用版本 0.8.x,则 DKMS 将仅包含一个模块 (zfs)。

使用命令:dkms status

下面举例见到的情形:

#An example of dirty DKMS status (This is bad):
spl, 0.7.12, 3.10.0-862.14.4.el7: installed (original_module exists) (WARNING! Diff between built and installed module!)
spl, 0.7.12, 3.10.0-957.1.3.el7: installed (original_module exists)
zfs, 0.7.12, 3.10.0-862.14.4.el7: installed (original_module exists) (WARNING! Diff between built and installed module!)
zfs, 0.7.12, 3.10.0-957.1.3.el7: installed (original_module exists)

#An example of empty DKMS status (This is bad):
(empty)

#An example of DKMS status without kernal (This is bad):
zfs, 0.7.12: added
spl, 0.7.12: added

#An example of clean DKMS status (This is good):
spl, 0.7.12, 3.10.0-957.1.3.el7.x86_64, x86_64: installed
zfs, 0.7.12, 3.10.0-957.1.3.el7.x86_64, x86_64: installed 

or 

spl, 0.7.12, 3.10.0-957.1.3.el7.x86_64, x86_64: installed (original_module exists)
zfs, 0.7.12, 3.10.0-957.1.3.el7.x86_64, x86_64: installed (original_module exists)

or 

zfs, 0.8.3, 3.10.0-1127.el7.x86_64, x86_64: installed (original_module exists)

在上面的例子中,我的Linux上的ZFS是0.7.12,我的旧内核是3.10.0-862.14.4.el7,我的新内核是3.10.0-957.1.3.el7。你的版本可能不同。

如果提示:

Error! Could not locate dkms.conf file.
File: /var/lib/dkms/zfs/0.8.2/source/dkms.conf does not exist.

这意味着你的系统中安装了多个版本的 dkms-ZFS 模块。在我的情况下,0.8.3 正在运行,旧的 (0.8.2) 仍然可用。检查文件夹(/var/lib/dkms/zfs/)以查看是否需要删除任何旧库。

#Currently running: dkms ZFS 0.8.3, kernel 3.10.0-1062.18.1.el7.x86_64

cd /var/lib/dkms/zfs/

#ls -al
total 12K
0.8.2 <---- Delete this
0.8.3
kernel-3.10.0-1062.1.2.el7.x86_64-x86_64 -> 0.8.2/3.10.0-1062.1.2.el7.x86_64/x86_64 <---- Delete this
kernel-3.10.0-1062.4.1.el7.x86_64-x86_64 -> 0.8.2/3.10.0-1062.4.1.el7.x86_64/x86_64 <---- Delete this
kernel-3.10.0-1062.4.3.el7.x86_64-x86_64 -> 0.8.2/3.10.0-1062.4.3.el7.x86_64/x86_64 <---- Delete this
kernel-3.10.0-1062.7.1.el7.x86_64-x86_64 -> 0.8.2/3.10.0-1062.7.1.el7.x86_64/x86_64 <---- Delete this
kernel-3.10.0-1062.9.1.el7.x86_64-x86_64 -> 0.8.3/3.10.0-1062.9.1.el7.x86_64/x86_64 <---- Delete this

你可能需要先删除 ZFS 和 SPL DKMS 模块,然后重新安装它们:

#If your version is 0.7.x:
sudo dkms remove zfs/0.7.12 --all; 
sudo dkms remove spl/0.7.12 --all; 


#If your version is 0.8.x:
sudo dkms remove zfs/0.8.3 --all;

有时,你需要手动删除旧内核:

sudo dkms remove zfs/0.7.12 -k 3.10.0-862.14.4.el7.x86_64; 
sudo dkms remove spl/0.7.12 -k 3.10.0-862.14.4.el7.x86_64;

然后,我们重新安装它们:

#Don't forget to use the version that matches your system. In my situation, it was 0.7.12 / 0.8.3

#0.7.x:
sudo dkms --force install spl/0.7.12; 
sudo dkms --force install zfs/0.7.12;

#0.8.x:
sudo dkms --force install zfs/0.8.3;

当然,还有可能你会提示:

ERROR (dkms apport): kernel package linux-headers-4.15.1-041501-lowlatency is not supported

这种情况就说明目前的内核不支持一些特性,所以我们需要降低内核版本,那么如何更换系统内核呢,请参考下面:

更换内核之后,再次运行 DKMS 状态。你应该会看到 ZPL 和 SPL 都附加到新内核:

#If your version is 0.7.x:
spl, 0.7.12, 3.10.0-957.1.3.el7.x86_64, x86_64: installed
zfs, 0.7.12, 3.10.0-957.1.3.el7.x86_64, x86_64: installed

#If your version is 0.8.x:
zfs, 0.8.3, 3.10.0-1127.el7.x86_64, x86_64: installed

尝试加载 ZFS 模块并导入 ZFS 数据:

sudo /sbin/modprobe zfs
sudo zpool import -a

如果一切看起来都不错,你可以重新启动系统和测试,以查看是否自动加载 ZFS。一旦一切正常,从系统中删除旧内核。

sudo package-cleanup --oldkernels --count=1 -y

就这样,一切是不是都很棒了~~

第 2 步:重新安装 ZFS 包

一般来说,第一步之后就可以解决问题了,如果你已经尝试第一步,它没有工作。你可能需要重新安装 ZFS 包。下面是一个典型的错误消息:

#zpool import -a
The ZFS modules are not loaded.
Try running '/sbin/modprobe zfs' as root to load them.

然后,按照提示加载ZFS模块的时候,系统再次提示:

#/sbin/modprobe zfs
modprobe: FATAL: Module zfs not found.
or
modprobe: ERROR: could not insert 'zfs': Invalid argument

这时,我们需要做的就是擦除所有ZFS包:

apt-get autoremove zfs zfs-dkms libzfs2 spl spl-dkms libzpool2 -y

然后重启电脑,之后重新尝试安装ZFS:

apt install zfs -y

安装后,尝试启动 ZFS 模块:

/sbin/modprobe zfs
zpool import -a

到现在应该完全没问题了。

不过如果你已经试了3次多,没有任何用处,不要浪费你的时间。你可能希望将 ZFS 磁盘带到其他服务器。新服务器应该能够识别 ZFS 磁盘。对于原始服务器,你可以使用原始路径通过 NFS 连接到新服务器上的 ZFS 磁盘。这将最大限度地减少变化的影响。

请记住,ZFS 版本非常重要。具有较新版本 ZFS 版本的服务器可以读取在较旧的 ZFS 版本中创建的 ZFS 磁盘。你始终可以通过运行以下操作来检查 ZFS 版本:

#Get the version of the host:
sudo zfs upgrade -v
sudo zpool upgrade -v


#Get the version of the ZFS disks:
sudo zfs get version
sudo zpool get version

 

本文最后更新于2020年12月19日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!