~ubuntu-branches/debian/experimental/sysvinit/experimental

« back to all changes in this revision

Viewing changes to debian/initscripts/etc/init.d/mountvirtfs

  • Committer: Bazaar Package Importer
  • Author(s): Petter Reinholdtsen
  • Date: 2008-08-12 16:07:50 UTC
  • Revision ID: james.westby@ubuntu.com-20080812160750-65gpyv74vh4qr69w
Tags: 2.86.ds1-61
* Fix typo in rcS(5), proberly->properly (Closes: #484233).  Thanks to
  Julien Danjou for noticing.
* Fix typo in rcS(5), maually->manually (Closes: #493680).  Thanks to
  Xr for noticing.
* Modify runlevel detection code in invoke-rc.d to notice the
  difference between runlevels 0 and 6, and the boot runlevel, to
  make it possible to use invoke-rc.d during boot (Closes: 384509).
* Make sure to call restorecon after mounting tmpfs file systems, to
  set SELinux permissions (Closes: #493679).  Patch from Russell
  Coker.
* Move responsibility of stopping the splash screen process from
  individual init.d scripts to init.d/rc.  This make sure the
  progress calculation reflect reality, and that the splash screen
  is taken down in runlevel 1 (Closes: #431560) and that it stop
  before gdm and kdm (Closes: #422922, #489734).
* Skip error message from checkfs.sh when / is read-only.  Patch
  from Mirek Slugen (Closes: #492214).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
#
3
 
# mountvirtfs   Mount all the virtual filesystems the kernel
4
 
#               provides and that are required by default.
5
 
#
6
 
#               This script can be called several times without
7
 
#               damage; it tries to mount the virtual filesystems
8
 
#               only if not mounted yet, and only updates /etc/mtab
9
 
#               if it is writable and there is a need to.
10
 
#
11
 
#               This functionality was previously provided by
12
 
#               mountkernfs from the glibc package.
13
 
#
14
 
# Version:      @(#)mountvirtfs  2.85-23  29-Jul-2004  miquels
15
 
#
16
 
 
17
 
# Script needs to be robust and continue when parts fail,
18
 
# so we're not setting the "-e" flag.
19
 
#set -e
20
 
 
21
 
PATH=/lib/init:/bin:/sbin
22
 
 
23
 
TTYGRP=5
24
 
TTYMODE=620
25
 
if [ -f /etc/default/devpts ]
26
 
then
27
 
        . /etc/default/devpts
28
 
fi
29
 
 
30
 
TMPFS_SIZE=
31
 
if [ -f /etc/default/tmpfs ]
32
 
then
33
 
        . /etc/default/tmpfs
34
 
fi
35
 
 
36
 
KERNEL=`uname -s`
37
 
umask 022
38
 
 
39
 
dir_writable () {
40
 
        if [ -d "$1/" ] && [ -w "$1/" ] && touch -a "$1/" 2>/dev/null
41
 
        then
42
 
                return 0
43
 
        fi
44
 
        return 1
45
 
}
46
 
 
47
 
domount () {
48
 
 
49
 
        # Directory present ?
50
 
        if [ ! -d $3 ]
51
 
        then
52
 
                return
53
 
        fi
54
 
 
55
 
        # Do we support this filesystem type ?
56
 
        TYPE=
57
 
        if [ $1 = proc ]
58
 
        then
59
 
                case "$KERNEL" in
60
 
                        Linux|GNU)
61
 
                                TYPE=proc
62
 
                                ;;
63
 
                        *)
64
 
                                TYPE=procfs
65
 
                                ;;
66
 
                esac
67
 
        elif grep -E -qs "$1\$" /proc/filesystems
68
 
        then
69
 
                TYPE=$1
70
 
        elif grep -E -qs "$2\$" /proc/filesystems
71
 
        then
72
 
                TYPE=$2
73
 
        fi
74
 
        if [ "$TYPE" = "" ]
75
 
        then
76
 
                return
77
 
        fi
78
 
 
79
 
        #
80
 
        #       Get the options from /etc/fstab.
81
 
        #
82
 
        OPTS=
83
 
        if [ -f /etc/fstab ]
84
 
        then
85
 
                exec 9<&0 0</etc/fstab
86
 
                while read FDEV FDIR FTYPE FOPTS REST
87
 
                do
88
 
                        case "$FDEV" in
89
 
                                ""|\#*)
90
 
                                        continue
91
 
                                        ;;
92
 
                        esac
93
 
                        if [ "$3" != "$FDIR" ] || [ "$TYPE" != "$FTYPE" ]
94
 
                        then
95
 
                                continue
96
 
                        fi
97
 
                        case "$FOPTS" in
98
 
                                noauto|*,noauto|noauto,*|*,noauto,*)
99
 
                                        return
100
 
                                        ;;
101
 
                                ?*)
102
 
                                        OPTS="-o$FOPTS"
103
 
                                        ;;
104
 
                        esac
105
 
                        break
106
 
                done
107
 
                exec 0<&9 9<&-
108
 
        fi
109
 
 
110
 
        # See if anything is mounted yet
111
 
        if ! mountpoint -q $3
112
 
        then
113
 
                # No, do it now
114
 
                mount $MOUNT_N -t $TYPE $OPTS $4 $TYPE $3
115
 
        else
116
 
                # Need to update mtab only ?
117
 
                if [ -n "$DO_MTAB" ] &&
118
 
                   ! grep -E -sq "^([^ ]+) +$3 +" /etc/mtab
119
 
                then
120
 
                                mount -f -t $TYPE $OPTS $4 $TYPE $3
121
 
                fi
122
 
        fi
123
 
}
124
 
 
125
 
#
126
 
#       We only create/modify /etc/mtab if the location where it is
127
 
#       stored is writable.  If /etc/mtab is a symlink into /proc/
128
 
#       then it is not writable.
129
 
#
130
 
DO_MTAB=
131
 
MOUNT_N=-n
132
 
MTAB_PATH="`readlink -f /etc/mtab || :`"
133
 
case "$MTAB_PATH" in
134
 
        /proc/*)
135
 
                ;;
136
 
        /*)
137
 
                if dir_writable ${MTAB_PATH%/*}
138
 
                then
139
 
                        DO_MTAB=Yes
140
 
                        MOUNT_N=
141
 
                fi
142
 
                ;;
143
 
esac
144
 
 
145
 
if [ -n "$DO_MTAB" ] && [ ! -f /etc/mtab ]
146
 
then
147
 
        :> /etc/mtab
148
 
fi
149
 
 
150
 
# Mount standard /proc and /sys.
151
 
domount proc "" /proc
152
 
domount sysfs "" /sys
153
 
 
154
 
# Mount /dev/pts. Create master ptmx node if needed.
155
 
#
156
 
# As of 2.5.68, devpts is not automounted when using devfs. So we
157
 
# mount devpts if it is compiled in (older devfs didn't require it
158
 
# to be compiled in at all).
159
 
#
160
 
if [ "$KERNEL" = Linux ]
161
 
then
162
 
        #
163
 
        #       Since kernel 2.5.something, devfs doesn't include
164
 
        #       a standard /dev/pts directory anymore. So if devfs
165
 
        #       is mounted on /dev we need to create that directory
166
 
        #       manually.
167
 
        #
168
 
        if grep -qs '/dev devfs' /proc/mounts
169
 
        then
170
 
                if [ ! -d /dev/pts ]
171
 
                then
172
 
                        mkdir /dev/pts
173
 
                fi
174
 
        fi
175
 
        if [ -d /dev/pts ]
176
 
        then
177
 
                if dir_writable /dev && [ ! -c /dev/ptmx ]
178
 
                then
179
 
                        mknod --mode=666 /dev/ptmx c 5 2
180
 
                fi
181
 
                domount devpts "" /dev/pts -ogid=$TTYGRP,mode=$TTYMODE
182
 
        fi
183
 
fi
184
 
 
185
 
# Mount tmpfs.
186
 
#
187
 
# Around kernel version 2.3.3x, a memory based filesystem was
188
 
# introduced to support POSIX shared memory, called shmfs. 
189
 
# Later this filesystem was extended for general usage -
190
 
# provided you set the CONFIG_TMPFS compile option and mount
191
 
# it as type tmpfs.
192
 
#
193
 
# Early in the 2.4 kernel series, shmfs was renamed to tmpfs, but
194
 
# you could mount it using both type shmfs and tmpfs. Starting
195
 
# at kernel version 2.5.44, the shmfs alias was dropped.
196
 
#
197
 
# Confusingly, in kernels 2.3.x - 2.5.43 where both shmfs and
198
 
# tmpfs are present, disabling CONFIG_TMPFS actually removes
199
 
# support for shmfs, but tmpfs is still listed in /proc/filesystems
200
 
# to support SYSV and POSIX shared memory, and it should still be
201
 
# mounted under /dev/shm.
202
 
#
203
 
# Recommendation: always enable CONFIG_TMPFS and always mount
204
 
# using the tmpfs type. Forget about shmfs.
205
 
206
 
# Tmpfs can be used as memory filesystem, so you can limit tmpfs
207
 
# max size using /etc/default/tmpfs to prevent tmpfs from using
208
 
# up all system memory.
209
 
#
210
 
if [ -n "$TMPFS_SIZE" ]
211
 
then
212
 
        tmpfs_opt="-osize=${TMPFS_SIZE}"
213
 
fi
214
 
domount tmpfs shmfs /dev/shm $tmpfs_opt
215
 
 
216
 
# Mount usbfs/usbdevfs if /proc/bus/usb is present.
217
 
#
218
 
# Usbfs/usbdevfs is used for USB related binaries/libraries.
219
 
# "usbfs" and "usbdevfs" are the exact same filesystem.
220
 
# "usbdevfs" was renamed to "usbfs" by linux usb developers,
221
 
# because people sometimes mistook it as a part of devfs. Usbfs
222
 
# will be superseded by other filesystems (e.g. sysfs), and when
223
 
# it becomes obsolete the mount action below should be removed.
224
 
#
225
 
if [ -d /proc/bus/usb ]
226
 
then
227
 
        domount usbfs usbdevfs /proc/bus/usb
228
 
fi
229