--- Title: "Mount with automount (autofs)" Author: "Kristof Vandam" Categories: [ "administration" ] Tags: [ "linux", "data", "mount", "shares" ] Date: 2018-11-09T10:08:15+02:00 Truncated: true Draft: false --- Automagically mount remote directories on login. ## Install the required pakages ```.language-command sudo yum -y install autofs ``` ## Create the entry file the mapper file is a file where we specify the directory where all our mounts should be placed. This file should be stored in */etc/auto.master.d*, note that the extension is required to be *.autofs* for example: */etc/auto.master.d/home.autofs* ```.language-command /home/guests /etc/auto.home ``` The value for */home/guests* is the file where we specify our mount options. **Note**: Make sure the */home/guests* directory exists, if not create it with: ```.language-command mkdir /home/guests ``` ## Create the mapper file We earlier specified where our map file should be stored (*/etc/auto.home*), create this file. Say we want to auto mount the home directories stored on **serverA** on /home/guests/[*USER*] when [*USER*] logs in. ```.language-command * -rw,sync serverA:/home/guests/& ``` * The wildcards task is to create the directory based on the users homedirectory on serverA (specified with **&**) * We give option like: read/write and sync * As last param we have to say where we want to mount to, again, the **&** is dynamic and maps to the logged in user. ## Enable and start the service ```.language-command sudo systemctl enable autofs sudo systemctl start autofs ``` ## Wrapping up Log in as a user, and check if the mount is present as expected. ```.language-command df -h ``` Should output something like: ```.language-command Filesystem Size Used Avail Use% Mounted on /dev/xvda1 8.0G 5.6G 2.5G 70% / devtmpfs 224M 0 224M 0% /dev tmpfs 244M 0 244M 0% /dev/shm tmpfs 244M 41M 204M 17% /run tmpfs 244M 0 244M 0% /sys/fs/cgroup tmpfs 49M 0 49M 0% /run/user/1000 tmpfs 49M 0 49M 0% /run/user/0 /serverA:/home/guests/user1 200M 0 200M 0% /home/guests/user1 ``` Note the last line where we see that the mount is present