Technology, Linux, Windows

Windows shares on Linux

Since I elected to use Server 2012 R2 as my file & print server, I had a need to map various windows shares on my Linux containers.  There are a few prerequisites that need to be in place in order to make this work, at least on CentOS 7.  First things first, every machine needs to have the cifs-utils package installed.

In order to make an entry in /etc/fstab and have these shares mounted automagically at boot, I needed to create credential files to allow them to authenticate.  You can put these files wherever you want, I chose to store them in /etc.

Then you want to make this file read/write only for root to protect the credentials:

You can now reference this file in /etc/fstab to pass credentials when mounting a share.  Initially, that line looked like this:

To break it down for those who might not know:

  • //myserver/myfolder – this is your windows UNC path
  • /mnt/myfolder – this is the mount point on the system
  • cifs – this is the filesystem type
  • soft – if for whatever reason the share disconnects while the system is accessing it, it will return an error.  By default this is hard, meaning that the program will hang/crash instead.
  • rw – mount it in a read/write state
  • credentials= – path to the credentials file that was created earlier
  • 0 0 – dump/pass numbers.  Dump indicates whether and how often the file system should be backed up by the dump program, pass indicates the order in which fsck should check the drive on boot… root file system is 1, others can be 0 (for never) or 2 (indicating after root).

However, I was running into an issue where the share would disconnect after 5-10 minutes and the only way I could get it to restore would be to unmount/remount like so:

For just the standard shares this wasn’t a big deal, but I had a share setup for my Plex media, as well as VM backups being copied onto a different share.  So it was causing me some headaches for a bit until I got it figured out.  It would cause the rsyncs for my backup jobs to fail, as well as making my Plex server timeout on the first attempt to use it after it had been idle for awhile.   For a quick & dirty fix I ended up temporarily setting up cron jobs on the machines that would touch a file on the share every few minutes and act as a keep alive of sorts.

To solve the issue, I found that I needed to add the cifs version to the fstab:

Since making this change, I haven’t had any more issues.

Series Navigation<< File server replication with RobocopyInstall Plex on CentOS >>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.