how to setup ubuntu that fstab runs after network is connected?
8,239
You can declare this filesystems as a network device by adding _netdev
to the options sections of your fstab line like so:
//192.168.5.167/H /mnt/ssd cifs credentials=/root/.smbreds,_netdev,noauto,x-systemd.automount 0 0
This will prevent the system from attempting to mount this filesystem until the network has been enabled on the system.
This is stated in man-pages for mount
:
_netdev
The filesystem resides on a device that requires network access (used to prevent the system from attempting to mount these filesystems until the network has been enabled on the system).
Important:
- You appear to be trying to use
x-systemd.automount
but not successfuly. As it appears in the example you posted in your question, you have added an extra space betweenx-
andsystemd.automount
which will result in an error. If you want to use systemd.automount in your fstab options, then use it like thisx-systemd.automount
and then runsudo systemctl daemon-reload
and follow it bysudo systemctl restart remote-fs.target
- I assume you understand that having the
noauto
option as in the example you added to your question, will prevent this filesystem from beeing mounted at boot time and will not be mounted withmount -a
command. This filesystem can only be explicitly mounted with this option in the fstab line. If that is not what you want, then you should remove thenoauto
option.
Related videos on Youtube
Comments
-
Ciasto piekarz over 1 year
right now
I have setup
/etc/fstab
like this://192.168.5.167/H /mnt/ssd cifs credentials=/root/.smbreds,noauto,x- systemd.automount 0 0
I want to set it up like first network should be connected and then fstab mount should get mounted.
-
Ciasto piekarz over 4 years
/sbin/ifquery --all --state
returnslo=lo
-
John about 4 yearsRaffa's answer is clearly the better solution. If for some reason someone wanted to use my rc.local solution, a better test command might be
ping -c 5 -t 2 192.168.5.167 >/dev/null
. If that IP can't be pinged, the mount command won't be run.be run. -
B. Butz almost 3 yearsNotice carefully the leading underscore. It's _netdev, not netdev. I missed that the first tme.