Recently, I was doing some server setup works which involves NFS and Autofs. Of course, I ran into several problems. So I’d like to document it just in case.
Problem 1. Unable to mount exported shares via autofs
In NFS server’s /etc/exports
, I put the following:
/mnt/static/images 10.1.1.1/29(ro)
And in a client’s /etc/auto.master
and /etc/mnt.nfs
, I put
# /etc/auto.master
/mnt /etc/mnt.nfs
# /etc/mnt.nfs
images -fstype=nfs4,soft,timeo=10,ro,intr,retry=0 10.1.1.1:/mnt/static/images
So theoretically, I should be able to visit /mnt/images
on the client, but instead, I get the following error:
# ls /mnt/images
ls: cannot access /mnt/images: No such file or directory
What went wrong? I googled a lot and finally find an article in which it states that:
Note that with NFSv4, all exported directories must be part of a single hierarchy and that the root directory of that hierarchy must be exported and identified with the option fsid=0 or fsid=root.
With that information, I made my /etc/exports
to look like that and exportfs -ra
to apply the changes:
/mnt 10.1.1.1/29(ro)
/mnt/static/images 10.1.1.1/29(ro)
Then the autofs mount in client works. Although I’m not sure if it is the correct way to fix the issue, it can be used as a workaround.
Problem 2. autofs cause client to hang on startup when nfs server is down
By default, in /etc/autofs.conf
, there is a timeout
set to 5 minutes. That mean how long does the client to wait before declaring the nfs server is down.
So I first tried to set a shorter timeout
in /etc/auto.master
for my specific mount like this, but it didn’t work. My client still waits more than 5 minutes on startup.
# /etc/auto.master
/mnt /etc/mnt.nfs --timeout=10
Then, I found there is also some other options in man nfs
that might have something to do with the hang. So I changed my /etc/mnt.nfs
to look like this:
# /etc/mnt.nfs
images -fstype=nfs4,soft,timeo=10,ro,intr,retry=0 10.1.1.1:/mnt/static/images
Now my client almost doesn’t hang on startup.