Someone recently asked in comp.os.linux.development.system how to
automatically have all cdroms in a cdrom changer appear to be mounted
at once (with different names) without having to manually mount,
change and remount.

This is quite easy to do with autofs (the automounter).  Here's how to
do it.

1. Check your kernel is configured to have CONFIG_AUTOFS_FS
   (and of course rebuild it if necessary).   (And reboot it!)

2. Get the automounter code.  Look in
	ftp://ftp.kernel.org/pub/linux/daemons/autofs
   I have tested this with version 0.3.14 .

3. Build and (as root) install autofs from step 2.

4. Obtain a program to switch the cdrom changer to a specific slot.

   The Linux source contains at the end of /Documentation/cdrom/ide-cd
   a program called cdchange.c;  in older (v2.0) kernels it was
   called cdload.c.  Compile it and install it somewhere,  I'll assume
   /usr/local/sbin/cdchange .  

   Alternatively,  you can use my version called cdchanger which is
   based upon it but has the ability to remount after switching.

5. You need to create 4 (or 3) files for the automounter.

(a) Initialization code to start the daemon.  This is typically a
matter of copying the file samples/rc.autofs (from the autofs source)
into whatever is applicable for your system,  e.g. /etc/init.d/autofs,
and adding links to it as needed (e.g. from /etc/rc2.d).

(b) Unless you change the above file, it will start autofs with the
file /etc/auto.master.  Again, the autofs distribution contains an
example samples/auto.master.  You need to add a line to it like this:

/changer	/etc/auto.changer.sh

This tells the automounter to check names under the /changer mount 
point by calling the script /etc/auto.changer.sh.  Here is an example
of the file based on their sample:

Richard Sharman <rsharman@magma.ca>

-------------- /etc/auto.master --------------
# /etc/auto.master

# Format of this file:
# mountpoint map options
# For details of the format look at autofs(8).
/misc	/etc/auto.misc
/changer	/etc/auto.changer.sh
------------------------------------------

(c) To use the sample /misc mount-point,  don't forget to copy the
file sample/auto.misc to /etc/auto.misc .  This is a totally separate
mount point and is for other stuff;  if you don't want that yet
comment out the line in the auto.master file.

(d) Install the script /etc/auto.changer.sh which is attached below.
You will have to edit it for your setup, by changing these
definitions:

DEVICE - the cdrom changer device.
PROG   - the program which switches its slots (step 4 above).
MAX.   - the maximum slot number.

Also, uncomment out one section, for cdload (for V2.0) or for cdchange
(for V2.1), or my cdchanger.  Note that you must also set MUST_UNMOUNT
to a non-empty string for cdload and cdchage, and for cdload you must
also set SLOT_ZERO_BASED to a non-empty string (since cdload numbers
slots from zero).


6. Start the automounter, e.g.  /etc/init.d/autofs start

Try referencing a cdrom in the second slot
% ls /changer/disk2

Now try another slot
% ls /changer/disk3

The "/changer" part is what you put in the /etc/auto.master file.
The "disk2" can be any name ending in a number.  The auto.changer.sh
part simply uses the number to tell the changer-program what slot is
required.

7. For debugging, it is useful to look at the logs,  so as root 
	xterm -e tail -f /var/log/daemon.log &
   is helpful.  (Check /etc/syslog.conf for where the daemon logs are
   directed to.)





-------------- /etc/auto.changer.sh --------------
#! /bin/sh
#		 /etc/auto.changer.sh

# This is an "executable map" file for autofs - the automounter -
# which allows automounting of different slots of an ATAPI cdrom changer.
#
# To use it,  add a line to /etc/auto.master like this (without the comment!)
# /changer	/etc/auto.changer.sh
#   ^
#   L___  Replace with what mount point you want
# You can the refer to the slots as /changer/NAMEn
# where NAME can be anything you want (including nothing), and 
# n is a number between 1 and the maximum allowed.
# E.g.  /changer/disk2   or  /changer/slot3   or  /changer/1
#

# Richard Sharman <rsharman@magma.ca> Mon Apr  6 00:04:25 1998


# ---- Edit these as appropriate ----
#
DEVICE=/dev/hdd

# Set PROG to the cd-changer program,  and MUST_UNMOUNT to a non-empty
# string unless you are using my modified cdchanger program.
#
#   To use the cdload program in the V2.0 kernel's ide-cd file
# PROG=/usr/local/sbin/cdload
# MUST_UNMOUNT="yes"
# SLOT_ZERO_BASED="yes"
#   To use the change program in the V2.1 kernel's ide-cd file
PROG=/usr/local/sbin/cdchange
MUST_UNMOUNT="yes"
#	To you use my cdchanger,  use these definitions
# PROG="/usr/local/bin/cdchanger -n"
# MUST_UNMOUNT=""

# This is for a 4 slot changer (obviously).
MIN=1
MAX=4
#
# ----------------------------------------

# Comments beginning with ## are all for debugging.

## echo >&2 auto.misc.sh called
if [ $# -ne 1 ] ; then
    echo >&2 $0 should be called with a single parameter
    exit 1
fi

case $1 in
    # this is only needed if you have a changer with > 9 slots!
    # Extract the last two characters of $1
    *[0-9][0-9] )
      SLOT=${1:0-2}
      ;;
    *[0-9] )
      # Extract the last character of $1
      SLOT=${1:0-1}
      ;;
    * )
      echo >& $0: cannot deduce slot number from $1
      exit 1
      ;;
esac

if [ $SLOT -lt $MIN -o $SLOT -gt $MAX ] ; then
    echo >&@ $0 called with bad slot number $SLOT,  should be between $MIN and $MAX
    exit 1
fi

# If you use the standard cdchange (or cdload),  you must unmount the device
# before changing slots.  
if [ "$MUST_UNMOUNT" ] ; then
	mount | grep -q "^$DEVICE" && umount $DEVICE
fi
# I think that some earlier versions of this program numbered from 0
# rather than from 1, so for them subtract 1 from SLOT here.
if [ "$SLOT_ZERO_BASED" ] ; then
	let SLOT=SLOT-1
fi
#
$PROG $DEVICE $SLOT

# If you use my cdchanger,  it will aumotically unmount the device.
# But you must add the -n option (so it doesn't remount it).
#      /usr/local/bin/cdchanger -n $DEVICE $SLOT

if [ $? -eq 0 ] ; then
    # Create the line to be printed to stdout for autofs.
    # The format is the sme as described in autofs(5) except for the
    # first field,  the key,  which must be omiitted.
    LINE="-fstype=iso9660,ro :$DEVICE"
    ## echo >&2 "$0 success,  line is '$LINE'"
    echo $LINE
    rc=0
else
    echo >&2 $PROG was unable to switch to slot $SLOT of $DEVICE
    exit 1
fi
exit $rc
