• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

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
0
cawasaki
Asked:
cawasaki
  • 5
  • 5
  • 3
1 Solution
 
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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) :)
0
 
Jan SpringerCommented:
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.
0
 
cawasakiAuthor Commented:
hello Jan,

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

thanks
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Jan SpringerCommented:
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.
0
 
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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
0
 
Jan SpringerCommented:
Sure, until it dies.   Been there, done that.
0
 
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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
0
 
Jan SpringerCommented:
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.
0
 
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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.
0
 
Jan SpringerCommented:
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.
0
 
Daniel McAllisterPresident, IT4SOHO, LLCCommented:
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
0
 
cawasakiAuthor Commented:
hello,

thanks for help, i have found the solution with fstab

i have put user, and the correct code is username
//192.168.1.1/NAS_share /media/share cifs auto,username=toto,password=toto,domain=contoso.com,default 0 0

Open in new window

0
 
cawasakiAuthor Commented:
my solution work
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now