Link to home
Start Free TrialLog in
Avatar of cawasaki
cawasaki

asked on

mount cifs share everytime server reboot on redhat 7.4

hello,

i need to mount a cifs share on redhat 7.4 server automaticly after reboot.

i use this command to mount the share:

mount -t cifs "//192.168.1.1/NAS_share" -o username=toto,password=toto,domain=contoso.com,dir_mode=0777,file_mode=0777,vers=3\.0 /media/share

Open in new window

this work but after reboot the server i lost the mount, so i test on /etc/fstab this line but its not work
//192.168.1.1/NAS_share /media/share cifs auto,user=toto,password=toto,domain=contoso.com,default 0 0

Open in new window


i use authentification with user on my Active directory to access the share.

thank you for help
Avatar of Daniel McAllister
Daniel McAllister
Flag of United States of America image

In both cases you are LIKELY to be attempting the mount BEFORE the authentication daemons (samba? winbindd?) are running.
Put your startup after a delay in rc.local
Or, better yet -- use the automounter and don't even try to mount the filesystem until needed (likely well after startup and network auth daemons are completed).

In any case, IMHO, once you know the issue, there are DOZENS of ways to cure it -- pick the right one for YOUR situation...

Dan

PS: I do an automount on a /media/movies folder on my home system... never fails me :) (well, once when the server had a corrupted FS, but that's a different story) :)
For my CIFS mounts, I have a cron job that runs every 5 minutes to check if the share is mounted and, it if isn't, to attempt to do that.   This takes care of it all of the time -- not just on boot.
Avatar of cawasaki
cawasaki

ASKER

hello Jan,

do you have an exemple how i can do it with a cron job?

thanks
Put your credentials in a file and refer to the file:

#!/bin/bash -x

RESULT=`/usr/bin/stat -f /media/share | /bin/grep cifs | /bin/grep -v grep`

if [ "$RESULT" == "" ]; then

  #attempt to mount
  /bin/mount -v -t cifs //192.168.1.1/NAS_share /media/share -o credentials=/etc/smb-credentials,uid=user

  RESULT=`/usr/bin/stat -f /media/share | /bin/grep cifs | /bin/grep -v grep`

   if [ "$RESULT" == "" ]; then

     /bin/echo "Please check to see that this directory exists" # | /usr/bin/mailx -s "Mount of //192.168.1.1/NAS_share failed" you@yourdomain.com
     exit

   fi

fi

You may need to change the path on the command and/or install mailx.

Create a cron job in /etc/cron.d:

*/5 * * * * user /path/to/script

where "user" is the account that needs to mount the share.
No offense to Jan, but setting a cron job to re-mount it is a "poor man's" automount.

Here is an instruction manual for the real-deal...

https://www.unixmen.com/how-to-mount-a-smbcifs-share-as-an-automount-on-centosfedorarhel/

Dan
Sure, until it dies.   Been there, done that.
Jan,

I still disagree - even more strongly so, given your explanation!

Keeping a full gas can in your trunk because you're always running out of gas isn't the same as plugging the leak in the fuel tank.

If your automount daemon is crashing, you have something wrong with your system, and choosing a hammer and chisel to work a path around it just means that the same problem is going to bite you in the backside later -- probably in a more critical way.

Furthermore, this is RHEL7, so you can set your automount daemon to restart automatically if it ever does crash. (See systemd restart-on-failure options). In fact, on most of my systemd servers, the automount daemon is one of several services (qmail-*, httpd, named, and a few others) that not only restart on failure, but they also send an email alert when they do restart, so that I'll know to research the problem! (see a writeup on that here: http://northernlightlabs.se/systemd.status.mail.on.unit.failure)

This isn't Microsoft -- failures in Linux systems that require a restart of a service are RARE, and are DEFINITELY not Standard Operating Practice. If you have a service that routinely fails on you, you should FIX IT, not work around it! (Yes, that is my opinion - and yes, I realize its only worth what you paid for it on the FREE part of this site...)

Dan
Well, I took it to mean that the CIFS mount *was* Windows.  And there I have had problems.  So, unless I am incorrect about his share being Windows, my suggestion stands.
Ummmm.... if the filesystem/mount source (being Windows) won't mount with an automount, then it won't mount from a cron job either.

As far as I know, you can't fix a broken Windows fileserver with commands that run on a Linux server.
I'd be anxious to hear otherwise.

Dan

PS: The question says he's trying to mount the CIFS filesystem (assumed to be FROM a Windows system, but not NECESSARILY so) onto an RHEL7 server. So the commands we're talking about here (including the automounter) are in the RHEL7 server.
You're missing the point.  If it mounts and the Windows system barfs for whatever reason, I have the cron job attempt to remount the share.  And, if it doesn't mount, then send an email to that effect.

The commands that the author provided indicate that the mount is performed from the linux side.
OK, but how is that a counterpoint to the automounter? If the mount is lost by the automounter, it will attempt to re-mount as soon as someone attempts to access the resource. That is the core nature of the automount daemon. What's more, with the automounter you don't have to wait 5 minutes for the cron job to kick in...

I stand by my claim (opinion) that putting the mount command in a 12-times-an-hour cron job is a work around for people who can't figure out the automount service....

I've had enough of this banter without input from the question author. I'm setting myself to ignore the question from here. If you are the author and desire my help to setup the automounter, send me a message directly.

Good luck to you all...

Dan
ASKER CERTIFIED SOLUTION
Avatar of cawasaki
cawasaki

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
my solution work