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.
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.
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:
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
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.Instead of fighting systemd assumptions and legacy options which may or may not work, make your service and make your mount target depend on it.
My SMB shares are mounted from 192.168.1.2, change to what is correct in your case.
# /etc/systemd/system/wait-for-ping.service
[Unit]
Description=Blocks until it successfully pings 192.168.1.2
After=network-online.target
[Service]
ExecStartPre=/usr/bin/bash -c "while ! ping -c1 192.168.1.2; do sleep 1; done"
ExecStart=/usr/bin/bash -c "echo good to go"
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Enable that service with:
sudo systemctl daemon-reload
sudo systemctl enable --now wait-for-ping.service
Then edit your fstab as follows to include this as final mount option:
x-systemd.after=wait-for-ping.service
Do another systemctl daemon-reload
and you can verify that your mount target has the correct option set. My mount target is /mnt/media
, that creates mnt-media.mount
, so do:
systemctl cat mnt-media.mount
This should have an header like this:
# Automatically generated by systemd-fstab-generator
[Unit]
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
SourcePath=/etc/fstab
After=wait-for-ping.service
... rest of file follows ...
Reboot your machine and you should find your mounts waiting until a ping succeeds.
One option would be, instead of using an entry in /etc/fstab, add the commands the following to /etc/rc.local:
/sbin/ifquery --all --state 2>/dev/null && /bin/mount -t cifs -o credentials=/root/.smbreds,noauto,x-
The rc.local script is the last thing to be run on system boot.
The ifquery first checks to see if all auto configured network interfaces are up (you could potentially change it to a ping command to be sure you've got a working connection), and if true, mounts the filesystem.
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.
– John
Feb 07 '20 at 23:17