I have a Ubuntu 19.10 install that was originally setup with EXT4 but I migrated to root on ZFS, loosely following the instructions at https://github.com/zfsonlinux/zfs/wiki/Ubuntu-18.04-Root-on-ZFS.
I had numerous issues with the install that I didn't have with PopOS or Arch when I set them up with ZFS (such as not being able to have /var being a mounted dataset).
My only remaining issue is that I have a second hard drive, also ZFS, that I'm trying to have the system automatically import at boot. Both the system and this secondary hard drive are using LUKS. I correctly have cryptsetup setup so that the secondary hard drive is decrypted at the same time that I type the password for the root system.
The pool was not being imported by the cache file (despite this being set to run after cryptsetup), which is apparently another bug that I saw referenced on AskUbuntu. I then setup a systemd service to import the pool specifically, in the same way that the instructions above recommend creating a service for importing the boot pool.
The problem is that I cannot get the service to run at the correct time and so importing the pool always fails with ZFS saying the pool does not exist. It seems that I cannot get systemd to run the service at the correct time. With the file below I noticed that the service definitely is being run after cryptsetup is complete, so I don't know why ZFS cannot find the pool. The weird thing is that it appears to be the first service that's being run after cryptsetup is finished. I did notice at some point some systemd logs specifying that the cryptsetup dependency was tossed due to a dependency loop but I haven't seen that error now in a while and am not sure what could be causing that.
So the question is - how do I make this work? Is there something obvious with systemd that I'm missing?
Here is the service file that I am using.
[Unit] DefaultDependencies=no Requires=zfs-load-module.service After=systemd-udev-settle.service After=zfs-load-module.service After=cryptsetup.target Before=zfs-import-scan.service Before=zfs-import-cache.service [Service] Type=oneshot RemainAfterExit=yes ExecStartPre=/bin/sleep 3 ExecStart=/sbin/zpool import -N zfsmedia [Install] WantedBy=zfs-import.target
Without the ExecStartPre, it never works. The system boots without mounting the pool. With the ExecStartPre, it works about 50/50. I haven't tried a bigger delay. I also tried adding After=fs-remount-rw.service to no effect. If I remove the Before= lines then the system bizzarely drops into a rescue shell with half of the system datasets not mounted (I also had that symptom numerous times while trying to get the root on ZFS).
After the failure to import at boot, I can then enter "zpool import zfsmedia" after boot and it works fine. It seems like it's just the timing of the systemd unit that is wrong and I can't figure out how to get it right, or what to do if the problem is systemd not honoring dependencies.