5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
25 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
32 echo "umountall: $1" 1>&2
34 echo "Usage:\n\tumountall [-k] [-s] [-F FSType] [-l|-r] [-Z] [-n]" 1>&2
35 echo "\tumountall [-k] [-s] [-h host] [-Z] [-n]" 1>&2
41 # This script is installed as both /sbin/umountall (as used in some
42 # /sbin/rc? and /etc/init.d scripts) _and_ as /usr/sbin/umountall (typically
43 # PATHed from the command line). As such it should not depend on /usr
44 # being mounted (if /usr is a separate filesystem).
46 # /sbin/sh Bourne shell builtins we use:
54 # /sbin commands we use:
58 # The following /usr based commands may be used by this script (depending on
59 # command line options). We will set our PATH to find them, but where they
60 # are not present (eg, if /usr is not mounted) we will catch references to
61 # them via shell functions conditionally defined after option processing
62 # (don't use any of these commands before then).
64 # Command Command line option and use
65 # /usr/bin/sleep -k, to sleep after an fuser -c -k on the mountpoint
66 # /usr/sbin/fuser -k, to kill processes keeping a mount point busy
68 # In addition, we use /usr/bin/tail if it is available; if not we use
69 # slower shell constructs to reverse a file.
71 PATH
=/sbin
:/usr
/sbin
:/usr
/bin
73 # Clear these in case they were already set in our inherited environment.
88 # Is the passed fstype a "remote" one?
89 # Essentially: /usr/bin/grep "^$1" /etc/dfs/fstypes
91 for t
in $RemoteFSTypes
93 [ "$t" = "$1" ] && return 0
98 # Get list of remote FS types (just once)
99 RemoteFSTypes
=`while read t junk; do echo $t; done < /etc/dfs/fstypes`
103 # Process command line args
105 while getopts ?rslkF
:h
:Zn c
112 h
) if [ -n "$HFLAG" ]; then
113 usage
"more than one host specified"
119 F
) if [ -n "$FFLAG" ]; then
120 usage
"more than one FStype specified"
126 usage
"FSType ${FSType} exceeds 8 characters"
131 # Alias any commands that would perform real actions to
132 # something that tells what action would have been performed
138 : # No need to show where we'd sleep
147 # 1) arguments beyond those supported
148 # 2) can't specify both remote and local
149 # 3) can't specify a host with -r or -l
150 # 4) can't specify a fstype with -h
151 # 5) can't specify this host with -h (checks only uname -n)
152 # 6) can't be fstype nfs and local
153 # 7) only fstype nfs is remote
155 if [ $# -ge $OPTIND ]; then # 1
156 usage
"additional arguments not supported"
159 if [ -n "$RFLAG" -a -n "$LFLAG" ]; then # 2
160 usage
"options -r and -l are incompatible"
163 if [ \
( -n "$RFLAG" -o -n "$LFLAG" \
) -a "$HFLAG" = "h" ]; then # 3
164 usage
"option -${RFLAG}${LFLAG} incompatible with -h option"
167 if [ -n "$FFLAG" -a "$HFLAG" = "h" ]; then # 4
168 usage
"Specifying FStype incompatible with -h option"
171 if [ -n "$HFLAG" -a "$HOST" = "$LOCALNAME" ]; then # 5
172 usage
"Specifying local host illegal for -h option"
175 if [ "$LFLAG" = "l" -a -n "$FSType" ]; then # 6
176 # remote FSType not allowed
177 isremote
"$FSType" &&
178 usage
"option -l and FSType ${FSType} are incompatible"
181 if [ "$RFLAG" = "r" -a -n "$FSType" ]; then # 7
182 # remote FSType required
183 isremote
"$FSType" ||
184 usage
"option -r and FSType ${FSType} are incompatible"
190 # Take advantage of parallel unmounting at this point if we have no
191 # criteria to match and we are in the global zone
193 if [ -z "${SFLAG}${LFLAG}${RFLAG}${HFLAG}${KFLAG}${FFLAG}${ZFLAG}" -a \
194 "$ZONENAME" = "global" ]; then
195 umount
-a ${UMOUNTFLAG}
196 exit # with return code of the umount -a
200 # Catch uses of /usr commands when /usr is not mounted
201 if [ -n "$KFLAG" -a -z "$NFLAG" ]; then
202 if [ ! -x /usr
/sbin
/fuser
]; then
204 echo "umountall: fuser -k skipped (no /usr)" 1>&2
205 # continue - not fatal
208 : # no point in sleeping if fuser is doing nothing
211 if [ ! -x /usr
/bin
/sleep ]; then
213 echo "umountall: sleep after fuser -k skipped (no /usr)" 1>&2
214 # continue - not fatal
221 # Shell function to avoid using /usr/bin/cut. Given a dev from a
222 # fstype=nfs line in mnttab (eg, "host:/export) extract the host
223 # component. The dev string looks like: "host:/path"
232 # Similar for smbfs, but tricky due to the optional parts
233 # of the "device" syntax. The dev strings look like:
234 # "//server/share" or "//user@server/share"
235 print_smbfs_host
() {
247 # doumounts echos its return code to stdout, so commands used within
248 # this function should take care to produce no other output to stdout.
253 while read dev mountp fstype mode dummy
261 /etc
/svc
/volatile | \
268 /tmp
/.libgrubmgmt
* | \
275 # file systems possibly mounted in the kernel or
276 # in the methods of some of the file system
282 if [ -n "$HFLAG" ]; then
284 if [ "$fstype" = "nfs" ]; then
285 thishost
=`print_nfs_host $dev`
287 if [ "$fstype" = "smbfs" ]; then
288 thishost
=`print_smbfs_host $dev`
290 if [ "$HOST" != "$thishost" ]; then
294 if [ -n "$FFLAG" -a "$FSType" != "$fstype" ]; then
298 if [ -n "$LFLAG" ]; then
299 # umount local filesystems
300 isremote
"$fstype" && continue
303 # Note: isremote is true for both nfs & autofs, so
304 # this will filter out autofs mounts with nfs file
305 # system mounted on the top of it.
307 # WARNING: use of any syscall on a NFS file system has
308 # the danger to go over-the-wire and could cause nfs
309 # clients to hang on shutdown, if the nfs server is
311 # For the reason described above, a simple test like
312 # "df -F nfs $mountp" can't be used to filter out
313 # nfs-over-autofs mounts. (isremote works OK)
315 if [ -n "$RFLAG" ]; then
316 # umount remote filesystems
317 isremote
"$fstype" ||
continue
319 if [ "$ZONENAME" != "global" ]; then
320 for option
in `echo $mode | tr , '\012'`; do
322 # should not see any zone options
325 if [ "$option" = "zone=$ZONENAME" ]; then
329 if [ "$option" != "zone=$ZONENAME" ]; then
332 # we are called from the global zone
334 for option
in `echo $mode | tr , '\012'`; do
342 # skip mounts from non-global zones if ZFLAG is not set
343 if [ "$option" = "zone=" -a -z "$ZFLAG" ]; then
346 # skip mounts from the global zone if ZFLAG is set
347 if [ "$option" != "zone=" -a -n "$ZFLAG" ]; then
351 if [ -n "${KFLAG}" ]; then
352 fuser
-c -k $mountp 1>&2
355 if [ -n "$SFLAG" ]; then
356 umount
${UMOUNTFLAG} ${mountp} 1>&2
358 if [ $trc -ne 0 ]; then
362 # We want to umount in parallel
363 fslist
="$fslist $mountp"
368 if [ -n "$fslist" ]; then
369 umount
-a ${UMOUNTFLAG} $fslist 1>&2
371 if [ $trc -ne 0 ]; then
381 # /etc/mnttab has the most recent mounts last. Reverse it so that we
382 # may umount in opposite order to the original mounts.
385 if [ ! -x /usr
/bin
/tail ]; then
389 if [ -n "$REVERSED" ]; then
390 REVERSED
="$line\n$REVERSED"
396 error
=`echo $REVERSED | doumounts`
398 error
=`tail -r $MNTTAB | doumounts`