CIFS mounts hang on read
I have a problem with a bunch of CIFS mounts that look like this:
//192.168.10.2/remote-share /home/windows-shared/remote-share cifs defaults,user=xxx,password=xxx,uid=603,gid=603 0 0
This issue occurs after a while, usually after a day when the users boot their machines in the morning and their shares don't work remotely any more.
So when I try to do a ls
I get this:
ls: cannot access /home/windows-shared/remote-share: Host is down
I get nothing related in dmesg
. The problem with this is that now any read call to this part of the system just hangs so as a solution I would rather have a faster error rather than hanging indefinitely.
After reading a bit the man page of mount.cifs
it appears that by default every mount is soft
meaning that it would timeout eventually. The problem is that it takes a way too long to timeout.
Update:
Adding these parameters to the mount command didn't help either:
soft,timeo=300,retrans=3
I would highly suggest AutoFS.
This will dynamically mount and unmount your network shares in the background, all transparent to the user. I used to have problems with unmounting and remounting mobile devices until I made the switch.
Unfortunately, there are far too many guides which overly complicate autofs setup. Assuming you're on an Ubuntu box, here are the easy instructions on setting it up.
Here's some very simple instructions:
- Install from apt-get:
sudo apt-get install autofs -y
- Remove everything in
/etc/auto.master
and replace with:/- /etc/auto.cifs --timeout=20 --ghost
- Add one line like this to auto.cifs for each mount:
/mnt/LOCAL/MOUNT/PATH -fstype=cifs,rw,noperm,credentials=/etc/auto.credentials ://SERVER/MOUNT
- In
/etc/auto.credentials
, add the following content:username=USERNAME password=PASSWORD
- Finally,
sudo service autofs restart
.
That's it.