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 ...

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.

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!