ALINK="#FF0000">

"Linux Gazette...making Linux just a little more fun!"


Quick autofs Tutorial

By Mark Nielsen


What is autofs? Autofs uses automount to mount cdrom and floppy drives (and other things) to your computer as you need them and umount as they are not being used. What is mount and unmount? Mount and umount are programs to mount a device ontop of a directory. For example, this command would mount the first floppy drive (drive a: in DOS terms) to the directory "/mnt/floppy" so that everytime you access "/mnt/floppy" to access your floppy drive.

mount /dev/fd0 /mnt/floppy

And this command unmounts or frees up the floppy drive from being used.

    
umount /dev/fd0 

Now, in DOS terms, your floppy disk is accessed as you need it. For normal users, that is what they would expect. They wouldn't want to use mount and umount because it is time consuming and because they might not get it right.

I assume "/dev/cdrom" is your cdrom drive and "dev/fd0" is your floppy drive. I am also assuming you will backup your "/etc/auto.master" file. Use this script to create the following threes files and restart autofs. Login as "root", goto your home directory, copy whatever between the next two lines to a file called "CreateAutofs.script" and execute the script with the command

 
source CreateAutofs.script

cd
echo "Please ignore any errors when making directories"
     ### Let us make sure the two directories exist, ignore errors
mkdir /mnt/floppy
mkdir /mnt/cdrom
     ### Let us backup the auto files in case they haven't
mv /etc/auto.master /etc/auto.master_old
mv /etc/auto.floppy /etc/auto.floppy_old
mv /etc/auto.cdrom /etc/auto.cdrom_old
     ### Create the files for autofs
echo "/mnt/cdrom /etc/auto.cdrom --timeout 10" > /etc/auto.master
echo "/mnt/floppy /etc/auto.floppy --timeout 1" >> /etc/auto.master
echo "floppy   -user,suid,fstype=msdos :/dev/fd0" > /etc/auto.floppy
echo "cdrom    -fstype=iso9660,ro   :/dev/cdrom" > /etc/auto.cdrom
     ### Create the links to the floppy drive and cdrom drive
ln -s /mnt/floppy/floppy a:
ln -s /mnt/cdrom/cdrom d:
ln -s /mnt/floppy/floppy floppy
ln -s /mnt/cdrom/cdrom cdrom 
     ### Lets retstart autofs, you might have to reboot
cd /etc/rc.d/init.d
./autofs restart
     ### If it didn't work, you might have to reboot 
     ### Try "./autofs start" if the restart claims autofs has not been
     #### started
cd


The end of your results should look something like the following if it was sucessfull

Start /usr/sbin/automount --timeout 10 /mnt/cdrom file /etc/auto.cdrom
Start /usr/sbin/automount --timeout 1 /mnt/floppy file /etc/auto.floppy
Now put a floppy disk formatted for MSDOS and a cdrom in and execute the commands
ls a:
ls d:
to see if there is anything on them. Hopefully you don't get any error messages.

Personally, my /etc/auto.floppy file looks like

floppy          -fstype=auto,defaults,user,suid :/dev/fd0
and my /etc/auto.cdrom file look like this
cdrom           -fstype=iso9660,user,suid       :/dev/cdrom
The reason why I gave conservative values in the script was the fact the my values might be security hazards. But since I am the only person using my computer, I wanted to make sure my personal account had full access to the floppy and cdrom drives. Also, -fstype=auto doesn't seem to work quite right when your disk is formated for MSDOS, but works fine with ext2. "-fstype=auto" tries to autodetect the file format.

If you noticed the timeout value for the floppy drive is 1 second. This makes it so that by the time the floppy drive light has gone out, your floppy disk is unmounted and a normal user can take the floppy disk out and "nothing bad happens". I made the timeout value for the cdrom 10 seconds because it wasn't working really well at 1 second, and I figured it was because the drive didn't have enough time to "warm up" before it was being shut down. You might want to test what the timeout value for your cdrom drive should be.

To get more information about autofs, do the commands

man 5 autofs
man autofs
and look the the directory "usr/doc" for the directory "autofs-0.3.14" or something similar to it.

Now to explain it

Okay, here is my brief explanation for what is happening. Read the man pages and any docs first.

Your "/etc/rc.d/init.d/autofs" script first looks at "/etc/auto.master". That file usually has three things on each line. It has the directory which all mounts will be located at. Then next to that value is the filename which contains the configuration(s) for what devices you want mounted. We will call these filenames the "supplemental" files. Next to that value is the timeout which you want to occur after so many seconds of inactivity. The timeout will free or umount all devices specificed in the supplemental files after so many seconds of inactivity.

Now, the supplemental files can have more than on entry, but for my purposes I don't do that. Read below for the explanation. The supplemental files can be named anything you want them to be named. They also have three values for each entry. The first value is the "psuedo" directory. I will explain this later. The second value contains the mount options. The third value is the device (like "/dev/fd0" which is the floppy drive) which the "psuedo" directory is connected to.

The "pseudo" directory is contained in the directory which is defined in "/etc/auto.master". When people try to access this "psuedo" directory, they will be rerouted to the device you specified. For example, the above script will generate a link called "a:" which if you list with the command "ls a:" will give you a list of files in the floppy drive. Or, a similar command would be "ls /mnt/floppy/floppy". But if you do the command "ls /mnt/floppy", you don't see anything even though the directory "/mnt/floppy/floppy" should exist. That is because "/mnt/floppy/floppy" doesn't exist as a file or directory, but somehow the system knows that if you specifically ask for "/mnt/floppy/floppy", it will reroute you to the floppy drive.

Now as to the reason why I didn't combine the floppy drive and cdrom drive into the same supplementary file. Each definition in the "/etc/auto.master" file will have its own "automount" program running for it. If you have several devices running on the same automount program and one of them fails, it could force the others not to work. That is why I want every device running on its own automount program which means there is one device per supplementary file per entry in the "/etc/auto.master" file.


Copyright © 1998, Mark Nielsen
Published in Issue 24 of Linux Gazette, January 1998


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next