[systemd-devel] Unable to get service to wait for a mount before starting

Andrei Borzenkov arvidjaar at gmail.com
Tue Oct 29 18:39:12 UTC 2024


29.10.2024 10:03, Adam Nielsen wrote:
>>> I tried using RequiresMountsFor=/mnt/share however again, if it runs too
>>> early in the boot process the mount is not there and the unit fails to
>>> start, and is not retried (logs just say "Job myservice.service/start
>>> failed with result 'dependency'.")
>>
>> RequiresMountsFor only works if systemd knows about this mount point
>> which in practice usually means this mount point must be present in
>> /etc/fstab.
> 
> Thanks for the suggestion!  I do have it in /etc/fstab, although there
> are two:
> 
> server:/path /mnt/server/path nfs4 x-gvfs-hide,noauto,x-systemd.automount,timeo=15,soft,proto=tcp 0 0
> /mnt/server/path/subfolder /mnt/share none bind,_netdev,x-systemd.automount,x-systemd.requires=/mnt/server/path 0 0
> 

x-systemd.automount makes no sense. You service has implicit Requires 
mnt-share.mount that will trigger mounting of both filesystems on boot 
anyway and won't have any idle timeout.

> This mounts an NFS path into a folder, then bind mounts a folder within
> it to /mnt/share.  I then use RequiresMountsFor=/mnt/share, since it's
> the second mount that has to happen before the systemd unit can start.
> 
> The mounts work (they always mount in the correct sequence) it's just
> that RequiresMountsFor= doesn't seem to like this set up.
> 

Instead of guessing you should have read the logs. I cannot reproduce it 
(without using NFS) and educated guess is - you do not have proper 
network-online.target implementation, so your NFS is attempted to be 
mounted before network setup is finished and this attempt fails.

But without logs we can speculate until the cows come home.


More information about the systemd-devel mailing list