Typo
[linux_from_scratch_hints.git] / OLD / automount.txt
blobd110243a023247d07ca843f1ddf38a607da83dcc
1 TITLE:          Setting up Automount
2 LFS VERSION:    Any
3 AUTHOR:         R. Cort Tompkins <rtompkin@cs.odu.edu>
4 SPECIAL THANKS TO:
5         Tan Siong Hua <stsh@pd.jaring.my>
7 SYNOPSIS:
8         The mounting and unmounting of removable media is a tedious task, 
9 especially when it needs to be done by unprivileged users.  Automount is a 
10 utility that will automatically unmount specified devices after a given 
11 interval, and then remount them automatically upon subsequent access.  This 
12 makes the mount/unmount process relatively transparent to the end user.  
14 HINT:
15 To get started you'll need a few things:
16 1) Automount support in the kernel.  This is compiled into the kernel by 
17 default unless you explicitly removed it during kernel configuration.  If this 
18 is the case, reconfigure your kernel (i.e. "make menuconfig" in your kernel 
19 source directory) and enable Automount v4 as a built-in feature under the 
20 "File Systems" heading.
22 2) The automount user utilities.  Download the latest version 3 utilities from 
23 ftp://ftp.kernel.org/pub/linux/daemons/autofs (autofs-3.1.7.tar.bz2 at the time
24 of this writing).  Extract this archive and cd into it.  Before compilation
25 and installation, we'll take preemptive action to stop a compile-time error:
27         $ cp modules/lookup_program.c modules/lookup_program.c.old
28         $ sed "s/OPEN_MAX/FOPEN_MAX/" modules/lookup_program.c.old > \ 
29           modules/lookup_program.c
31         $ ./configure --prefix=/usr --sbindir=/sbin
32         $ make
33         $ make install
35 If you look in the sample subdirectory, you'll find rc.autofs, a startup script
36 designed to help automate the automounting process.  Use this if you wish, but 
37 I will give instructions for creating a slightly simpler script which should 
38 help you better understand the workings of automount.
40 First we'll create the script itself, as root:
42 $ cat > /etc/rc.d/init.d/auto_mount << "EOF"
43 #!/bin/bash
44 # Begin /etc/rc.d/init.d/auto_mount
46 # Automount script by Cort Tompkins - rtompkin@cs.odu.edu, derived
47 # from ethnet script by Gerard Beekmans - gerard@linuxfromscratch.org
49 source /etc/rc.d/init.d/functions
51 case "$1" in
52         start)
54         for mountspec in $(/bin/ls /etc/sysconfig/automount-config/*.auto)
55         do
56                 source $mountspec
57                 MOUNT_BASE=${mountspec%.auto}
58                 echo "Starting automount for group ${MOUNT_BASE##*/}  ..."
59                 /sbin/automount --timeout=${TIMEOUT} $MOUNTPOINT file \
60                 $MOUNT_BASE.map
61                 evaluate_retval
62         done
63         ;;
64         
65         # assume all instances of automount were started by this script
66         stop)
67                 echo -n "Stopping automount ..."
68                 # Unmount everything mounted by automount
69                 /bin/killall -USR1 automount
70                 /bin/killall automount
71                 evaluate_retval
72                 ;;
73         restart)
74                 $0 stop
75                 sleep 1
76                 $0 start
77                 ;;
78         *)
79                 echo "Usage: $0 {start|stop|restart}"
80                 exit 1
81                 ;;
82 esac
83 # End /etc/rc.d/init.d/auto_mount
84 EOF
86 Please resist the temptation to name the startup script "automount."  This
87 means that the script will get the same kill signals we send to automount
88 proper.
90 Give the script proper permissions:
91 $ chmod 754 /etc/rc.d/init.d/auto_mount
93 Since I use automount for network shares, I only want it to be running when
94 in a networkable state.  On the very rare occasion that you find yourself in
95 an unnetworked runlevel, you can always mount your removable devices manually.
96 $ cd /etc/rc.d
97 $ for rl in $(seq 0 2; echo 6); do
98   > cd rc${rl}.d 
99   > ln -s ../init.d/auto_mount K45auto_mount
100   > cd ..
101   > done
102 $ for rl in $(seq 3 5); do
103   > cd rc${rl}.d
104   > ln -s ../init.d/auto_mount S25auto_mount
105   > cd ..
106   > done
108 Create the sysconfig directory that the script will use:
109 $ mkdir /etc/sysconfig/automount-config
111 Inside /etc/sysconfig/automount-config/, you'll create pairs of files for each 
112 group of devices you wish to automount.  The format of the files is as follows:
114 xxxx.auto:
115 MOUNTPOINT=/path/to/mountdir
116 TIMEOUT=999
118 xxxx.map:
119 MOUNTNAME       -fstype=FSTYPE[,OPTIONS]        :/path/to/device
120 MOUNTNAME       -fstype=FSTYPE[,OPTIONS]        :/path/to/device
122 DO NOT create the "MOUNTNAME" directory under the "MOUNTPOINT" yourself.
123 Automount will create and remove this directory as needed.
125 The format of the .auto files is arbitrarily determined by the workings of the 
126 auto_mount script; more information on the format of the .map files can be 
127 found using "man 5 autofs".  The OPTIONS used in the .map file are the same 
128 options you would pass to mount with the -o flag.  Note that you can have 
129 multiple entries in a .map file, but they will all assume the same mountpoint 
130 and timeout specified in the corresponding .auto file of the same prefix.  The 
131 auto_mount script can handle any number of .map/.auto pairs (so long as the 
132 pairs both have the same prefix).  Here are some examples:
135 cdrom.auto:
136 MOUNTPOINT=/mnt
137 TIMEOUT=5
139 cdrom.map:
140 cd      -fstype=iso9660,ro      :/dev/cdrom
142 The above pair will automount /dev/cdrom at /mnt/cd with a timeout of 5 
143 seconds.  This means that after five seconds of inactivity the cdrom device will
144 be automatically unmounted, allowing you to put in a new CD to be automatically
145 remounted upon subsequent access.  You can verify this after initializing
146 automount:
148 $ ls /mnt/cd; mount
150 You will see that the cdrom is mounted. Wait five seconds.
152 $ mount
154 If everything is working properly, automount will have unmounted the cdrom.
155 Subsequent access to /mnt/cd will cause it to be remounted.
157 Most CD drives lock their CD trays while mounted, preventing you from removing 
158 the media while the drive is mounted.  Floppy drives, on the other hand, have 
159 no such protection; it is best to keep their timeout value as small as possible:
161 floppy.auto:
162 MOUNTPOINT=/mnt
163 TIMEOUT=1
165 floppy.map:
166 flop    -fstype=auto    :/dev/fd0
168 This mounts the floppy drive at /mnt/flop.  Note that a timeout of 0 will 
169 disable the automatic unmounting altogether.  
171 Automount can also be used to mount network shares:
173 samba.auto:
174 MOUNTPOINT=/smb/win2kbox
175 TIMEOUT=300
177 samba.map:
178 c -fstype=smbfs,username=samba,password=xxxx    ://win2kbox/c
179 d -fstype=smbfs,username=samba,password=xxxx    ://win2kbox/d
181 The two samba shares specified will be automounted at /smb/win2kbox/c and 
182 /smb/win2kbox/d
184 One final note of caution (from the autofs man page):
186 UNSUPPORTED:
187    The  automounter  does  not  support  direct  maps or mount
188    trees (more than one file system to be mounted under a spe-
189    cific automount point)...
191 This (unfortunately) means that you can't have separate 
192 .auto/.map pairs with the same MOUNTPOINT.  Thus, the individual
193 floppy and cdrom examples used above cannot be used together!  The
194 best alternative in this case is to combine them into one file pair:
197 removables.auto:
198 MOUNTPOINT=/mnt
199 TIMEOUT=1
201 removable.map:
202 cd      -fstype=iso9660,ro      :/dev/cdrom
203 flop    -fstype=auto    :/dev/fd0
206 The more adventurous among you may also consider compiling and 
207 installing automount v4 (beta). Its compilation and installation 
208 is virtually identical to that outlined above, with the 
209 exception of the patching of lookup_module.c (the first block of 
210 commands).  Upgrading is as simple as:
212         $ tar xvfj autofs-4.0.0pre10.tar.bz2
213         $ cd autofs-4.0.0pre10
214         $ ./configure --prefix=/usr --sbindir=/sbin && make &&
215           make install
216         $ /etc/rc.d/init.d/auto_mount restart
218 Feel free to e-mail me with questions or suggestions.