Auto Mount NAS Network Drives with AutoFS in Ubuntu
autofs is a tool for automatically mounting directories when they are needed. I find that this makes it ideal for using with laptops on my WiFi network to access my NAS, that had difficulty keeping static mounts via fstab when they hibernate. Auto-mounts are mounted only as they are accessed, for example when you cd into the mounted directory and they they are unmounted after a period of inactivity.
How to Setup autofs on ubuntu 22.04
Install autofs on ubuntu with apt
sudo apt update
sudo apt install autofs
use a text editor to edit the config file /etc/auto.master and append a reference to a new file that we will create to the end.
vi /etc/auto.master/mnt
and add this line to the end of the file.
/etc/auto.nasdocs
create the file we mentioned above
vi /etc/auto.nasdocs
and put in our auto mount statement, where nasdocs is the new local mount directory name that will be created inside /mnt and the directory on my NAS drive that we are mounting is 192.168.11.10:/volume1/nasdocs
nasdocs -rw 192.168.11.10:/volume1/nasdocs
read changes
service autofs reload
test it by listing or changing into the directory
ls /mnt/nasdocs
Further Reading
There is a more detailed guide hosted on ubuntu Wiki Autofs – Community Help Wiki (ubuntu.com)