Wondering how to perform autofs automount NFS? Our in-house experts are here to help you out with this article. Our NFS support is here to offer a lending hand with your queries and issues.
Autofs automount NFS
NFS is a great way to mount remote drives across a network and treat them like local drives on a local Linux system.
With a 10 gigabit Ethernet connection and remote SSD or NVMe storage, remote drives can be every bit as speedy and zippy as local SSD or NVMe storage.
This is an excellent way to create centralized network storage for multiple Linux clients.
One little downside to NFS involves auto-mounting the remote shares using /etc/fstab.
If the server is online, everything is good, but if there is no network connection, client boot time increases as Linux times out while attempting to mount a nonexistent remote share.
Today, let us see the steps followed by our support techs for the Autofs installation
Summary of Installation
Step 1. Install autofs on the client, not the server.
sudo apt install autofs
Step 2. Edit auto.master for direct mapping
/- /etc/auto.misc
Step 3. Edit auto.misc
/nfs/myshare -fstype=nfs4,rw 192.168.100.10:/media/myshare
The exact paths and address will depend upon your network and NFS server.
Step 4. Restart autofs to apply the changes
sudo service autofs restart
Installation
autofs is available for free from the Ubuntu repository.
sudo apt install autofs
This will add an empty directory, auto.master.d, and five files in /etc.
autofs has its own man page for more details about operation.
man autofs
/etc/auto.master and Direct Mapping
Open this file as root in a text editor.
sudo xed /etc/auto.master
Add this line to the end of the file and save. Leave the existing contents of the file alone.
/- /etc/auto.misc
auto.master is the main file autofs will check in order to mount an NFS share. Optionally, we can use custom files in auto.master.d, but this is not necessary and requires extra setup.
autofs uses entries found in two files in order to mount a single share. Yes, this is confusing and more complicated than it needs to be, so it is easy to make mistakes somewhere and wonder why NFS shares are not mounting. Take your time and double check.
An entry in auto.master tells autofs where to find a map file. A map file maps remote shares to local mount points. In the example above, we are using the existing file auto.misc as the map file.
An auto.master entry consists of three parts:
<mount_point> <map_file> <options>
mount_point
We are using a special notation consisting of a forward slash followed by a hyphen.
/-
This denotes direct mapping where auto.misc will specify the mount point details. Another way is to specify indirect mapping using a mount point as an absolute path and all remote shares will be mounted under it as a virtual directory structure, but I could never get this to work. We will use direct mapping.
map_file
This is the path to another file that contains the mapping/mounting details. Use the absolute path to the file. We are using /etc/auto.misc. auto.misc is the map file in this case.
options
Additional options for the mount go here. We do not need to specify any options for this example, so this is left blank.
/etc/auto.misc
Since we specified auto.misc as the map file in auto.master, this is the file we need to edit. We can use almost any text file in place of auto.misc as long as we specify the absolute path in auto.master, but we will reuse auto.misc for convenience because it already exists.
Open /etc/auto.misc in a text editor as root.
sudo xed /etc/auto.misc
The NFS server should already be set up and configured for sharing.
Add an entry to auto.misc like this:
/media/myshare -fstype=nfs4,rw 192.168.100.10:/media/nfs_share_on_server
We are using NFSv4 on the server, so we can specify nfs4 for the filesystem type. Your exact mounting details will depend upon your system.
- /media/myshare – This is the mount point on the local Linux computer. There no need to create this directory in advance. Name it whatever you want. Placing it in /media causes Nemo file manager to automatically display it in its sidebar, but this can lead to duplicate listings.
- -fstype=nsf4,rw – The server is using NFSv4, so we specify nfs4 here. If using NFSv3 or NFSv2, use nfs. The rw means mount with read/write access.
- 192.168.100.10 – This is the NFS server’s IP address. A domain name is also allowed. In this case, the NFS server exists on a private LAN, isolated from the Internet, so security is not an issue.
- :/media/nfs_share_on_server – This is an absolute path of the share on the NFS server. This must be set up in advance on the NFS server, which we assume is up and running here. Make sure to separate the IP address from the path using a colon (:).
Save the file, and restart autofs to see what happens. Make sure that /etc/fstab does not contain any entries that mount the same NFS share since /etc/fstab is not needed for NFS if using autofs.
sudo service autofs restart
The NFS share will be available in Nemo in the sidebar. Just select the share to access its contents.
[Looking for a solution to another query? We’re happy to help.]
Conclusion
In this article, we provide a quick and simple solution from our Support team to perform Autofs automount NFS
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments