profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Thursday, August 6, 2015

The saga of me, fedora gnu/linux 22 and automount of NFS

I have been trying to figure this stuff out from quite some time now. No thanks to all the headache and it did not work many a times.
I wanted to just document it here (even if it is a failure so that others don't have to do it.
I added the nfs mount commands to the fstab but I would never do that again. If these drives for some reason fail to mount during boot then your system will not boot. What a bummer. The boot screen was also cheating me with a wrong and unrelated error (in regards to the boot) about the nouveau driver (for nvidia gtx 980). After asking the all knowing google the grandpa i got some clues and more jitters.
I decided not to mount them during boot (so that atleast i will have a bootable OS) and mount them somehow after loging in and for this I surrendered myself to the autostart application of the gnu/linux OS. I created a shell script with containing the working commands to mount the nfs shares from my netgear nas.
something like this


mount -t cifs -o username=meow,password=roar //nas/Music /mnt/nfs/nas_music
and rebooted the system. This of course didn't help because only root can run the mount command. What a bummer.
Then I added sudo in front of the line, saved it and rebooted it but no go.
Then after bothering google grandpa for a while i did (to edit the sudo)
visudo
added the following 2 lines

##nfs mount script 
meow  ALL=(ALL:ALL) NOPASSWD: /pathtoscript/myscript.sh

but then again i was out of luck here too.
I ran the command from the script in the shell and sure enough it asked for the password. I thought that was the problem so i did.


echo roar | sudo -S mount -t cifs -o username=meow,password=roar //nas/Music /mnt/nfs/nas_music
7/8/2015
so i added the path to the myscript.sh in the .bash_profileHope it all goes well. Let's see. I am adament to find a permanent alternative to how this is done by everyone else and so far it isn't going great.
So the good news is here. It is finally working. I am going to summarize my way of doing nfs automount to your gnu/linux OS boxes which safe, will never obstruct your booting of the gnu/linux OS, safe and sound, works every time.

So here we go
  1. create a myscript.sh and place it somewhere in the directory where all users have access it. I suggest /opt/
  2. manually via shell mount a share or two and check which commands are working for you without a problem to mount the nfs shares; make a note of that syntax or the command
  3. add the following lines in front of that above working nfs mount commands
    echo $mypassword | sudo -S
    here $myassword is a variable which is the user's login password and yes in my case the user was me and i am part of the administrator group. The above command will make sure that when you mount the nfs share it provides the credentials to proceed.
  4. Now enter this command into the myscript.sh and save it, make it editable by root only and accessible, executible by the user, in my case me. Make the file owned by root and group root:
    sudo chown root.root myscript.sh
    Now set the sticky but, make it executable for all and writable only by root:
    sudo chmod 4755 myscript.sh
  5.  find the .bash_profile which is the user profile on fedora 22 and it can be different on your particular gnu/linux distro. open it with your editor (nano or vi) and add the path to the script at the end of it and save it like this
    /pathtoscript/myscript.sh

    That is it....

No comments:

Post a Comment