NFS exports and mountpoints
I’ve had some weird behavior recently with my NFS exports on my server, and I think having figured out what was going on, I should blog about it, as it took me a while to work out why.
My server uses NFS to export some of it’s directories, most importantly is this line in the /etc/exports
/data *(rw,async,no_root_squash,no_subtree_check)
I thought that this would export all my directories in /data, which it kind of does, but it doesn’t really do in the way I thought it would.
On my server, an ls in /data lets me know there are 4 directories, apps, downloads, mp3 and tv. When I look on my client at /net/media/data I see 4 directories, apps, downloads, mp3 and tv.
But inside the downloads directory there are a whole bunch of files and directories on the server. But on the client the downloads directory is empty.
Why would that be? Why would a directory be populated on my server, but appear empty when browsing via nfs, it just doesn’t make sense. But then I discovered this…
mib@media:~$ mount
/dev/mapper/data-home on /home type ext3 (rw)
/dev/mapper/data-mp3 on /data/mp3 type ext3 (rw)
/dev/mapper/data-download on /data/downloads type ext3 (rw)
securityfs on /sys/kernel/security type securityfs (rw)
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
“What special about your mount paths?” I hear you cry
Well notice that /dev/mapper/data-download (an LVM volume) is mounted on /data/downloads, it looks like NFS only accesses the single filesystem that is mounted on teh directory accessed, and does not cross mount points that way the local filesystem does.
So /data is on the volume /, and has a downloads subdirectory, but that downloads subdirectory is a target for a mountpoint, and NFS does see the mounted data, only the target directory.
So how can I solve it? The answer it turns out is simple, add the line /data/downloads to the exports file, execute exportfs -a, and restart autofs on my client (it caches) and it all started working. I’m sure there is a perfectly sensible reason for NFS working that way, but I couldn’t find anything obivous in the docs warning me about it and I’ve been scratching my head for a week now trying to work it out.
I hope if anyone else has this problem that this post helps.