<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gettin' My Geek On &#187; nfs</title>
	<atom:link href="http://www.markstevens20.net/blog/tag/nfs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markstevens20.net/blog</link>
	<description>Ramblings on my experiments with Linux, networking, and collaboration aps</description>
	<lastBuildDate>Sat, 30 Jan 2010 01:23:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>NFSv4 Configuration</title>
		<link>http://www.markstevens20.net/blog/2009/09/nfsv4-configuration/</link>
		<comments>http://www.markstevens20.net/blog/2009/09/nfsv4-configuration/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 01:35:35 +0000</pubDate>
		<dc:creator>Mark Stevens</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[virtualization]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[HomeNetworking]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nfs]]></category>
		<category><![CDATA[storage]]></category>

		<guid isPermaLink="false">http://www.markstevens20.net/blog/?p=278</guid>
		<description><![CDATA[Having figured out Samba shares, I thought I would tackle remote file systems between Linux machines using NFS (Network File Service). The documentation looked clear enough, but it wasn&#8217;t quit as easy as I expected, largely due to the differences between version 3 and 4 of NFS with respect to: firewall behavior exporting file system [...]]]></description>
			<content:encoded><![CDATA[<p>Having figured out <a href="http://www.markstevens20.net/blog/2009/06/linux-windows-xp-home-networking/" target="_blank" title="my Samba config blog post">Samba shares</a>, I thought I would tackle remote file systems between Linux machines using NFS (Network File Service).  The <a href="http://www.centos.org/docs/5/html/5.2/Deployment_Guide/ch-nfs.html" target="_blank" title="Centos.org doc for NFS">documentation</a> looked clear enough, but it wasn&#8217;t quit as easy as I expected, largely due to the differences between version 3 and 4 of NFS with respect to:</p>
<ul>
<li>firewall behavior</li>
<li>exporting file system syntax and use of pseudo file systems</li>
<li>difference in mount command syntax</li>
</ul>
<p>I am running systems that use SELinux and <a href="#footnote" title="link to blog footnote">firewalls*</a>.  I have one Centos 5.3 NFS server and three client machines running as <a href="#footnote" title="link to blog footnote">virtual machines**</a> on the server.  My goal was to establish remote file systems for the virtual machine clients. I&#8217;ll skip some of the introductory steps to set up the nfs server process that are listed in the <a href="http://www.centos.org/docs/5/html/5.2/Deployment_Guide/ch-nfs.html" target="_blank" title="Centos.org doc for NFS">doc</a>.</p>
<p>I&#8217;ll list the commands that I used to export the file system from the server and the mount command I first used on the client.  The file system that I was attempting to export was /junk/client1.  On the server (server.stevens.net), I added the following to /etc/exports:</p>
<div class="code">
[root@sserver ~]# <b>vi /etc/exports</b><br />
<b>/junk/client1  client1.stevens.net(rw)</b> <i>(:wq!)</i><br />
[root@sserver /]# <b>exportfs -rv</b><br />
[root@sserver /]# exportfs -rv<br />
exporting client1.stevens.net:/junk/client1<br />
[root@sserver /]# service nfs restart<br />
Shutting down NFS mountd:                                  [  OK  ]<br />
Shutting down NFS daemon:                                  [  OK  ]<br />
Shutting down NFS quotas:                                  [  OK  ]<br />
Shutting down NFS services:                                [  OK  ]<br />
Starting NFS services:                                     [  OK  ]<br />
Starting NFS quotas:                                       [  OK  ]<br />
Starting NFS daemon:                                       [  OK  ]<br />
Starting NFS mountd:                                       [  OK  ]
</div>
<p>and I used the following mount command on client1.stevens.net (and received the error shown):</p>
<div class="code">
[root@client1 ~]# <b>mount -t nfs4 sserver.stevens.net:/junk/client1 /remotesys</b><br />
mount.nfs4: sserver.stevens.net:/junk/client1 failed, reason given by server: No<br />
such file or directory.
</div>
<p>A bit surprised that it didn&#8217;t work, I poked around the Internet and I found some good info that ultimately helped me get on the right track at <a href="http://www.brennan.id.au/19-Network_File_System.html#nfs4" target="_blank" title="http://www.brennan.id.au/index.html"> Miles Brennan&#8217;s Linux Home Server HOWTO page</a>. He does an excellent job explaining the pseudo file system configuration required for version 4 of NFS.</p>
<p>I built out the following psuedo file system on the server:</p>
<div class="code">
[root@sserver /]# <b>mkdir NFS4exports</b><br />
[root@sserver /]# <b>cd NFS4exports</b><br />
[root@sserver NFS4exports]# <b>mkdir client1</b><br />
[root@sserver NFS4exports]# <b>mkdir client2</b>
</div>
<p>I then created bindings in /etc/fstab between /NFS4exports and /junk directories as follows (Bindings are like symbolic links, but the files are available in both filesystems, rather than being linked to the source location.):</p>
<div class="code">
[root@sserver /]# <b>vi /etc/fstab</b><br />
<b>/junk/client1            /NFS4exports/client1    none    bind         0 0<br />
/junk/client2            /NFS4exports/client2    none    bind         0 0</b><br />
[root@sserver /]# <b>mount -a -t none</b><br />
[root@sserver /]# <b>cd /NFS4exports/client1</b><br />
[root@sserver client1]# <b>ls -ltr</b> <i> This actually displays the files &#038; directories in the /junk/client1/ directory. </i><br />
total 24<br />
drwxrwxrwx 2 root root 4096 Sep  7 13:38 backup<br />
drwxrwxrwx 2 root root 4096 Sep  7 13:38 filestore<br />
-rwxrwxrwx 1 root root   39 Sep  7 13:41 client1.txt
</div>
<p>Then I list the pseudo file systems in the /etc/exports file, and it is critical to note that the fsid=0 option be defined on the /NFS4exports file system (even though /NFS4exports itself will not be mounted by a remote client).  Then all exported file systems are sub-directories of this system.  If I had additional file systems elsewhere on the server that I wanted to share (say, /home), I would need to create an entry in the pseudo file system and bind it to /home in fstab.</p>
<div class="code">
[root@sserver client1]# <b>vi /etc/exports<br />
/NFS4exports *.stevens.net(ro,fsid=0)<br />
/NFS4exports/client1 client1.stevens.net(rw,nohide)</b><br />
<b>/NFS4exports/client2 client2.stevens.net(rw,nohide)</b><br />
<i>then export with <b>exportfs -rv</b> and restart nfs</i>
</div>
<p>Then I mounted the file systems from the client1 system.  A major difference between the NFSv3 and NFSv4 command is that the root pseudo filesystem is <b>not</b> included in the identity of the remote file system (i.e., the NFS4exports directory is omitted from the command.</p>
<div class="code">
[root@client1 /]# <b>mount -t nfs4 sserver.stevens.net:/client1 /remotesys</b><br />
[root@client1 /]# <b>ls -ltr /remotesys</b><br />
total 24<br />
drwxrwxrwx 2 root root 4096 Sep 7 13:38 backup<br />
drwxrwxrwx 2 root root 4096 Sep 7 13:38 filestore<br />
-rwxrwxrwx 1 root root 39 Sep 7 13:41 client1.txt
</div>
<p>And on client2, showing an example that it can mount the client1 directory, but can&#8217;t see anything or write to it:</p>
<div class="code">
[root@client2 /]# <b>mount -t nfs4 sserver.stevens.net:/client1 /remotesys</b><br />
[root@client2 /]# <b> cd /remotesys</b><br />
[root@client2 remotesys]# <b>ls</b><br />
[root@client2 remotesys]# <b>mkdir test</b><br />
mkdir: cannot create director &#8216;test&#8217;: Read-only file system<br />
[root@client2 remotesys]# <b>cd..</b><br />
root@client2 /]# <b>umount /remotesys</b><br />
[root@client2 /]# <b>mount -t nfs4 sserver.stevens.net:/client2/remotesys</b><br />
[root@client2 /]# <b> cd /remotesys</b><br />
[root@client2 remotesys]# <b>ls -ltr</b><br />
total 24<br />
drwxrwxrwx 2 root root 4096 Sep 7 13:38 backup<br />
drwxrwxrwx 2 root root 4096 Sep 7 13:38 filestore<br />
-rwxrwxrwx 1 root root 39 Sep 7 13:41 client2.txt
</div>
<p>And that completed my setup (except to modify /etc/fstab so that the new /remotesys file system will automount at boot).  The main point was to learn about NFS, but I also ended up with a way to provide storage for my virtual machines outside of the .vmdk virtual file system.<br />
<a name="footnote" id="footnote"></a><br />
<i><br />
Footnotes:<br />
* NFSv4 plays better with firewall because, unlike NFSv3, it does not make use of portmapper and rpc.mountd, rpc.statd, and rpc.lockd. I just had to open port 2049 on the firewall for NFS. However, during some troubleshooting, I needed to execute &#8220;showmount -e sserver.stevens.net&#8217; from a client machine.  The firewall blocked it, because it uses rpc.mountd and portmapper picks a random port by default.  I used /etc/sysconfig/nfs to define a static port for rpc.mountd and then opened this port on the firewall too.<br />
**  As a side note with respect to the virtualization setup, I created one vm and installed a small, simple Centos image.  Then I copied the files twice to new folders in /var/lib/vmware/VirtualMachines. Then I imported these virtual machines into VMware Server to quickly make some clones.  Just a quick edit of the /etc/sysconfig/network file to update each machine to a unique hostname, and I had 3 distinct client machines.</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.markstevens20.net/blog/2009/09/nfsv4-configuration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
