I have 2 partitions: / and /data. My swap file is encrypted at /data/swap.

So /etc/crypttab looks like:

root_crypt UUID=6666 none luks
swap /data/swap /dev/urandom swap

And /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?

EDIT: 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 Before After Wants and 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.

Completely confused.

  • Sure, thanks. Not that G+ is showing me an easy way to communicate. Sigh. I am at avi [at] atomicinc [dot] com. – deitch Apr 24 '16 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.