Page 1 of 2

Mounting an NFS directory in /etc/fstab

Posted: 2011/12/02 21:04:10
by DK907
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

[code]
david.example.com:/shares /mnt/nfs nfs rsize=8192,wsize=8192,timeo=14,intr,udp 0 0
[/code]
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

[code]
-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
[/code]
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 [i]code[/i] tags to aid legibility.]

Re: Mounting an NFS directory in /etc/fstab

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

Mounting an NFS directory in /etc/fstab

Posted: 2011/12/03 19:05:13
by toracat
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: 2011/12/03 19:20:02
by TrevorH
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: 2011/12/03 20:52:46
by pschaff
What happens if you omit the [b]timeo[/b] or [b]udp[/b] options?

Re: Mounting an NFS directory in /etc/fstab

Posted: 2011/12/03 21:24:00
by DK907
I tried all of your suggestions and it still does not work. I edited /etc/exports and added
[code]
/shares 192.168.1.0/24(rw,sync)
[/code]
I edited /etc/fstab and added
[code]
192.168.1.100:/shares /mnt/nfs nfs _netdev,rsize=8192,wsize=8192,intr 0 0
[/code]

Re: Mounting an NFS directory in /etc/fstab

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

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

Re: Mounting an NFS directory in /etc/fstab

Posted: 2011/12/03 21:41:46
by DK907
[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 [b]server[/b] and not on the [b]client[/b].[/quote]

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: 2011/12/03 21:52:39
by pschaff
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: 2011/12/04 00:30:25
by DK907
[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.[/quote]
Thank you, that worked. I added
[code]
mount.nfs david.example.com:/shares /mnt/nfs
[/code]
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.