Mounting an NFS directory in /etc/fstab

Posted by DK907 on 2011/12/2 21:04:10
I am studying for the RHCSA exam and I am trying to mount an NFS directory at boot.

I resolved my ip address to david.example.com in /etc/hosts and I entered /shares *.example.com(rw,sync) in /etc/exports and entered exportfs -a. I entered

david.example.com:/shares /mnt/nfs nfs rsize=8192,wsize=8192,timeo=14,intr,udp 0 0 

in /etc/fstab.

When I restart it takes longer than normal to boot up and when I check the boot messages it says mount.nfs connection timed out. When I enter mount -a it does mount /shares on /mnt/nfs.

I tried editing /etc/sysconfig/iptables and I added

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT

I did service iptables restart and it restarted without any problems but when I restart I still have the same problem.

Does anyone have any suggestions?.

[Moderator edited to insert code tags to aid legibility.]

Re: Mounting an NFS directory in /etc/fstab

Posted by DK907 on 2011/12/3 16:47:31
chkconfig nfs on was activated before I started this thread.

Re: Mounting an NFS directory in /etc/fstab

Posted by toracat on 2011/12/3 19:05:13
Just for testing purpose, can you use the IP address in /etc/fstab and see if it still fails to mount upon booting?

Re: Mounting an NFS directory in /etc/fstab

Posted by TrevorH on 2011/12/3 19:20:02
Include the "_netdev" option in the list of options. This tells the init scripts that the file system to be mounted resides on a network device and needs the network to be available before it can be mounted.

Re: Mounting an NFS directory in /etc/fstab

Posted by pschaff on 2011/12/3 20:52:46
What happens if you omit the timeo or udp options?

Re: Mounting an NFS directory in /etc/fstab

Posted by DK907 on 2011/12/3 21:24:00
I tried all of your suggestions and it still does not work. I edited /etc/exports and added
/shares 192.168.1.0/24(rw,sync)

I edited /etc/fstab and added
192.168.1.100:/shares /mnt/nfs nfs _netdev,rsize=8192,wsize=8192,intr 0 0 


Re: Mounting an NFS directory in /etc/fstab

Posted by pschaff on 2011/12/3 21:33:13
Are you saying that solved the problem? If so, you have a DNS issue.

The /etc/exports file is used on the NFS server and not on the client.

Re: Mounting an NFS directory in /etc/fstab

Posted by DK907 on 2011/12/3 21:41:46
Quote:

pschaff wrote:
Are you saying that solved the problem? If so, you have a DNS issue.

The /etc/exports file is used on the NFS server and not on the client.


No, I said it still does not work. I am just practicing for the RHCSA exam so my computer is both the server and the client. Entering mount -a works, so I do not understand why these directories are not mounting at boot. I do not think DNS was ever the problem because I resolved my IP address to david.example.com in /etc/hosts and I can ping david.example.com.

Re: Mounting an NFS directory in /etc/fstab

Posted by pschaff on 2011/12/3 21:52:39
Not a very realistic environment but I guess one has to make do with available resources. You could add the mount command in /etc/rc.d/rc.local that runs at the end of the boot.

Re: Mounting an NFS directory in /etc/fstab

Posted by DK907 on 2011/12/4 0:30:25
Quote:

pschaff wrote:
Not a very realistic environment but I guess one has to make do with available resources. You could add the mount command in /etc/rc.d/rc.local that runs at the end of the boot.

Thank you, that worked. I added
mount.nfs david.example.com:/shares /mnt/nfs

to /etc/rc.d/rc.local and it worked.
I am curious to know if it is theoretically possible to use NFS to mount a directory that is on the local host at boot using /etc/fstab. It is not important because it is the results that count.

Re: Mounting an NFS directory in /etc/fstab

Posted by TrevorH on 2011/12/4 0:38:08
I do remember doing this a few years ago and I had to amend the order of some of the start-up scripts. Looking at my CentOS 5 box which is the only one I use as an NFS server, in /etc/rc3.d I see that I have S25netfs and S60nfs which means that it will attempt to mount the NFS file systems before it has started the NFS daemons. The solution was to rename the start up script so that netfs ran after nfs.

Re: Mounting an NFS directory in /etc/fstab

Posted by DK907 on 2011/12/4 19:11:42
Quote:

TrevorH wrote:
I do remember doing this a few years ago and I had to amend the order of some of the start-up scripts. Looking at my CentOS 5 box which is the only one I use as an NFS server, in /etc/rc3.d I see that I have S25netfs and S60nfs which means that it will attempt to mount the NFS file systems before it has started the NFS daemons. The solution was to rename the start up script so that netfs ran after nfs.

In CentOS 6, /etc/rc3.d and /etc/rc5.d both contain S24nfslock, S25netfs and S30nfs. Why would Red Hat put these startup scripts in the wrong order?. This is such an obvious problem that I cannot believe it was done by accident. I experimented with this by renaming S25netfs to S32netfs and I commented the mount.nfs4 commands that I had put in /etc/rc.d/rc.local and I uncommented the mount the nfs entries in /etc/fstab. It worked. I am glad that I learned about this problem now so I will know how to fix it when I take the RHCSA exam.

Re: Mounting an NFS directory in /etc/fstab

Posted by pschaff on 2011/12/4 19:47:54
Using the same system as the server and client for NFS is quite unusual, and one might argue of doubtful value in the real world. I doubt it is a situation that would come up on the RHCSA exam, nor one that would be considered by Red Hat when determining the order in which to start services.

Re: Mounting an NFS directory in /etc/fstab

Posted by jlehtone on 2011/12/4 20:51:03
I think that the logic for startup order is clear.

Mounting foreign filesystems is probably initialization of important
resources to the use of the system. That can be important and
needed early on. There are even diskless clients that definitely
depend on mounting first.

NFS server on the other hand is a mere service that a fully
operational system provides to the other machines on the network.

Re: Mounting an NFS directory in /etc/fstab

Posted by DK907 on 2011/12/4 21:45:57
Quote:

pschaff wrote:
Using the same system as the server and client for NFS is quite unusual, and one might argue of doubtful value in the real world. I doubt it is a situation that would come up on the RHCSA exam, nor one that would be considered by Red Hat when determining the order in which to start services.

So if I shared a directory using NFS in /etc/exports and I used a different computer as a client then it would not be necessary to rename the startup scripts on the client?. In the RHCSA exam it will be possible to use virtualization to simulate a real client/server network on a single computer so I should start practicing on a computer that is capable of virtualization to get more realistic experience before I take the test.

Re: Mounting an NFS directory in /etc/fstab

Posted by TrevorH on 2011/12/5 0:32:26
Yes, the renaming of the startup scripts is only necessary when you use the same system as nfs client and server at the same time. In normal use it wouldn't be required. Virtualisation is the real solution to your problem.

This Post was from: https://www.centos.org/newbb/viewtopic.php?forum=56&topic_id=34540