bitcreed

Linux & Systems

Fixing ZFS Filesystems That Do Not Automount on Ubuntu

· updated

I recently had a case of ZFS filesystems that were added to an existing Ubuntu 22.04 system. Every time the system restarted, the ZFS daemons showed as “dead” and zpool list returned “no pools available”.

That was a real problem: users could log in, but couldn’t reach their files and configs, because /home was on that ZFS.

Mounts manually, but not on boot

Starting the ZFS systemd services manually succeeded but didn’t mount the filesystems, while zpool import -a fixed things temporarily. Still, the filesystems would not come up on boot.

root@capernaum:/root# systemctl status zfs-zed
 zfs-zed.service - ZFS Event Daemon (zed)
     Loaded: loaded (/lib/systemd/system/zfs-zed.service; enabled; vendor prese>
     Active: inactive (dead)
       Docs: man:zed(8)

root@capernaum:/root# systemctl status zfs-import-cache
 zfs-import-cache.service - Import ZFS pools by cache file
     Loaded: loaded (/lib/systemd/system/zfs-import-cache.service; enabled; ven>
     Active: inactive (dead)
       Docs: man:zpool(8)

The ZFS module was there and loaded, but did “nothing” to mount the filesystems, even though all disks were present.

root@capernaum:/root# dmesg | grep zfs
[    3.911970] zfs: module license 'CDDL' taints kernel.
[    3.912006] zfs: module license taints kernel.
root@capernaum:/root# journalctl -u zfs
-- No entries --
root@capernaum:/root# zpool status
no pools available

Problem: missing zfs.target and no ZFS in the initrd

It turned out that the ZFS target had never been enabled and the initrd was missing ZFS support:

root@capernaum:/root# ls /etc/systemd/system/multi-user.target.wants/zfs.target
ls: cannot access '/etc/systemd/system/multi-user.target.wants/zfs.target': No such file or directory
root@capernaum:/root# lsinitramfs /boot/initrd.img-$(uname -r) | grep zfs
root@capernaum:/root# # (no results listed)

Solution: install zfs-initramfs and enable zfs.target

Installing the missing zfs-initramfs package with sudo apt install zfs-initramfs, which conveniently also regenerates the initramfs, and enabling the systemd target solved the problem.

root@capernaum:/root# lsinitramfs /boot/initrd.img-$(uname -r) | grep zfs
conf/conf.d/zfs
etc/default/zfs
etc/zfs
etc/zfs/zed.d
# ...

Enable the systemd target with:

root@capernaum:/root# systemctl enable zfs.target
Created symlink /etc/systemd/system/multi-user.target.wants/zfs.target /lib/systemd/system/zfs.target.

I also installed the missing zsys package with sudo apt install zsys.

Upgrade ZFS

For good measure, I also upgraded the pool with zpool upgrade [poolname]. Running zpool upgrade listed it as missing some features, because it had been created from a live disk with an older ZFS version.

Need help with a Linux system too? Get in touch.