Debian – Install zfs on debian 9 stretch

aptdebianzfs

I tried to install zfs on debian 9.1, however I'm experiencing some errors.

My first installation was only of zfs-dkms however I read on the net that also the spl-dkms is required for zfs-dkms to run.


My steps were to change my sources.list adding the contrib non-free as follows:

/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

Done a classic apt-get update and then tried installing zfs with the following:

apt-get install spl-dkms

and only after

apt-get install zfs-dkms

As a result, I have these errors:

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

Reading journalctl -xe as suggested I get:

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.

What's wrong here? I missed something else? How is the zfs-linux package related to zfs installation?

What is the correct way to install zfs in debian 9 ?

Best Answer

The actual answer by @cas is good but have some corrections to be applied.

So let's take a fresh installation of Debian 9 and assuming that the contrib non-free repositories are also not enabled.


Step 0 - Enable the contrib non-free repositories

I used sed to find and replace the word main inside /etc/apt/sources.list

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

apt-get update

Step 1 - ZFS Installation

Since the last fixes spl-dkms is correctly seen as zfs-dkms dependency so it's recalled automatically and it's not necessary to install it manually before zfs-dkms. The symbolic link is needed due to a bug inside the zfs distribution in Debian, that doesn't look for rm binary in the right position.

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

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

apt-get -y install zfs-dkms

Step 2 - ZFS Restart

At this point zfs-dkms is installed but it throws errors in journalctl -xe; to start zfs properly use:

/sbin/modprobe zfs

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

Step 3 - YOU MUST CREATE AT LEAST ONE ZPOOL

At this point I discovered that YOU must create a zpool before reboot otherwise zfs will not load the proper modules if there are no zpools. It's a sort of saving resources mechanism ( but even in that case this will still throw errors inside journalctl -xe )

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

" We are not doing this because ZFS modules would taint the kernel, if there's no zpool available then it shouldn't be loaded. "

If you miss this part you have to start from Step 2

For example, by using the example provided by @cas, you can create this file based zpool or directly create your disk based ones.

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

then after a reboot everything will work with no errors in journalctl -xe