在 debian 9stretch 上安装 zfs

在 debian 9stretch 上安装 zfs

我尝试在 debian 9.1 上安装 zfs,但是遇到一些错误。

我的第一次安装只是 zfs-dkms,但是我在网上读到 zfs-dkms 的运行也需要 spl-dkms。


我的步骤是改变我的来源.list添加非免费贡献如下:

/etc/apt/sources.list

deb http://ftp.nl.debian.org/debian/ stretch main contrib non-free
deb-src http://ftp.nl.debian.org/debian/ stretch main contrib non-free

deb http://security.debian.org/debian-security stretch/updates main contrib non-free
deb-src http://security.debian.org/debian-security stretch/updates main contrib non-free

# stretch-updates, previously known as 'volatile'
deb http://ftp.nl.debian.org/debian/ stretch-updates main contrib non-free
deb-src http://ftp.nl.debian.org/debian/ stretch-updates main contrib non-free

完成经典的 apt-get 更新,然后尝试使用以下命令安装 zfs:

apt-get install spl-dkms

并且只有在之后

apt-get install zfs-dkms

结果,我有这些错误:

root@debian:/etc/apt# apt-get install zfs-dkms
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libnvpair1linux libuutil1linux libzfs2linux libzpool2linux zfs-zed zfsutils-linux

...

DKMS: install completed.
Setting up libzpool2linux (0.6.5.9-5) ...
Setting up libzfs2linux (0.6.5.9-5) ...
Setting up zfsutils-linux (0.6.5.9-5) ...
Created symlink /etc/systemd/system/zfs-mount.service.wants/zfs-import-cache.service â /lib/systemd/system/zfs-import-cac
Created symlink /etc/systemd/system/zfs.target.wants/zfs-import-cache.service â /lib/systemd/system/zfs-import-cache.serv
Created symlink /etc/systemd/system/zfs-share.service.wants/zfs-mount.service â /lib/systemd/system/zfs-mount.service.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-mount.service â /lib/systemd/system/zfs-mount.service.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-share.service â /lib/systemd/system/zfs-share.service.
Created symlink /etc/systemd/system/multi-user.target.wants/zfs.target â /lib/systemd/system/zfs.target.
zfs-import-scan.service is a disabled or a static unit, not starting it.
Job for zfs-mount.service failed because the control process exited with error code.
See "systemctl status zfs-mount.service" and "journalctl -xe" for details.
zfs-mount.service couldn't start.
Job for zfs-share.service failed because the control process exited with error code.
See "systemctl status zfs-share.service" and "journalctl -xe" for details.
zfs-share.service couldn't start.
Setting up zfs-zed (0.6.5.9-5) ...
Created symlink /etc/systemd/system/zed.service â /lib/systemd/system/zfs-zed.service.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-zed.service â /lib/systemd/system/zfs-zed.service.
Processing triggers for libc-bin (2.24-11+deb9u1) ...

阅读日志控制-xe按照建议我得到:

root@debian:/etc/apt# journalctl -xe
Aug 02 23:13:13 debian systemd[1]: zfs-share.service: Main process exited, code=exited, status=1/FAILURE
Aug 02 23:13:13 debian systemd[1]: Failed to start ZFS file system shares.
-- Subject: Unit zfs-share.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit zfs-share.service has failed.
--
-- The result is failed.
Aug 02 23:13:13 debian systemd[1]: zfs-share.service: Unit entered failed state.
Aug 02 23:13:13 debian systemd[1]: zfs-share.service: Failed with result 'exit-code'.
Aug 02 23:13:13 debian systemd[1]: Starting Mount ZFS filesystems...
-- Subject: Unit zfs-mount.service has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit zfs-mount.service has begun starting up.
Aug 02 23:13:13 debian zfs[81481]: The ZFS modules are not loaded.
Aug 02 23:13:13 debian zfs[81481]: Try running '/sbin/modprobe zfs' as root to load them.
Aug 02 23:13:13 debian systemd[1]: zfs-mount.service: Main process exited, code=exited, status=1/FAILURE
Aug 02 23:13:13 debian systemd[1]: Failed to start Mount ZFS filesystems.
-- Subject: Unit zfs-mount.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit zfs-mount.service has failed.
--
-- The result is failed.
Aug 02 23:13:13 debian systemd[1]: zfs-mount.service: Unit entered failed state.
Aug 02 23:13:13 debian systemd[1]: zfs-mount.service: Failed with result 'exit-code'.
Aug 02 23:13:13 debian systemd[1]: Starting ZFS file system shares...
-- Subject: Unit zfs-share.service has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit zfs-share.service has begun starting up.
Aug 02 23:13:13 debian systemd[81483]: zfs-share.service: Failed at step EXEC spawning /usr/bin/rm: No such file or direc
-- Subject: Process /usr/bin/rm could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The process /usr/bin/rm could not be executed and failed.
--
-- The error number returned by this process is 2.

这是怎么回事?我还错过了什么吗?怎么样zfs-linux与zfs安装相关的包?

在 debian 9 中安装 zfs 的正确方法是什么?

答案1

@cas 的实际答案很好,但需要进行一些更正。

因此,让我们全新安装 Debian 9 并假设非免费贡献存储库也未启用。


第 0 步 - 启用 contrib 非自由存储库

我曾经sed查找并替换这个词主要的里面/etc/apt/sources.list

sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list

apt-get update

第 1 步 - ZFS 安装

由于最后的修复spl-dkms被正确地视为zfs-dkms依赖项,因此它会自动调用,并且无需在之前手动安装它zfs-dkms。由于 Debian 中的 zfs 发行版内部存在错误,因此需要符号链接,该错误不会rm在正确的位置查找二进制文件。

apt -y install linux-headers-$(uname -r)

ln -s /bin/rm /usr/bin/rm

apt-get -y install zfs-dkms

第 2 步 - ZFS 重新启动

此时 zfs-dkms 已安装,但会抛出错误journalctl -xe;要正确启动 zfs,请使用:

/sbin/modprobe zfs

systemctl restart zfs-import-cache
systemctl restart zfs-import-scan
systemctl restart zfs-mount
systemctl restart zfs-share

第 3 步 - 您必须创建至少一个 ZPOOL

此时我发现您必须在重新启动之前创建一个 zpool否则,如果没有 zpool,zfs 将无法加载正确的模块。这是一种节省资源的机制(但即使在这种情况下,这仍然会在内部抛出错误journalctl -xe

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864348

“我们不这样做是因为 ZFS 模块会污染内核,如果没有可用的 zpool,则不应加载它。”

如果你错过了这部分,你必须从第2步

例如,通过使用 @cas 提供的示例,您可以创建基于此文件的 zpool 或直接创建基于磁盘的 zpool。

truncate -s 100M /root/z1
truncate -s 100M /root/z2
zpool create tank /root/z1 /root/z2
zpool scrub tank
zpool status

然后reboot一切都会正常工作,没有错误journalctl -xe

答案2

在添加 Apt 源之后,Debian 9.4 对我来说略有不同:

apt-get install linux-headers-amd64       # not tied to specific kernel version
apt-get install zfs-dkms zfsutils-linux   # my apt recommends is off

lsblk                                     # double-check which disks to pool

zpool create -f jeff -o ashift=12 -o autoexpand=on -o autoreplace=on mirror sdb sdd
zfs set mountpoint=/var/jeff jeff
zfs set compression=lz4 jeff
zfs create jeff/blog
zfs create jeff/docs
zfs create jeff/pics
zfs set compression=off jeff/pics

df -h

坐骑是不是现在的叹息 - 发现存在一个/var/jeff包含内容的现有内容 - 将其移开并做了一个reboot......

重启后:

df -htzfs
Filesystem        Size  Used Avail Use% Mounted on
jeff              849G  128K  849G   1% /var/jeff
jeff/blog         850G  128K  849G   1% /var/jeff/blog
jeff/docs         856G  128K  849G   1% /var/jeff/docs
jeff/pics         850G  128K  849G   1% /var/jeff/pics

万岁- 所有存在和位腐烂保护:)

答案3

我刚刚创建了一个全新的拉伸虚拟机来测试这一点。最小安装(只需 ssh 和标准系统工具),编辑sources.list 添加 contrib 和 non-free,然后:

apt-get install spl-dkms zfs-dkms

您可能还想手动安装zfsutils-linux。它应该在您安装时自动安装zfs-dkms,但不同的 Debian 版本和不同版本的 Debian ZoL 软件包的依赖关系可能会有所不同:

apt-get install  zfsutils-linux

看起来好像 systemd 单元文件中存在错误zfs-share。它正在尝试运行/usr/bin/rm而不是/bin/rm.

快速解决方法是运行ln -s /bin/rm /usr/bin,或者:

cd /etc/systemd/system
cp -a /lib/systemd/system/zfs-share.service .
edit zfs-share.service and change `/usr/bin/rm` to `/bin/rm`

然后重新启动 zfs 服务:

systemctl restart zfs-import-cache
systemctl restart zfs-import-scan
systemctl restart zfs-mount
systemctl restart zfs-share

注意:我modprobe zfs在重新启动任何 zfs 服务之前手动运行。我不确定他们是否会自动执行此操作,因此您可能也需要这样做。

顺便说一句,您可能也想apt-get install zfs-initramfs确保 zfs 在 initramfs 期间加载。


我测试过这适用于:

# truncate -s 100M /root/z1
# truncate -s 100M /root/z2
# zpool create tank mirror /root/z1 /root/z2 

# zfs set compression=lz4 tank
# rsync -ax /etc /tank/
# du -sch /etc /tank/etc/
3.5M    /etc
825K    /tank/etc/
4.3M    total

# zpool scrub tank
# zpool status
  pool: tank
 state: ONLINE
  scan: scrub repaired 0 in 0h0m with 0 errors on Thu Aug  3 19:28:21 2017
config:

    NAME          STATE     READ WRITE CKSUM
    tank          ONLINE       0     0     0
      mirror-0    ONLINE       0     0     0
        /root/z1  ONLINE       0     0     0
        /root/z2  ONLINE       0     0     0

errors: No known data errors

zpool 正在工作,并且 /tank 在重新启动后会自动挂载。

结论:现在可以了。


顺便说一句,这个延伸虚拟机使用在我的主系统上创建的 ZFS zvolsid作为其磁盘。我在初始安装后、安装 spl-dkms 和 zfs-dkms 之前立即对其进行了快照,这样如果出现任何重大问题,我可以快速恢复并重新开始。

我首先制作的 zvol 只有 1GB,后来需要增加它以便有足够的空间用于 build-essential、linux-headers-amd64 等:

# zfs list -r -t all export/volumes/stretch
NAME                                         USED  AVAIL  REFER  MOUNTPOINT
export/volumes/stretch                      6.25G   834G  1.77G  -
export/volumes/stretch@2017-08-03-18:31:04   279M      -  1.09G  -

虚拟机中的 Tank设置compression=lz4可能比无用更糟糕 - zvol 已经有 lz4 压缩。

相关内容