Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (2024)

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (1)

  • February 19, 2022

Configuring autofs in Linux is a straightforward task. This article will guide you through the process of setting up and enabling the autofs service.

Table of Contents

Introduction

As part of this process, we will discuss the difference between static and dynamic mount points and use a previous article “Create and Export an NFS server in Linux” as a reference and for demonstrative purposes.

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (2)

Pre-Installation Checks

This tutorial assumes you have a RHEL7 or CentOS7 machine running with root or sudo privileges to become root. Also, it helps to already have an NFS server and client setup with perhaps one or two exported shares.

Checklist items

Ensure that you have the following setup (below) before proceeding to the autofs configuration section.

    1. Check if the nfs-utils package is installed on both the NFS server and client instances: rpm -qa | grep nfs-utils . If nfs-utils is not installed, run the following command to install it: yum -y install nfs-utils

    2. Check if the nfs.service is started and enabled to autostart on reboot (only on the server instance, not required for the client instance): sudo systemctl status nfs.service to check if NFS service is running. If not, run the following to start it: sudo systemctl start nfs.service. The following command will ensure the NFS service is enabled to autostart on reboot: sudo systemctl enable nfs.service

    3. Check if the right ports are allowed for NFS on your local firewall (firewalld): sudo firewall-cmd --list-all if not, run the following commands (below) to allow the right firewall ports for NFS.
$ sudo firewall-cmd --permanent --add-service=rpc-bind$ sudo firewall-cmd --permanent --add-service=mountd$ sudo firewall-cmd --permanent --add-service=nfs$ sudo firewall-cmd --permanent --add-port=2049/tcp$ sudo firewall-cmd --permanent --add-port=2049/udp$ sudo firewall-cmd --reload

If you’re having difficulties with any of the instructions on the checklist (above), revisit the “Create and Export an NFS server in Linux” article for further detailed assistance.

Static vs. Dynamic NFS mounts

Simply put, static NFS shares (as the term suggests) are always available. Typically, entries are made in the /etc/fstab file to ensure the NFS share is mounted automatically after rebooting a machine. However, this is not considered best practice if bandwidth conservation and optimum performance are your organizational goals.

This is why dynamic NFS mounts are the industry standard. It allows NFS shares to be mounted automatically on an as-needed basis. The mount point or NFS share expires after a set period of time of not being accessed. This not only conserves bandwidth, it also improves overall performance when compared to static NFS mounts.

Setting Up AutoFS Mounts

We are now ready to proceed with the autofs configuration. We will begin with the server-side and end with the client-side instance.

Server-side configuration

SSH into your server instance. VM1 is our server instance for this demonstration. Then, less or cat the contents of the /etc/exports file (shown in the image below). This is where we expect to find the NFS shares currently being exported to our client instance.

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (3)

As you can see (above) the /nfs_share mount is being exported from this server instance to the client instance. For this demonstration, we will create a new share called /nfs_auto_share and export that share to the client instance.

Creating an NFS share using SSM

We will use the SSM utility to create our new nfs share. The new logical volume called lv_nfs_auto_share will be 10GB in size. Run the following command (below):

[admin@vm1 ~]$ sudo ssm create -s 10GB -n lv_nfs_auto_share --fstype xfs -p vg00 /dev/vda2 /nfs_auto_share[sudo] password for admin: Logical volume "lv_nfs_auto_share" created. Logical volume "lv_nfs_auto_share" created.meta-data=/dev/vg00/lv_nfs_auto_share isize=512 agcount=4, agsize=655360 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0data = bsize=4096 blocks=2621440, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0Directory '/nfs_auto_share' does not exist! Create (Y/n/q) ? Y

In the image shown below, we can see the output of the df command and verify that our new share has been mounted. Next, we will ensure the /nfs_auto_share mount point persists on our server instance.

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (4)

Photo by admingeek from Infotechys

Using your preferred text editor, open the /etc/fstab file and add the following entry (circled in the image below) to the file. Then, save and exit the file.

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (5)

Photo by admingeek from Infotechys

Finally, we will complete the server-side configuration, by once again opening the /etc/exports file and adding the share as a new entry to the file.

[admin@vm1 ~]$ cat /etc/exports/nfs_auto_share 192.168.1.197(rw,sync)

Finally, we will export the new share to our client instance.

[admin@vm1 ~]$ sudo exportfs -va[sudo] password for admin:exporting 192.168.1.197:/nfs_auto_share

Client-side configuration

SSH into your client instance. VM2 is our client instance for this demonstration. In the image below, the output of the df command shows our static mount point /nfs_share and does not yet show the /nfs_auto_share mount we’ve just exported. The /nfs_share is static because it has an entry in our /etc/fstab file and remains persistent and visible even though we currently have no use for it.

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (6)

Photo by admingeek from Infotechys

Now let’s configure AutoFS on our client instance to enable the /nfs_auto_share.

Pre-configuration Checklist

Before we begin, let’s ensure the AutoFS service is installed, enabled, and running on our client instance.

Starting and Enabling AutoFS

First, let’s run the following command (below) to check if the AutoFS service is running on our machine. If AutoFS is not installed, simply install it using yum: sudo yum -y install autofs

[admin@vm2 ~]$ sudo systemctl status autofs● autofs.service - Automounts filesystems on demandLoaded: loaded (/usr/lib/systemd/system/autofs.service; disabled; vendor preset: disabled)Active: inactive (dead)

As you can see, AutoFS is not running on our machine and we need to start it. While we’re at it, let’s enable it as well so it persists on our machine. We can use the semi-colon ; or double ampersand && to run multiple commands at once on the command-line (CLI).

[admin@vm2 ~]$ sudo systemctl start autofs ; sudo systemctl enable autofs

Now that AutoFS is running and enabled on our client instance, we can proceed to the next step and begin the configuration process to automount the /nfs_auto_share filesystem.

[admin@vm2 ~]$ sudo systemctl status autofs● autofs.service - Automounts filesystems on demandLoaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled)Active: active (running) since Mon 2022-02-21 13:26:56 EST; 4s agoMain PID: 2725 (automount)CGroup: /system.slice/autofs.service└─2725 /usr/sbin/automount --systemd-service --dont-check-daemonFeb 21 13:26:56 vm2.dev.infotechys.com systemd[1]: Starting Automounts filesystems on demand...Feb 21 13:26:56 vm2.dev.infotechys.com systemd[1]: Started Automounts filesystems on demand.

Automount the NFS share

We are going to create two separate files as part of this procedure. One file (nfs_auto_share.autofs) will reside under the /etc/auto.master.d/ sub-directory and the other file (auto.nfs_auto_share) will reside under /etc.

Using your preferred text editor, cd into /etc/auto.master.d and create a file called nfs_auto_share.autofs.

Add the following entry (below) to the file. Then, save and exit the file.

/- /etc/auto.nfs_auto_share
The entry (above) points the AutoFS service to the location of the file (/etc/auto.nfs_auto_share) where the parameters of the /nfs_auto_share filesystem or mount point is defined.

Next, cd into /etc and create a file called auto.nfs_auto_share. Add the following entry (below) to that file.

/nfs_auto_share -rw,intr 192.168.1.196:/nfs_auto_share

The entry (above) defines the new share (nfs_auto_share) we want dynamically mounted on our client machine. We’ve also specified that we want it mounted with read and write (rw) permissions from our NFS server instance (NFS Server IP Address is 192.168.1.196). The interrupt (intr) mount option is a default setting and is used when we do not expect to damage critical data by manually interrupting an NFS request.

Finally, restart the AutoFS service so it can read the newly added configuration files.

[admin@vm2 etc]$ sudo systemctl restart autofs && sudo systemctl status autofs● autofs.service - Automounts filesystems on demandLoaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled)Active: active (running) since Mon 2022-02-21 14:15:25 EST; 3s agoMain PID: 2882 (automount)CGroup: /system.slice/autofs.service└─2882 /usr/sbin/automount --systemd-service --dont-check-daemonFeb 21 14:15:25 vm2.dev.infotechys.com systemd[1]: Starting Automounts filesystems on demand...Feb 21 14:15:25 vm2.dev.infotechys.com systemd[1]: Started Automounts filesystems on demand.

Verifying or Testing the NFS share

You’ll notice that even after restarting the AutoFS service, the new /nfs_auto_share is still not visible (shown in the image below).

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (7)

Photo by admingeek from Infotechys

This is to be expected as we are not currently using the share. However, we can verify that it exists by listing it: ls -l /nfs_auto_share . We can also cd into it and create a test file: touch test1.txt. Executing any one of these options will activate the /nfs_auto_share and make it visible using the df command (shown in the image below).

NOTE: If you cannot create a file under /nfs_auto_share, it is because of your ownership/permission settings. SSH into your server instance and change the permission setting using the following command (below). This will allow world read, write, and execute permissions on /nfs_auto_share.

[admin@vm1 ~]$ sudo chmod -R 1777 /nfs_auto_share

Now, a listing of the /nfs_auto_share directory shows its contents (below).

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (8)

Photo by admingeek from Infotechys

Conclusion

Congratulations! You’ve successfully completed AutoFS configuration on your Linux machine. As part of this tutorial, we reviewed the difference between static and dynamic NFS mounts and configured AutoFS to mount a new share–created and exported from our NFS server instance.

Was this article helpful to you? If so, let us know in the comment section below. We’d love to hear from you!

Related Posts

Commands

Introducing The System Storage Manager (SSM)

Table of Contents IntroductionRedhat recently introduced the System Storage Manager (SSM), a unified user interface that allows uses to manage complicated systems in a simple

Read More »

Commands

Installing and Using Git on Linux Machines

In this article, we will review installing and using Git on Linux machines. Besides minor differences in syntax, the install commands and procedures are similar

Read More »

Commands

Create and Export an NFS Server in Linux

NFS or Network File System is a commonly known method for network file sharing on Linux hosts. We will create and export an NFS server.

Read More »

Tags

Algorithms (2)Ansible (17)Apache (7)Artificial Intelligence (7)Automation (27)Big Data (3)Blockchain (4)CentOS (128)CI/CD (3)Cloud Computing (3)co*ckpit (3)Containers (7)Database (4)Debian (30)DevOps (5)Docker (10)Fedora (9)Git (3)HAProxy (3)HOWTO (180)Information Technology (3)Install (86)Jenkins (5)Kali Linux (4)Kubernetes (16)KVM (5)LAMP (4)Linux (206)Linux commands (109)Minikube (5)mysql (6)nmcli (4)Podman (10)Python (8)RHCSA Exam (10)RHEL (147)SSH (3)sysadmin (2)Technology (11)Text Editor (8)Ubuntu (43)Upgrade (4)vim (2)Virtualization (4)Webserver (2)

Setting up AutoFS in Linux on RHEL7 or CentOS7 - Infotechys.com (2024)
Top Articles
Institutional Biosafety Committee Member Training
Forbes’ 2024 Highest-Paid Athletes List Has No Women — Why Change Is Coming
3 Tick Granite Osrs
13 Easy Ways to Get Level 99 in Every Skill on RuneScape (F2P)
Sandrail Options and Accessories
Lifebridge Healthstream
Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
Craigslist Motorcycles Jacksonville Florida
The Pope's Exorcist Showtimes Near Cinemark Hollywood Movies 20
Craigslist Vermillion South Dakota
Https Www E Access Att Com Myworklife
Miami Valley Hospital Central Scheduling
Saw X | Rotten Tomatoes
How to Store Boiled Sweets
History of Osceola County
Trac Cbna
Spergo Net Worth 2022
Willam Belli's Husband
Roll Out Gutter Extensions Lowe's
Trivago Sf
20 Different Cat Sounds and What They Mean
Program Logistics and Property Manager - Baghdad, Iraq
Munis Self Service Brockton
Rapv Springfield Ma
Busted Mugshots Paducah Ky
Culver's.comsummerofsmiles
Will there be a The Tower season 4? Latest news and speculation
Calvin Coolidge: Life in Brief | Miller Center
Courtney Roberson Rob Dyrdek
Swimgs Yuzzle Wuzzle Yups Wits Sadie Plant Tune 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Autumns Cow Dog Pig Tim Cook’s Birthday Buff Work It Out Wombats Pineview Playtime Chronicles Day Of The Dead The Alpha Baa Baa Twinkle
Scat Ladyboy
Basil Martusevich
Culver's Hartland Flavor Of The Day
Metra Union Pacific West Schedule
Tra.mypatients Folio
El agente nocturno, actores y personajes: quién es quién en la serie de Netflix The Night Agent | MAG | EL COMERCIO PERÚ
Unlock The Secrets Of "Skip The Game" Greensboro North Carolina
Unity Webgl Player Drift Hunters
Empires And Puzzles Dark Chest
Fifty Shades Of Gray 123Movies
2132815089
Acts 16 Nkjv
Booknet.com Contract Marriage 2
Big Reactors Best Coolant
Truck Works Dothan Alabama
What is 'Breaking Bad' star Aaron Paul's Net Worth?
15 Best Places to Visit in the Northeast During Summer
Wzzm Weather Forecast
M Life Insider
Craigslist Charlestown Indiana
Obituaries in Westchester, NY | The Journal News
Códigos SWIFT/BIC para bancos de USA
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 6347

Rating: 5 / 5 (60 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.