09 January 2011

Mounting via the Automounter

Once you run the mount command on a partition, it stays mounted until you unmount it or shut down or reboot your computer. This can cause problems. For example, if you've mounted a floppy and then physically removed the disk, Linux may not have had a chance to write the file to the disk. This situation also applies to Zip or other hotswappable removable drives.

Another example, with mounted NFS directories, occurs if the remote computer fails or the connection is lost; your system may become slow or even hang as it looks for the mounted directory.

This is where the automounter can help. It relies on the autofs daemon to mount configured directories as needed, on a temporary basis. In RHEL, the relevant configuration files are /etc/auto.master, /etc/auto.misc, and /etc/auto.net. If you use the automounter, keep the /misc and /net directories free. Red Hat configures automounts on these directories by default, and they won't work if local files or directories are stored there.


Onn the Job 
You won't even see the /misc or /net directories unless you properly configure /etc/auto.master and activate the autofs daemon. The /etc/auto.smb configuration file does not work for CIFS shares, such as from Windows XP/ Vista. One option for CIFS shares is an /etc/auto.cifs configuration, described at www.howtoforge.com/win-smb-autofs-share.

Default automounter settings are configured in /etc/sysconfig/autofs. The default settings include a timeout of 300 seconds; in other words, if nothing happens on an automount within that time, the share is automatically unmounted:
DEFAULT_TIMEOUT=300
The DEFAULT_BROWSE_MODE can allow you to search from available mounts. The following directive disables it by default:
DEFAULT_BROWSE_MODE="no"
There are a wide variety of additional settings available, as commented in the /etc/sysconfig/autofs file, which also assumes that the autofs daemon is active. To check, run the following command:
# /etc/init.d/autofs status
Make sure to run this command with administrative privileges; otherwise, you'll get the misleading message "automount is stopped".

/etc/auto.master

The standard /etc/auto.master file includes a series of comments, with three default commands. The first refers to the /etc/auto.misc file as the configuration file for this directory. The /net -hosts command allows you to specify the host to automount a network directory, as specified in /etc/auto.net.
/misc /etc/auto.misc
/net -hosts
+auto.master
In any case, these commands point to configuration files for each service. Shared directories from each service are automatically mounted, on demand, on the given directory (/misc and /net).
You can set up the automounter on other directories. One popular option is to set up the automounter on the /home directory. In this way, you can configure user home directories on remote servers, mounted on demand. Users are given access to their home directories upon login, and based on the DEFAULT_TIMEOUT directive in the /etc/sysconfig/autofs file, all mounted directories are automatically unmounted 300 seconds after that user logs off the system.
# /home /etc/auto.home
This works only if you don't already have a /home directory on your computer.

/etc/auto.misc

Red Hat conveniently provides standard automount commands in comments in the /etc/auto.misc file. It's helpful to analyze this file in detail. I use the default RHEL version of this file. The first four lines are comments, which I skip. The first command is:
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
In RHEL, this command is active by default-assuming you've activated the autofs service. In other words, if you have a CD in the /dev/cdrom drive, you can access its files through the automounter with the ls /misc/cd command. The automounter accesses it using the ISO9660 filesystem. It's mounted read-only (ro); set user ID permissions are not allowed (nosuid), and devices on this filesystem are not used (nodev).

With the command from /etc/auto.master, the CD is unmounted 300 seconds after the last time it's accessed. There are a number of other sample commands, commented out, ready for use. Of course, you would have to delete the comment character (#) before using any of these commands. The first of these commented commands allows you to set up a /misc/linux mount point from a shared NFS directory, /pub/linux, on the ftp.example.org computer:
#linux -ro,soft,intr  ftp.example.org:/pub/linux
The next command assumes that the /boot directory is stored on the /dev/hda1 partition. With this command, you don't need to mount /boot when you start Linux. Instead, this command allows you to automount it with the mount /misc/boot command.
#boot -fstype=ext2  :/dev/hda1
The following three commands apply to a floppy disk drive on your computer. The first command, set to an "auto" filesystem type, searches through /etc/filesystems to try to match what's on your floppy. The next two commands assume that the floppy is formatted to the ext2 filesystem.
#floppy     -fstype=auto     :/dev/fd0
#floppy     -fstype=ext2     :/dev/fd0
#e2floppy   -fstype=ext2     :/dev/fd0
The next command points to the first partition on the third SCSI drive. The jaz at the beginning suggests this is suitable for an Iomega-type Jaz drive.
#jaz    -fstype=ext2    :/dev/sdc1
Finally, the last command assumes that you want to apply the automounter to the IDE drive connected as the slave on the secondary controller. The removable at the beginning suggests this is suitable for removable hard drives.
#removable   -fstype=ext2   :/dev/hdd
With the possible exception of the floppy commands, you'll need to modify these lines for your own hardware.

/etc/auto.net

With the /etc/auto.net configuration script, you can review and read shared NFS directories. As IP addresses don't work with this script, you'll need either a DNS server or at least an appropriate database entry in /etc/hosts that associates the host name with the IP address of the NFS server.
To make this work, make sure execute permissions are enabled on this file. If necessary, run the following command:
# chmod 755 /etc/auto.net
Activate the automounter. Then to review available shares on my enterprise5fc6d system, I run the following command:
# /etc/auto.net enterprise5fc6d
-fstype=nfs,hard,intr,nodev,nosuid \
        /inst enterprise5fc6d:/inst
This tells me that the /inst directory on the enterprise5fc6d system is shared via NFS. Based on the directives in /etc/auto.master, I can access this share (assuming appropriate firewall and SELinux settings) with the following command:
# ls /net/enterprise5fc6d/inst

Activating the Automounter

Once you've configured the desired configuration files, you can activate the automounter. As it is governed by the autofs daemon, you can activate it (and make it reread your configuration files) with the following command:
# service autofs restart
With the default command in the /etc/auto.misc file, you should now be able to mount a CD on the /misc/cd directory, automatically, just by accessing the configured directory. Once you have a CD in the drive, the following command should work:
# ls /misc/cd
If you were to make /misc/cd your current directory, the automounter would ignore any timeouts. Otherwise, /misc/cd is automatically unmounted according to the timeout, which according to the command in /etc/auto.master is 60 seconds.



 See Also:


RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)




biOos

No comments: