In This tutorial we will show you How to automatically mount/unmount a SMB/CIFS Windows share on a CentOS/Fedora/RHEL server. In this article we will mount the NFS share using autofs. NFS share ‘/dbbackup‘ is exported from Fedora NFS Server (192.168.1.21). We are going to mount this nfs share on CentOS 7 & Ubuntu Linux using autofs. Steps to mount nfs share using Autofs in CentOS 7 Step:1 Install autofs package. Overview of automounting NFS and CIFS shares Mounting CIFS and NFS shares using the mount command, won’t survive a reboot. Luckily there are three different ways to auto-mount CIFS and NFS shares when the machine boots up: Announcement I have released my new course on Udemy, Kubernetes By Example. Sign up now to get free.
I have already written an article to configure NFS server which you can go to using the below link
What is Autofs?
Autofs is used to automatically mount any filesystem on demand as and when you access them and not only it will mount automatically but it can automatically unmount any filesystem when not in used for a particular predefined timeout value.
Why should I use Autofs ?
Automatically Mount Network Drive Mac
I understand a question which generally pops up in people's mind that even putting nfs share entry in /etc/fstab makes it auto mountable so how does it differs from autofs? Well as I defined above autofs is not only/at all about mounting the share on every reboot.
Take a scenario where a nfs share is supposed to be mounted at boot but it is not accessibe due to some reasons which will lead to delayed startup or even there might be a case when your OS will not at all boot up.
Advantages of AutoFS
- Shares are accessed automatically and transparently when a user tries to access any files or directories under the designated mount point of the remote filesystem to be mounted.
- Booting time is significantly reduced because no mounting is done at boot time.
- Network access and efficiency are improved by reducing the number of permanently active mount points.
- Failed mount requests can be reduced by designating alternate servers as the source of a filesystem.
In this article I will show you the configuration steps for autofs using NFS share
Automounter 1 4 2 – Automatically Mount Network Shares Traded
We we have two servers namely nfsserver and nfsclient. Lets start configuring a NFS share on nfsserver
On nfsserver
Since this article is all about autofs I am not using much permission on the exports. These are two simple shares which I am sharing with nfsclient
Restart the nfs services or reload the shares
NOTE: Do not run this command on production environment if anyone is accessing any of the share as it will disrupt the traffic for few seconds.
Genreally we reload the nfs share using the below command
The above command reexport all directories, synchronizing /var/lib/nfs/etab with /etc/exports. This option removes entries in var/lib/nfs/etab which have been deleted from /etc/exports, and removes any entries from the kernel export table which are no longer valid.
To see all the shares and the applied permissions
Well our server side work is done lets roll over to nfsclient
Automounter 1 4 2 – Automatically Mount Network Shares Outstanding
NOTE: For this article I have disabled my iptables and selinux.
In case you want to use iptables insert the below rule into your INPUT chain
On nfsclient
This is the place where the magic will happen. But for that we will have to configure autofs.
This is the place where the magic will happen. But for that we will have to configure autofs.
auto.master file
The primary configuration file for the automounter is /etc/auto.master, also referred to as the master map. The master map lists autofs-controlled mount points on the system, and their corresponding configuration files or network sources known as automount maps. The format of the master map is as shown below
mount-point map-name options
For our case
For our case
Description
Using the above line we are giving the default mount point as /mnt and redirecting to different file i.e. auto.master file to look into /etc/auto.misc for further information about the shares and server details we want to mount on /mnt. And lastly we have provided and extra option providing a timeout value to unmount the share in case or any inactivity for 20seconds.
Description |
The autofs mount point, /mnt, for example. |
The name of a map source which contains a list of mount points, and the file system location from which those mount points should be mounted. |
If supplied, these will apply to all entries in the given map provided they don't themselves have options specified. This behavior is different from autofs version 4 where options were cumulative. This has been changed to implement mixed environment compatibility. |
auto.misc file
The general format of maps is similar to the master map, however the 'options' appear between the mount point and the location instead of at the end of the entry as in the master map:
mount-point [options] location
mount-point [options] location
Description |
This refers to the autofs mount point. This can be a single directory name for an indirect mount or the full path of the mount point for direct mounts. Each direct and indirect map entry key (mount-point above) may be followed by a space separated list of offset directories (sub directory names each beginning with a '/') making them what is known as a multi-mount entry. |
Whenever supplied, these are the mount options for the map entries that do not specify their own options. |
This refers to the file system location such as a local file system path (preceded with the Sun map format escape character ':' for map names beginning with '/'), an NFS file system or other valid file system location. |
Enough with the explanation next edit auto.misc file
Save and exit the file
![Automounter 1 4 2 – Automatically Mount Network Shares Automounter 1 4 2 – Automatically Mount Network Shares](https://www.pixeleyes.co.nz/automounter/support/images/ConfigurationAssistant.jpg)
Mac Os Automatically Mount Network Drive
Description
Here we have defined two different mount points 'deepak' and 'raid' for their respective shares. Now next time as soon as you try to access these shares using 'cd' command the shares will be automatically mounted and when you are done just come out of the share path and after 20 seconds the share would be unmounted. We have specified the filesystem type for both the shares along with the original share location on our NFS server.
Its time to reload our autofs services
Verify if autofs is running
Automounter 1 4 2 – Automatically Mount Network Shares Buy Or Sell
Reloading maps
Make sure the NFS shares are not already mounted
Make sure the NFS shares are not already mounted
So none of the NFS shares are mounted still lets try to access them
As you see the files under 'deepak' share on NFS server are accessible from the nfsclient just by doing 'cd' to the share
Similarly you can try to access another share i.e. 'raid'
![Automatically Automatically](https://i.stack.imgur.com/d8tQo.png)
Automounter 1 4 2 – Automatically Mount Network Shares Price
IMPORTANT NOTE : If you do not know the names of the share used under auto.misc then you won't be able to access the NFS shares as be defualt /mnt would be shown as empty. The shares are mounted only when you 'cd' into the share directory.
You can use the watch command to verify if the shares automatically gets unmounted.
After few seconds the mount point 'work' is automatically unmounted as you can see below
Postbox 6 0 12 download free. Related Articles: