I want systemd on mount /mnt/test to automatically call a program (in real life cryptsetup to unlock the underlying device, for testing here echo) before the file system is mounted and after it is unmounted.

With /etc/systemd/system/stickbak-encryption.service:

Description=stickbak encryption

ExecStart=/bin/echo Unlock device.
ExecStop=/bin/echo Lock device.


and /etc/fstab (partly):

/dev/$DEVICE /mnt/test auto noauto 0 0

this works (after daemon reload and enabling the service) for systemctl start mnt-test.mount and respectively systemctl stop mnt-test.mount (as root).

On mount /mnt/test, however, systemctl status mnt-test.mount stickbak-encryption shows the latter service being inactive (dead), while the former is active (mounted).

How can I (or can I not?) set up a dependency that is honoured when /bin/mount is called as well? The status of the mount unit shows that mount /mnt/test seems to be translated to ExecMount=/bin/mount /dev/$DEVICE /mnt/test -t auto -o noauto, so apparently systemd gets notified.

  • since fstab is automatically parsed by systemd, and given that a quick google search resulted in no input on how one could control the generated mount file in a way to specify dependencies, I would guess this is impossible at this moment, but I really hope to be wrong and to see someone answer this question positively, for I'd profit out of it as well – brunocodutra Oct 1 '13 at 1:56

I very recently asked myself the same question, but I quickly came to the realisation that it doesn't work that way.

When you use the mount command-line program, systemd is not involved: mount reads /etc/fstab (or takes options from the command-line) and mounts the device. When you start a systemd mount unit, it's parsed by systemd which internally uses mount system calls to perform the mount.

So there is no way to systemd to get involved when you use mount.

As an aside, there is an interesting difference between using mount and systemd in what they accept as valid in /etc/fstab. Systemd parses the file and creates mount units that it then uses. When it does so, it accepts fewer parameters than mount requires.

If you use systemd then you only have to supply the device and mount point, however mount requires further options such as the file system and options.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.