In my /etc/fstab
I use the following:
//192.168.5.167/H /mnt/ssd ssd credentials=/root/.smbreds 0 0
But in case if the drive on Windows is not connected or Windows machine is not running, Ubuntu containing this /etc/fstab
won't boot.
You should consider user autofs instead of fstab. AutoFS will mount the share on demand.
Install the requirements with
sudo apt install autofs smbclient cifs-utils
Add the following line into /etc/auto.smb
.
sudo /cifs /etc/auto.smb --timeout=300
Of course create the folder
sudo mkdir /cifs
Restart the service
sudo systemctl restart autofs
Create the folder that will contain the credentials
mkdir /etc/creds
chmod 600 /etc/creds
Create the file /etc/creds/192.168.5.167
(or servername) and copy the content you currently have into /root/.smbreds. It should look like:
username=<smb username>
password=<smb password>
domain=<smb domain>
Your share should now be auto-mounted as soon as you do:
cd /cifs/192.168.5.167 #Or servername if you changed to servername)
You can even create a symbolic link if you need to have to same path than previously
umount /mnt/ssd
rmdir /mnt/ssd
ln -s /cifs/192.168.5.167 /mnt/ssd
If you read man fstab
you will see the next options you could try in your case:
noauto do not mount when "mount -a" is given (e.g., at
boot time)
nofail do not report errors for this device if it does
not exist.
The next step could be a script in cron that checks host availability and connects your windows share using mount /mnt/ssd
command.
Here is an example how you could check host availability by script.
noauto
and find out checking host availability script and mount using script. Also try to use ob2's answer.
//192.168.5.167/H /mnt/ssd ssd credentials=/root/.smbreds 0 0
Did you mean:
//192.168.5.167/H /mnt/ssd cifs credentials=/root/.smbreds 0 0
Unmount the share:
sudo umount /mnt/ssd
Edit fstab and add two more options: noauto and x-systemd.automount:
//192.168.5.167/H /mnt/ssd cifs credentials=/root/.smbreds,noauto,x-systemd.automount 0 0
Then do the systemd 2-step:
sudo systemctl daemon-reload
sudo systemctl restart remote-fs.target
noauto will prevent that mounting at boot.
x-systemd.automount will mount the share when accessed. It will be seamless. Just go to /mnt/ssd and it will mount. You can also add an option to have it unmount when idle if you want.
Feb 06 16:35:55 rockpro64 systemd[1]: Stopped target Remote File Systems.
Feb 06 16:35:55 rockpro64 systemd[1]: Stopping Remote File Systems.
Feb 06 16:35:55 rockpro64 systemd[1]: Dependency failed for Remote File Systems.
Feb 06 16:35:55 rockpro64 systemd[1]: remote-fs.target: Job remote-fs.target/start failed with result 'dependency'
Feb 6, 2020 at 16:38