Auto-Mounting

What is autofs ?

💡 You won’t waste network resources until you access the remote folder!

You can put NFS filesystems in the /etc/fstab configuration file so that they are automatically mounted upon system boot. However, in some cases, the system can experience performance problems using this arrangement. By allowing AutoFS to manage mounting NFS filesystems, you avoid these problems.

The first thing to do is to set up NFS server:

in my demo, i have centos plus an ubuntu machines, and for that i will install nfs-server or centos:

sudo yum install nfs-utils

systemctl start nfs-server

Now, let’s create the Directory that we want to be mounted on other machines mkdir /shared

Configure it to be exported;

vim /etc/exports

The /shared is the directory we just have created

‘*’ is for everyone on the network

/shared *(rw,sync,no_root_squash)

Make sure to allow necessary services on the firewall:

firewall-cmd --permanent --add-service={nfs-mountd-rpc-bind}

Now on the Ubuntu machine

let’s install Autofs

sudo apt-get install autofs

systemctl start autofs

in the /etc, you have to edit the main config file which is : auto.master

vi auto.master

add this following line :

/nfs /etc/auto.nfs

Basically, you are telling nfs to share anything specifi to the config ‘auto.nfs’ to be mounted on /nfs on our local machine

Exit the file and create his auto.nfs and add the correspondent configuration:

shared 192.168.1.16:/shared

‘shared’ will be used later to access the shared files. The address is meant for the nfs-server

Now, if you try and access the shared folder: ls /nfs you wont see anything but if you type ls /nfs/shared you will see the files you have created in the centos or the nfs-server

Last updated