10

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?

2
  • 1
    Try mount it with the _netdev option, it might help if you having network problem on the Linux client.
    – Intenso
    Jun 12, 2013 at 8:59
  • 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). Jun 12, 2013 at 18:16

4 Answers 4

11

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.

4
  • 2
    What is [any_name] - is it literally the string [any_name], or is it just some arbitrary piece of text?
    – detly
    Feb 8, 2015 at 8:22
  • Oh, right, [my_server] is the parent of the mount point, and [any_name] is the actual mount point (eg. the share name).
    – detly
    Feb 8, 2015 at 8:33
  • @detly yup, exactly
    – terdon
    Feb 8, 2015 at 13:19
  • 3
    Could you provide a real example of what [my_server] and [any_name] would be? Aug 18, 2018 at 19:25
2

To add to the autofs answer, I recommend doing the the way it is described here:

https://andrewaadland.me/2017-06-18-autofs-nfs-and-archlinux-key-not-found-in-map-sources/

That is:

  • Make the first field in auto.master is always /-.
  • Use full mount name in /etc/autofs/auto.server.

So in my case, /etc/autofs/auto.master contains:

/-      /etc/autofs/auto.nas

And /etc/autofs/auto.nas contains:

/home/rkitover/nas -fstype=cifs,credentials=/home/rkitover/.nascredentials,uid=1000,gid=1000,iocharset=utf8 ://nas/rkitover

This works for me!

2

Just to offer another angle, a current solution is doing this with systemd, as described here:

https://anteru.net/blog/2019/automatic-mounts-using-systemd/

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Dec 15, 2021 at 22:38
0

systemd + Mounts with Special Characters

Since most of these blogs and posts and such don't mention this in a way that was adequate for me, I want to a few key points:

  1. Keys like What= and Where= have literal values - no escapes
  2. Paths on the filesystem must be systemd-escaped
    • the shell will interpret \, so SINGLE quote it to escape: 'my\x20'
  3. You MUST run sudo systemctl daemon-reload between name/content changes
  4. sudo journalctl -xe ESCAPEME.mount will give better logs that status

Example: /etc/systemd/system/ESCAPEME.mount

/etc/systemd/system/mnt-TrueNAS-TV\x20Shows.mount:

[Unit]
  Description=My CIFs Media Mounter
  Requires=network-online.target
  After=network-online.service

[Mount]
  What=//192.168.1.200/TV Shows
  Where=/mnt/TrueNAS/TV Shows
  Options=username=my-user,password=my-secret
  Type=cifs

[Install]
  WantedBy=multi-user.target

Example: /etc/systemd/system/ESCAPEME.automount

/etc/systemd/system/mnt-TrueNAS-TV\x20Shows.automount:

[Unit]
  Description=My CIFs Media Automount

[Automount]
  Where=/mnt/TrueNAS/TV Shows

[Install]
  WantedBy=multi-user.target

More Info

See https://unix.stackexchange.com/questions/455094/auto-remount-cifs-share/740886#740886.

You must log in to answer this question.

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