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


Mark's autofs tutorial revisited


Mark's autofs tutorial revisited


at The Computer Underground

If this document changes, it will be available here: Mark's autofs tutorial revisited. Also, an earlier version of this tutorial is at January 1998 Issue #24.


  1. Some notes.
  2. Installing Autofs
  3. Explaining what we did.
  4. Installing for new users.
  5. Installing a zip drive and other resources.

Some notes.

What is autofs? Autofs lets you use your floppy and cdrom drives a little easier. In the MS Windoze world, when you need to access your floppy drive, you just goto drive "a:" and it is there. To replicate this feature in the Linux or UNIX world, you use an automounter that attaches a device (like a floppy or cdrom drive) to a directory on the computer.

If you don't have an automounter, you must manually attach a device to a directory using the commands "mount" and "umount". An example of attaching your floppy drive to the directory "/mnt/floppy" would be

mount /dev/fGd0 /mnt/floppy

If you need to explicitly define how the floppy drive was formatted, you can use these commands

mount -t msdos /dev/fd0 /mnt/floppy  ## For msdos formatted disks 
mount -t ext2 /dev/fd0 /mnt/floppy  ## For "linux" formatted disks
Also, you must make sure the directory "/mnt/floppy" exists. A command to make the directory would be,
mkdir -p /mnt/floppy
And this command unmounts or frees up the floppy drive from being used.
    
umount /dev/fd0 
Also, something one should be aware of, KDE and GNOME, which are desktop environments for X, usually have their own way of using floppy drives. The problem is, if you connect to your computer through telnet or ssh, these features are not available to you. That isn't nice. Using Autofs, any program or user entering a directory that is assigned to a device (like a floppy drive) causes the device to be attached to that directory. This happens at the system level rather than in the GUI level.

Also, Autofs can be used to grab an nfs site (and other things) and attach it to a directory. It can do more than just automouting your floppy and cdrom drives.

If you need some more info, try these urls or commands on your computer,

  1. man automount
  2. man autofs
  3. man /usr/man/man5/auto.master.5
  4. more /usr/doc/autofs-3.1.3/README
  5. Automount howto
NOTE: You also should consider any security hazards about using autofs.

Installing Autofs.

How do you install Autofs? Well, although I hate to demonstrate things for only one particular version of Linux (since I am heavily growing fond of Debian), this demo will be made for RedHat 6.0.

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 files and restart autofs. Login as "root", goto your home directory, copy whatever is between the next two lines to a file called "CreateAutofs.script" and then execute the script with the command

 
source CreateAutofs.script
----------------------------------------------------------------------
mkdir -p /root/Drives
cd /root/Drives

     ### Let us make sure the two directories exist, ignore errors
mkdir -p /mnt/Drives/floppy
mkdir /mnt/Drives/cdrom
     ### Let us backup the auto files in case they haven't
mv -f /etc/auto.master /etc/auto.master_old
mv -f /etc/auto.floppy /etc/auto.floppy_old
mv -f /etc/auto.cdrom /etc/auto.cdrom_old
     ### Create the files for autofs
echo "/mnt/Drives/cdrom /etc/auto.cdrom --timeout 10" > /etc/auto.master
echo "/mnt/Drives/floppy /etc/auto.floppy --timeout 3" >> /etc/auto.master
echo "floppy   -fstype=auto         :/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/Drives/floppy/floppy a:
ln -s /mnt/Drives/floppy/floppy floppy
ln -s /mnt/Drives/cdrom/cdrom d:
ln -s /mnt/Drives/cdrom/cdrom cdrom 
     ### Lets retstart autofs
/etc/rc.d/init.d/autofs stop
/etc/rc.d/init.d/autofs start
     ### If it didn't work, you might have to reboot 
cd /root/Drives
----------------------------------------------------------------------

Explaining what we did.

Now put a floppy disk formatted for MSDOS and a cdrom in and execute the commands

ls /root/Drives/a:
ls /root/Drives/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. Previously "-fstype=auto" wasn't working quite right with msdos disks, but when I increased the timeout to 3 seconds, it seemed to be working fine. 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.

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 specified 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 "pseudo" 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 "pseudo" 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 "pseudo" 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/Drives/floppy/floppy". But if you do the command "ls /mnt/Drives/floppy", you don't see anything even though the directory "/mnt/Drives/floppy/floppy" should exist. That is because "/mnt/Drives/floppy/floppy" doesn't exist as a file or directory, but somehow the system knows that if you specifically ask for "/mnt/Drives/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.

Also, another thing to note is, I use links to the "pseudo" directories. Non computer geeks will get confused if they try to manually use the "pseudo" directories. Basically, the "pseudo" directories are directories that don't exist until you try to use them. I like to use links to the "pseudo" directories so that the user sees and uses the link, and thus is happy because they are just always "there", which is unlike the "pseudo" directories which come and go as you need them.


Installing for new users.

How do you install this for new users? First, you must understand, the mount options you put into the autofs configuration files heavily determine how much a user can use the floppy or cdrom drives or other types of devices. There are also security hazards using autofs one should be aware of. Do the following,


mkdir -p /etc/skel/Drives
ln -s /mnt/Drives/floppy/floppy  /etc/skel/Drives/floppy  ## link to floppy
ln -s /mnt/Drives/floppy/floppy  /etc/skel/Drives/a: 
ln -s /mnt/Drives/cdrom/cdrom    /etc/skel/Drives/cdrom    ## link to cdrom
ln -s /mnt/Drives/cdrom/cdrom    /etc/skel/Drives/d: 

How do you install it for a user called "frank"?

Well assuming that Frank's home directory is /home/frank,


mkdir -p /home/frank/Drives   ## make a path for frank
chown frank /home/frank/Drives   ## Let frank own the directory

ln -s /mnt/Drives/floppy/floppy /home/frank/Drives/a:   ## link to floppy
ln -s /mnt/Drives/floppy/floppy /home/frank/Drives/floppy
ln -s /mnt/Drives/cdrom/cdrom /home/frank/Drives/d:   ## link to cdrom
ln -s /mnt/Drives/cdrom/cdrom /home/frank/Drives/cdrom

chown frank /home/frank/Drives/*  ### Let frank own the contents of directory

A truly risky command to install for a user after installing it for new users would be
     ### DO NOT DO THIS UNLESS YOU LIKE RISK
mkdir -p /home/frank/Drives

if [ -d /etc/skel/Drives ]; then
    tar -C /etc/skel -c Drives | tar -C /home/frank -xv Drives
    chown -R frank /home/frank/Drives 
   else
     echo "Dude, like try to make a /etc/skel/Drives directory first."
fi

Installing a zip drive or other resources.

Okay, now for some more funky stuff. I am going to use one more configuration file to both do the zip drive and an nfs site. First, I am assuming the zip drive is the slave on the primary IDE controller of your computer. Actually, I tried to connect to this site through nfs, and it didn't work. I tried it to one of my local computers and it worked fine.


echo "/mnt/Drives/zip /etc/auto.zip --timeout 10 --timeout 5" >> /etc/auto.master
echo "kernel   -ro,soft,intr   ftp.kernel.org:/pub/linux" > /etc/auto.zip
echo "zip1   -fstype=auto,rw :/dev/hdb1 " >> /etc/auto.zip 
echo "zip2   -fstype=auto,rw :/dev/hdb2 " >> /etc/auto.zip  
echo "zip3   -fstype=auto,rw :/dev/hdb3 " >> /etc/auto.zip
echo "zip4   -fstype=auto,rw :/dev/hdb4 " >> /etc/auto.zip

ln -s /mnt/Drives/zip/kernel  /etc/skel/Drives/kernel 
ln -s /mnt/Drives/zip/zip4    /etc/skel/Drives/zip    ## link to cdrom


Mark works for The Computer Underground as JALG. In his spare time, he tries to do volunteer stuff. Mark takes an active role in COLUG located in Columbus, Ohio.


Copyright © 1999, Mark Nielsen
Published in Issue 42 of Linux Gazette, June 1999


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next