Debian

在 debian 9 上安裝 zfs

  • May 26, 2020

我嘗試在 debian 9.1 上安裝 zfs,但是遇到了一些錯誤。

我的第一次安裝只是 zfs-dkms 但是我在網上看到 zfs-dkms 也需要 spl-dkms 才能執行。


我的步驟是更改我的sources.list添加contrib non-free如下:

/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) ...

按照建議閱讀journalctl -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 的正確方法是什麼?

@cas 的實際答案很好,但需要進行一些更正。

因此,讓我們重新安裝 Debian 9,並假設contrib 非免費儲存庫也未啟用。


第 0 步 - 啟用 contrib 非免費儲存庫

我曾經在裡面sed找到並替換了main這個詞/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 或直接創建基於磁碟的文件。

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

引用自:https://unix.stackexchange.com/questions/383566