Monthly Archives: October 2016

How to mount via autofs


here’s how to use autofs, it’s quite a good soft to be sure you mount filesystems anytime, it’s also useful to unmount them when you don’t need them (less uptime for the disk and you can save the planet this way).
First install the correct package:

# aptitude install autofs
Install autofs

Then create the few directories:

# mkdir /etc/ /etc/auto.master.d /mnt/autofs
Create directories

Now it’s time to do some configuration, so edit /etc/auto.master.d/master.autofs:

/mnt/autofs /etc/
Content of /etc/auto.master.d/master.autofs

Finally, simply set the mount(s) you want in /etc/ (one per line) :

# <directory name (will be in /mnt/autofs)> <options such as filesystem, uid/gid ...> <what you mount>
boxshare -fstype=cifs,defaults,_netdev,uid=1000,gid=1000,user=nobody,password= ://
Content of /etc/

There you can notice I just have one mount, a cifs one, the mount directory will be /mnt/autofs/boxshare.

Now restart autofs and check if it’s mounted!

# service autofs restart
# ls /mnt/autofs/boxshare
Start it up !

If when you “ls” the directory it fails, then stop autofs and troubleshoot it this way:

# service autofs stop
# automount -f -v

You’ll probably get this error:

Starting automounter version 5.0.7, master map /etc/auto.master
using kernel protocol version 5.02
lookup(file): failed to read included master map auto.master
mounted indirect on /mnt/autofs with timeout 300, freq 75 seconds

To fix it, simply open /etc/auto.master an comment the last line, so it should look like that:

# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#/misc /etc/auto.misc
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#/net -hosts
# Include /etc/auto.master.d/*.autofs
# Include central master map if it can be found using
# nsswitch sources.
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
Fixing it

Now you restart autofs and it should work !

If not, do the troubleshooting again 🙂
Cheers !