1

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.

3 Answers 3

0

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
3
  • from where do I get to know the domain ? Feb 6, 2020 at 15:43
  • I gave it a try and it didnt work. the remote disk is an ext formatted connected to that computer. Feb 6, 2020 at 16:30
  • Where is it failing, can you give more details ? I used to setup several time to remotely mount windows share. Also, domain is optional if you don't use it.
    – ob2
    Feb 7, 2020 at 14:44
0

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.

3
  • So i can include nofail in the mount command? Feb 3, 2020 at 21:17
  • @Ciastopiekarz I think it will not report errors for the device, but hanging could be present. I did not try it first. If it will not help, than use noauto and find out checking host availability script and mount using script. Also try to use ob2's answer.
    – Gryu
    Feb 3, 2020 at 21:24
  • ob2's answer didn't worked Feb 6, 2020 at 16:39
0

//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.

2
  • when I tried to restart I got thsi error: 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
  • can I use noauto with nofail together ? Feb 6, 2020 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .