Automatic remount cifs/SMB after short network interruption

9

3

A Windowsserver provides a network directory called data via CIFS/SMB protocol. The data folder is mounted on a Linux client with password and user authentification.

Sometimes the drive gets disconnected, but is available again after a second. I do not know exactly why, but it seems to be because of the Windows server or a broken network component.

How can I make Linux reconnect automatic as soon as possible?

Jonas Stein

Posted 2013-06-12T08:03:18.947

Reputation: 773

1Try mount it with the _netdev option, it might help if you having network problem on the Linux client. – Intenso – 2013-06-12T08:59:23.953

1@Intenso Can you provide a source for this? The man page said: _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). – Jonas Stein – 2013-06-12T18:16:56.347

Answers

9

I'd recommend mounting it via autofs. This is a service that will mount a directory on demand (for example if you cd into it or ls it) and unmount it automatically after a user defined timeout.

  • Install the autofs package for your distribution (by the way, remember to include your distro in your questions since an answer's details may depend on it).

  • Add the following to /etc/auto.master

    /media/[my_server] /etc/auto.[my_server]
    

    Where /media/[my_server] is the mount point of the share.

  • Create a file /etc/autofs/auto.[my_server] with this line:

    [any_name] -fstype=cifs,[other_options] ://[remote_server]/[share_name]
    

For more information see here and here.

terdon

Posted 2013-06-12T08:03:18.947

Reputation: 45 216

2What is [any_name] - is it literally the string [any_name], or is it just some arbitrary piece of text? – detly – 2015-02-08T08:22:38.717

Oh, right, [my_server] is the parent of the mount point, and [any_name] is the actual mount point (eg. the share name). – detly – 2015-02-08T08:33:33.047

@detly yup, exactly – terdon – 2015-02-08T13:19:33.410

2Could you provide a real example of what [my_server] and [any_name] would be? – bswinnerton – 2018-08-18T19:25:42.337