I have 2 partitions:
/data. My swap file is encrypted at
/etc/crypttab looks like:
root_crypt UUID=6666 none luks swap /data/swap /dev/urandom swap
/etc/fstab looks like (simplified):
UUID=abcd1234 / ext4 defaults 0 1 UUID=5678aaaa /data ext4 defaults 0 2 /dev/mapper/swap swap swap defaults 0 2
How does systemd possibly handle this? The generated crypttab units have to run before fstab to get
/ to mount, but fstab mounting has to run before crypttab units to get to the encrypted swap file.
Conversely, if I wanted my own systemd unit to find and mount
/data and then turn on the swap, at what phase would I do it?
Even better, I would like to write my own unit that checks if the swapfile exists and if not, creates it. The script to do that is easy, but what are my
WantedBy rules? This is before cryptmount, because the swapfile is encrypted, but it is after, because
/ needs to be mounted first.
It is both before fstab, because the swapfile needs to be created to be used, but it is after, because the swapfile is on a filesystem that must be mounted.