Mounting an NFS directory in /etc/fstab

Issues related to applications and software problems
DK907
Posts: 71
Joined: 2011/11/21 16:32:49

Mounting an NFS directory in /etc/fstab

Post by DK907 » 2011/12/02 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

[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.]

DK907
Posts: 71
Joined: 2011/11/21 16:32:49

Re: Mounting an NFS directory in /etc/fstab

Post by DK907 » 2011/12/03 16:47:31

chkconfig nfs on was activated before I started this thread.

User avatar
toracat
Site Admin
Posts: 7518
Joined: 2006/09/03 16:37:24
Location: California, US
Contact:

Mounting an NFS directory in /etc/fstab

Post by toracat » 2011/12/03 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?

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Mounting an NFS directory in /etc/fstab

Post by TrevorH » 2011/12/03 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.

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: Mounting an NFS directory in /etc/fstab

Post by pschaff » 2011/12/03 20:52:46

What happens if you omit the [b]timeo[/b] or [b]udp[/b] options?

DK907
Posts: 71
Joined: 2011/11/21 16:32:49

Re: Mounting an NFS directory in /etc/fstab

Post by DK907 » 2011/12/03 21:24:00

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]

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: Mounting an NFS directory in /etc/fstab

Post by pschaff » 2011/12/03 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 [b]server[/b] and not on the [b]client[/b].

DK907
Posts: 71
Joined: 2011/11/21 16:32:49

Re: Mounting an NFS directory in /etc/fstab

Post by DK907 » 2011/12/03 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 [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.

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: Mounting an NFS directory in /etc/fstab

Post by pschaff » 2011/12/03 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.

DK907
Posts: 71
Joined: 2011/11/21 16:32:49

Re: Mounting an NFS directory in /etc/fstab

Post by DK907 » 2011/12/04 00: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.[/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.

Post Reply