Recently, I had the opportunity to learn how to configure NFS shares in Linux. During my exploration of NFS, I came across something that I thought was really interesting and I want to share with Enable Sysadmin readers. What caught my attention is autofs. Let's dig into what autofs is and how it works.

Autofs defined

Autofs is an automount daemon that manages mount points as needed. In short, it only mounts a given share when that share is being accessed and are unmounted after a defined period of inactivity. Automounting NFS shares in this way conserves bandwidth and offers better performance compared to static mounts controlled by /etc/fstab.

How does it work?

Like most things in Linux, autofs uses a configuration file as the framework for completing tasks. It consults a map file located at /etc/auto.master. The file defines various mount points. Each entry in this file has three fields that need to be set for the daemon to work correctly. These fields are:

  1. Mount point
  2. Location of map file
  3. Optional field (allows for the inclusion of options)

Practical example

Let's look at how to mount a directory on our machines. For this demonstration, let's mount directory /afstest on our remote machine client.example.com (172.25.1.4) to the mount point /test/nfs_share. To do this, add the following to the auto.master file:

/test                 /etc/auto.misc      --timeout 30

Once that is completed, add the following to our map file /etc/auto.misc:

autofstest   -rw,soft,intr,rsize=8192,wsize=8192 client.example.com:/afstest

Field one in the auto.misc file is the name of the subdirectory in /misc. The second field contains our mount options, such as read and write permissions and size restrictions. The third field is the location of the NFS export.

NOTE: These fields are different from the fields listed in the /etc/auto.master

Once we have all of our options set, we need to restart the autofs service. Use the following command:

# /sbin/service autofs restart

Once complete, verify the active mount points by using this command:

# /sbin/service autofs status

As with all configuration file changes, if the service is running when the change is made, you need to reload the file. You can do this by restarting the service altogether or just doing a soft reload:

# /sbin/service autofs reload

Wrap up

The autofs utility is a great way to supplement your NFS journey with some additional insight into this useful feature. There is so much more to learn around the things we use every day if we just take the time to dig for it. Hopefully, you found this quick exercise helpful.

[ Free download: Advanced Linux commands cheat sheet. ]


執筆者紹介

Tyler is the Sr. Community Manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. Now that he has surfaced, he lives with his wife and son near Raleigh, where he worked as a data storage engineer before finding his way to the Red Hat team. He has written numerous technical documents, from military procedures to knowledgebase articles and even some training curricula. In his free time, he blends a passion for hiking, climbing, and bushcraft with video games and computer building. He is loves to read and enjoy a scotch or bourbon. Find him on Twitter or on LinkedIn.

UI_Icon-Red_Hat-Close-A-Black-RGB

チャンネル別に見る

automation icon

自動化

テクノロジー、チームおよび環境に関する IT 自動化の最新情報

AI icon

AI (人工知能)

お客様が AI ワークロードをどこでも自由に実行することを可能にするプラットフォームについてのアップデート

open hybrid cloud icon

オープン・ハイブリッドクラウド

ハイブリッドクラウドで柔軟に未来を築く方法をご確認ください。

security icon

セキュリティ

環境やテクノロジー全体に及ぶリスクを軽減する方法に関する最新情報

edge icon

エッジコンピューティング

エッジでの運用を単純化するプラットフォームのアップデート

Infrastructure icon

インフラストラクチャ

世界有数のエンタープライズ向け Linux プラットフォームの最新情報

application development icon

アプリケーション

アプリケーションの最も困難な課題に対する Red Hat ソリューションの詳細

Virtualization icon

仮想化

オンプレミスまたは複数クラウドでのワークロードに対応するエンタープライズ仮想化の将来についてご覧ください