Handling mounting of network filesystems/shares with autofs
From FedoraNEWS.ORG
Written by Konrad Kosmowski on 2005-08-09
| Table of contents |
Preface
In this article I will show how to mount networked filesystem shares (like NFS or CIFS/SMB but also any other filesystem that Fedora can support) using excellent automounter called autofs (ftp://ftp.kernel.org/pub/linux/daemons/autofs/). There are other tutorials/documents about autofs (http://www.google.com/search?q=autofs). Mine will focus on casual desktop usage with practical examples for Fedora Core.
This article does not cover how to export a filesystem. For that please consult users manual (from Red Hat Linux 9 - but it is still mostly up-to-date) concerning:
- Exporting NFS shares (http://ftp.redhat.com/pub/redhat/linux/9/en/doc/RH-DOCS/rhl-cg-en-9/s1-nfs-export.html)
- Configuring Samba (CIFS/SMB) shares (http://ftp.redhat.com/pub/redhat/linux/9/en/doc/RH-DOCS/rhl-cg-en-9/s1-nfs-export.html)
Or generic documentation about:
- Samba - free implementation of CIFS/SMB (also Windows Networking) (http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/)
- Linux NFS (Network Filesystem) HOWTO (http://nfs.sourceforge.net/nfs-howto/)
Problem
There are various ways to access remote filesystems in Linux. Most popular one is to simply mount them somewhere issuing the mount command with proper parameters. Another way is to mount it at boot-time using an entry to /etc/fstab file. Also sing graphical shells like GNOME or KDE allows to use networked file shares without mounting them - this is accomplished using various virtual filesystem implementations (like GNOME VFS or KIO). But each of these methods has its flaws.
- Issuing proper mount command will probably get you where you wish. But it is inconvinient. The command must be issued as root user (or is listed in /etc/fstab as allowed for regular user). So mount command is probably the most reliable and common - you certainly need to know it - but it is not casual.
- Mounting shares at boot is probably better idea. But still it produces problems - if the server (machine that holds shared files) is not aviable at the boot time (plenty of reasons - f. e. unplugged network cable) it will not mount (even if it will become aviable just after boot process). Another problem is with laptop systems - they often tend to switch networks for time to time and in various networks desired servers/shares vary. So /etc/fstab is also inconvinient here. Either you will need a lot of entries in this file and to issue commands manually.
- VFS-like solutions are more appealing to casual user - you just browse to desired share with your filemanager and the files will be at hand. But not exactly - VFS implementations vary from one program to another (mentioned GNOME and KDE). So GNOME program will understand GNOME VFS but other (non GNOME) program won't. That produces situations in which you browse a share, click a file and it will not open producing some bogus error. Also for text-based/legacy apps - most of them won't work with popular userspace VFS implementations.
Solution
Problem solved already
The solution to these problems is autofs. It allows you to mount previously defined shares when you wish. Advantages of autofs are that you:
- Do not need to issue any special commands to mount a filesystem. Just browse it and it will be instantly aviable or not aviable (producing standard file not found error).
- Do not need to be root in order to mount desired filesystem but given filesystem needs to be listed in config file.
- Works on kernel/operating system level (as opossed to aftermentioned userspace) which means that this way of handling network shares will be accessible to all programs that you run.
Note: autofs can also handle non-network mounts like devices (floppy, cdrom, digital camera etc.). But I think there are other and better ways to handle these. Fedora already supports casual handling of devices via HAL (http://www.redhat.com/magazine/003jan05/features/hal/) so I will only focus on networked filesystems.
Pre-configuration tasks
To configure autofs you need to:
- As for all administration tasks - be logged as root user.
- Know desired shares addresses. Typically it is something similar to //samba_server/foo for CIFS/SMB and nfs_server:/bar for NFS - my example will cover that addresses.
Installing autofs
With typical Fedora Core installation autofs is installed and ready to go by default. But you can check it issuing:
rpm -q autofs autofs-4.1.4-5
If it happens that you do not have autofs installed issue following command:
yum install autofs

