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 between x- and systemd.automount which will result in an error. If you want to use systemd.automount in your fstab options, then use it like this x-systemd.automount and then run sudo systemctl daemon-reload and follow it by sudo 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 with mount -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 the noauto option.
Share:
8,239

Related videos on Youtube

Ciasto piekarz
Author by

Ciasto piekarz

Updated on September 18, 2022

Comments

  • Ciasto piekarz
    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
    Ciasto piekarz over 4 years
    /sbin/ifquery --all --state returns lo=lo
  • John
    John about 4 years
    Raffa'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
    B. Butz almost 3 years
    Notice carefully the leading underscore. It's _netdev, not netdev. I missed that the first tme.