0

I have a smb mount on my linux server, but occasionally it loses connection, interrupting the software using the mounted directory. Is there a way to cache the smb mount on local disk?

1
  • What do you mean by "cache the smb mount"? Feb 17, 2023 at 10:00

1 Answer 1

0

It sounds like you want to have a SMB share mounted when in use. I would recommend using autofs for this.

Install autofs if not currently available and cifs-utils.

sudo apt-get install autofs cifs-utils # Or
sudo yum install autofs cifs-utils

Enable the service at boot.

sudo systemctl enable autofs
sudo systemctl start autofs

Setup config files.

/etc/auto.master

/path/to/mountpoint /etc/auto.<my_server>

/etc/auto.<my_server>

<any_name> -fstype=cifs,rw,credentials=/path/to/creds.txt ://<remove_server>/<share_name>

/path/to/creds.txt make sure to do chmod 600 on file

username=Username
password=Password

Reload the service sudo systemctl restart autofs

Some links for more information

You can also do this with fstab but the key difference here is when the smb share is not in use autofs will timeout the mount and free resources, while fstab will keep it mounted and use resources. You can set no timeout for autofs if it is important with --timeout=0 but I would recommend against it to save resources.

If you want to avoid autofs you can follow the below method for fstab. You will still need to create a creds file.

Add to /etc/fstab

//<server>/<share> /path/to/mount cifs credentials=/path/to/creds.txt 0 0

You must log in to answer this question.

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