cifs mounted folder keeps disconnecting (ubuntu server)

14,793

Solution 1

I guess this has something related to patches delivered by windows updates to prevent ransom-ware attack. It seams the server which holds the shared folder rejects CIFS V1 requests. By default mount uses CIFS V1. give it a try by adding vers=2.0 to the end of your mount command. I had the same problem and this way i manged to fix it. PS / FYI : my command looks as follows

//192.168.1.10/public/mount /media/windowsshare cifs credentials=/home/MY_USERNAME/.smbcredentials,iocharset=utf8,sec=ntlm,vers=2.0 0 0

Solution 2

From your mount output added to your question, we can see you are still using CIFS 1.0.

I would advise to mount the mount as CIFS 2.1 if the servers supports it, as that from CIFS v2.0 or 2.1 the protocol supports a better recovery from connection sleep/cuts. To do that the option is vers=2.1.

Durable handles (2.02, 2.1) – allow for connection to transparently reconnect to the server if there is a temporary disconnection

I also advise to add the option echo_interval=60 instead of adding a while loop, as in that way, the SMB client code sends itself a keepalive beacon every minute to the server.

Beware, that as I warned and corrected in @Thillina answer, the options are all on the 3rd field separated by a comma.

For more details, please see CIFS randomly losing connection to Windows share

Reading the articles I am quoting in my post:

3.0 - The SMBv3.0 protocol that was introduced in Microsoft Windows 8 and Windows Server 2012.

So you having Windows server 2012 means that ar least the Windows side supports CIFSv3.0 and lower.

To check if it was renegotiated and with which version, change the options in your fstab file, and do:

#mount -o remount /media/docs

and then run a mount command to check with what version the mount was done/negotiated.

Share:
14,793

Related videos on Youtube

neurino
Author by

neurino

Programmer and musician

Updated on September 18, 2022

Comments

  • neurino
    neurino over 1 year

    I have this fstab entry to allow a tomcat app to read/write on a Windows Samba shared folder:

    //dc/docs    /media/docs      cifs       credentials=...,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm,uid=tomcat7,gid=tomcat7,dir_mode=0770,file_mode=0770 0 0
    

    Problem is it keeps unmounting after a certain amount of time -- not a Windows failure, I can access the share elsewhere

    $ sudo ls /media/docs
    finance  postsale  repository
    
    #after e.g. 10 minutes...
    $ sudo ls /media/docs
    [sudo] password for user:
    ls: cannot access '/media/docs': Connection reset by peer
    
    #this takes ages to complete
    $ sudo umount /media/docs
    
    #this fails immediately after, succedes after about 5/10 seconds
    $ sudo mount /media/docs
    mount error(112): Host is down
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
    $ sudo mount /media/docs
    mount error(104): Connection reset by peer
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
    $ sudo mount /media/docs
    $ sudo ls /media/docs
    finance  postsale  repository
    

    How do I debug this or prevent from dropping?

    Tomcat app users have no rights to remount so everytime they need to rise a ticket to IT.

    Please note this mount on the same share does not drop (only difference I spot is user is a sudoer while tomcat7 above is not):

    //dc/share       /media/share     cifs       credentials=....credentials,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm,uid=user,gid=user,dir_mode=0770,file_mode=0770 0 0
    

    UPDATE:

    Folder /var/log/samba is empty -- how do I set logging for samba?

    If I keep on listing the folder it does not drop:

    while true; do date; ls /media/docs; sleep 5; done
    

    UPDATE 2:

    Here the mount output:

    //fs-mxp/ZZZshare on /media/share type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
    //fs-mxp/ftp on /media/ftp type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
    //sql-mxp/C$ on /media/sql type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=administrator,domain=YYY-it,uid=1000,forceuid,gid=1000,forcegid,addr=10.39.52.11,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
    //fs-mxp/ZZZdocs on /media/docs type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=YYYdoc,domain=YYY-it,uid=113,forceuid,gid=123,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
    //fs-mxp/ZZZshare/ASTE on /home/esales/aste type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1001,forceuid,gid=1002,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
    //fs-mxp/ftp/YYYvendor on /home/esales/YYYvendor type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=XXX,domain=YYY-it,uid=1001,forceuid,gid=1002,forcegid,addr=10.39.52.6,file_mode=0770,dir_mode=0770,nounix,serverino,mapposix,rsize=61440,wsize=65536,actimeo=1)
    
    • X Tian
      X Tian almost 7 years
      I would look at the log files (/var/log/samba/...) first and if they do not give enough detail, increase the verbosity to help diagnose, what's going on. The logs on the shared side may help too? Add the results to your original question, if you see something that might be useful.
    • neurino
      neurino almost 7 years
      @X Tian: /var/log/samba/ is empty, any advice to turn on logging or increase verbosity? If I keep listing the folder every 5 seconds it does not drop...
    • neurino
      neurino almost 7 years
      @RuiFRibeiro: added mount output, thanks for your interest.
    • roaima
      roaima almost 7 years
      You might also want to consider using the automounter (autofs4), which will automatically and transparently mount and umount filesystems on demand.
  • neurino
    neurino almost 7 years
    Thank you, I tried adding vers=2.0 at the end, let's see if it solves. In the meanwhile I added a cron job that every 5 minutes touches the shares to keep alive, I'm posting my workaround too for reference.
  • Rui F Ribeiro
    Rui F Ribeiro almost 7 years
    The syntax, while accepted, was wrong, and the connection were still done with 1.0; options should be done in the 4th field, and not at the end. I edited the code, and replace the tags with <code>, as it is more appropriate for showing a long line.
  • neurino
    neurino almost 7 years
    Thanks Rui, I changed to suggested vers=2.1 -- BTW how do I check if the server supports it? It's a Win Server 2012 -- unluckily it won't mount with option echo_interval=60 so, at the moment, I'm leaving my cifs ping on
  • Rui F Ribeiro
    Rui F Ribeiro almost 7 years
    added to the answer. I suggest to read my own link/answer, as it is related and quite detailed; you original question is a bit confusing, I could swear it was a Samba Server + Linux client until now, and from the comments about looking at /var/log/samba, it seems I was not the only one.
  • Rui F Ribeiro
    Rui F Ribeiro almost 7 years
    No problem at all, I was just providing feedback.