old-www/LDP/LG/issue42/nielsen.html

358 lines
13 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>Mark's autofs tutorial revisited LG #42</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Mark's autofs tutorial revisited</font></H1>
<H4><a href="mailto:mark@tcu-inc.com">by Mark Nielsen</a></H4>
</center>
<P> <HR> <P>
<h1> Mark's autofs tutorial <u><i>revisited</i></u></h1>
<br><i> <a href="http://www.tcu-inc.com">at The Computer Underground</a></i>
</center>
<p>
If this document changes, it will be available here:
<a href="http://www.tcu-inc.com/mark/articles/Autofs2.html">
Mark's autofs tutorial revisited</a>.
Also, an earlier version of this tutorial is at
<a href="http://www.ssc.com/lg/issue24/nielsen.html">
January 1998 Issue #24.</a>
<P> <hr><P>
<ol>
<li><a href="#Intro"> Some notes.</a>
<li><a href="#Install"> Installing Autofs</a>
<li><a href="#Explain"> Explaining what we did.</a>
<li> <a href="#Install2"> Installing for new users.</a>
<li><a href="#zip"> Installing a zip drive</a> and other resources.
</ol>
<hr>
<a name="Intro"></a>
<h1> Some notes.</h1>
<p>
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.
<p>
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
<pre>
mount /dev/fGd0 /mnt/floppy
</pre>
<p>
If you need to explicitly define how the floppy drive was formatted, you
can
use these commands
<pre>
mount -t msdos /dev/fd0 /mnt/floppy ## For msdos formatted disks
mount -t ext2 /dev/fd0 /mnt/floppy ## For "linux" formatted disks
</pre>
Also, you must make sure the directory "/mnt/floppy" exists. A command to
make the directory would be,
<pre>
mkdir -p /mnt/floppy
</pre>
And this command unmounts or frees up the floppy drive from being used.
<pre>
umount /dev/fd0
</pre>
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.
<p>
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.
<p>
If you need some more info, try these urls or commands on your computer,
<ol>
<li>man automount
<li>man autofs
<li>man /usr/man/man5/auto.master.5
<li>more /usr/doc/autofs-3.1.3/README
<li><a href="http://metalab.unc.edu/LDP/HOWTO/mini/Automount.html">
Automount howto</a>
</ol>
NOTE: You also should consider any security hazards about using autofs.
<hr>
<a name="Install"></a>
<h1> Installing Autofs.</h1>
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.
<p>
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
<pre>
source CreateAutofs.script
</pre>
----------------------------------------------------------------------
<pre>
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
</pre>
----------------------------------------------------------------------
<hr>
<a name="Explain"></a>
<h1> Explaining what we did.</h1>
<p>
Now put a floppy disk formatted for MSDOS and a cdrom in and execute the
commands
<pre>
ls /root/Drives/a:
ls /root/Drives/d:
</pre>
to see if there is anything on them. Hopefully you don't get any error
messages.
<p>
Personally, my /etc/auto.floppy file looks like
<pre>
floppy -fstype=auto,defaults,user,suid :/dev/fd0
</pre>
and my /etc/auto.cdrom file look like this
<pre>
cdrom -fstype=iso9660,user,suid :/dev/cdrom
</pre>
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.
<p>
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.
<p>
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.
<p>
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.
<p>
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.
<p>
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.
<hr>
<a name="Install2"></a>
<h1> Installing for new users.</h1>
<p>
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,
<hr>
<pre>
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:
</pre>
<hr>
<p>
How do you install it for a user called "frank"?
<p> Well assuming that Frank's home directory is /home/frank,
<hr>
<pre>
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
</pre>
<hr>
A truly risky command to install for a user after installing it for new
users would be
<hr>
<pre>
### 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
</pre>
<hr>
<a name="zip"></a>
<h1> Installing a zip drive or other resources.</h1>
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.
<p>
<hr>
<pre>
echo "/mnt/Drives/zip /etc/auto.zip --timeout 10 --timeout 5" &gt;&gt; /etc/auto.master
echo "kernel -ro,soft,intr ftp.kernel.org:/pub/linux" &gt; /etc/auto.zip
echo "zip1 -fstype=auto,rw :/dev/hdb1 " &gt;&gt; /etc/auto.zip
echo "zip2 -fstype=auto,rw :/dev/hdb2 " &gt;&gt; /etc/auto.zip
echo "zip3 -fstype=auto,rw :/dev/hdb3 " &gt;&gt; /etc/auto.zip
echo "zip4 -fstype=auto,rw :/dev/hdb4 " &gt;&gt; /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
</pre>
<hr>
<i>
Mark works for <a href="http://www.tcu-inc.com">The Computer Underground</a>
as JALG. In his spare time, he tries to do volunteer stuff. Mark takes an
active role in
<a href="http://bopper.wcbe.org/~COLUG/">COLUG
</a>
located in Columbus, Ohio.
</i>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1999, Mark Nielsen <BR>
Published in Issue 42 of <i>Linux Gazette</i>, June 1999</H5></center>
<!--===================================================================-->
<!--startcut ==========================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./lg_tips42.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./lamb.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
</BODY>
</HTML>
<!--endcut ============================================================-->