Skip to main content

Configure AutoFS to Automatically Mount Filesystems

Hands-On Lab

 

Photo of Matthew Pearson

Matthew Pearson

Linux Training Architect II in Content

Length

00:30:00

Difficulty

Intermediate

autofs allows filesystems to be automatically mounted when they are accessed. In this hands-on lab, you are tasked with configuring a series of mounts using autofs.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Configure AutoFS to Automatically Mount Filesystems

In this lab, we will create two automounts. These should be indirect mounts that are mounted under /mnt/marketing. The first should be called assets, and it should have anxfs file system and use the /dev/xvdg1 device. The second should be called backup, and it should have a btrfs filesystem, be read-only, and use the /dev/xvdg2 device. The map file for this indirect map should be /etc/auto.marketing.

Next, we will need to create two direct mounts, one for administrators and the other for normal users. The administrator mount should be mounted at /mnt/admin/data with an ext4 file system using the /dev/xvdg3 device. The map file for this should be /etc/auto.admin. The user mount should be located at /mnt/user/data, have an ext2 file system, use the /dev/xvdg4 device, and have a timeout of one hour. The map file should be/etc/auto.user.

Before We Begin

To get started, we need to log in to our instance with the provided credentials. Make sure to become the root user.

Install the autofs Package

Install the autofs package and start and enable the autofs service.

  1. Use the yum command to install the autofs package:

yum -y install autofs

  1. Start and enable the autofs service:

systemc enable autofs --now

  1. Check that the status is running:

systemctl status autofs

Create an Indirect Mount

Create an indirect mount at /mnt/marketing based on the information provided in the instructions:

  1. Create the /mnt/marketing directory:

mkdir /mnt/marketing

  1. Use a text editor (for our exmaple, we use vim) to open our /etc/auto.master document:

vim /etc/auto.master

  1. Under the /misc/ section, add the following:

/mnt/marketing /etc/auto.marketing

  1. Save and quit with :wq.
  2. Create a map file for /mnt/marketing called /etc/auto.marketing:

vim /etc/auto/marketing

  1. Enter the following content:
assets -fstype=xfs :/dev/xvdg1
backup -fstype=btrfs,ro :/dev/xvdg2
  1. Save and quit with :wq.
  2. Restart the autofs service to apply the changes:

systemctl restart autofs

  1. Use ll/mnt/marketing/assets to see that we currently don't have anything in the file, then df -h to check that our information is mounted.
  2. Do the same for our backup, using ll/mnt/marketing/backup to see that the file is empty, then df -h to check that it is mounted.
  3. Finally, check that it is read-only by using mount | grep backup. ro should be present in the list to show it is read-only. We can also use touch /mnt/marketing/backup/test1 to see that it is set as read-only.

Create a Direct Mount

Create a direct mount at /mnt/admin/data based on the information provided in the instructions:

  1. Use a text editor (for our example, we use vim) to edit the /etc/auto.master file.
  2. Right under /mnt/marketing enter in the following:

/- /etc/auto.admin

  1. Use :wq to save and quit.
  2. Create a map file for the entry called /etc/auto.admin, for our example we're using vim:

vim /etc/auto.admin

  1. Add the following information:

/mnt/admin/data -fstype=ext4 :/dev/xvdg3

  1. Save and quit.
  2. Restart the autofs service to apply the changes:

systemctl restart autofs

  1. Use df -h to see that our information is mounted.

Create a Second Direct Mount

Create a direct mount at /mnt/user/data based on the information provided in the instructions

  1. Use a text editor (in our example, vim) to open /etc/auto.master:

vim /etc/auto.master

  1. Under our previous entery of /- /etc/auto.admin, enter the following:

/- /etc/auto.user --timeout=3600

  1. Create a map file for the entry called /etc/auto.user:

vim /etc/auto.user

  1. Enter the following:

/mnt/user/data -fstype=ext2 :/dev/xvdg4

  1. Save the file.
  2. Restart the autofs service to apply the changes:

systemctl restart autofs

  1. Use ll /mnt/user/data/ to see that our information is populated.
  2. Check that the information is mounted with df -h.
  3. Finally, check our timeout time by using mount | grep data and looking at the timeouts that have been set.

Conclusion

Congratulations! You've completed the lab!