3
# mountvirtfs Mount all the virtual filesystems the kernel
4
# provides and that are required by default.
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.
11
# This functionality was previously provided by
12
# mountkernfs from the glibc package.
14
# Version: @(#)mountvirtfs 2.85-23 29-Jul-2004 miquels
17
# Script needs to be robust and continue when parts fail,
18
# so we're not setting the "-e" flag.
21
PATH=/lib/init:/bin:/sbin
25
if [ -f /etc/default/devpts ]
31
if [ -f /etc/default/tmpfs ]
40
if [ -d "$1/" ] && [ -w "$1/" ] && touch -a "$1/" 2>/dev/null
55
# Do we support this filesystem type ?
67
elif grep -E -qs "$1\$" /proc/filesystems
70
elif grep -E -qs "$2\$" /proc/filesystems
80
# Get the options from /etc/fstab.
85
exec 9<&0 0</etc/fstab
86
while read FDEV FDIR FTYPE FOPTS REST
93
if [ "$3" != "$FDIR" ] || [ "$TYPE" != "$FTYPE" ]
98
noauto|*,noauto|noauto,*|*,noauto,*)
110
# See if anything is mounted yet
111
if ! mountpoint -q $3
114
mount $MOUNT_N -t $TYPE $OPTS $4 $TYPE $3
116
# Need to update mtab only ?
117
if [ -n "$DO_MTAB" ] &&
118
! grep -E -sq "^([^ ]+) +$3 +" /etc/mtab
120
mount -f -t $TYPE $OPTS $4 $TYPE $3
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.
132
MTAB_PATH="`readlink -f /etc/mtab || :`"
137
if dir_writable ${MTAB_PATH%/*}
145
if [ -n "$DO_MTAB" ] && [ ! -f /etc/mtab ]
150
# Mount standard /proc and /sys.
151
domount proc "" /proc
152
domount sysfs "" /sys
154
# Mount /dev/pts. Create master ptmx node if needed.
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).
160
if [ "$KERNEL" = Linux ]
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
168
if grep -qs '/dev devfs' /proc/mounts
177
if dir_writable /dev && [ ! -c /dev/ptmx ]
179
mknod --mode=666 /dev/ptmx c 5 2
181
domount devpts "" /dev/pts -ogid=$TTYGRP,mode=$TTYMODE
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
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.
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.
203
# Recommendation: always enable CONFIG_TMPFS and always mount
204
# using the tmpfs type. Forget about shmfs.
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.
210
if [ -n "$TMPFS_SIZE" ]
212
tmpfs_opt="-osize=${TMPFS_SIZE}"
214
domount tmpfs shmfs /dev/shm $tmpfs_opt
216
# Mount usbfs/usbdevfs if /proc/bus/usb is present.
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.
225
if [ -d /proc/bus/usb ]
227
domount usbfs usbdevfs /proc/bus/usb