On Fri, Apr 22, 2011 at 07:27:00PM +0100, Roger Leigh wrote: > On Sun, Apr 17, 2011 at 07:21:56AM +1000, Kel Modderman wrote: > > On Sun, 17 Apr 2011 02:06:50 AM Roger Leigh wrote: > > > Done. The diff to sync svn with the uploaded NMU is attached. I stupidly > > > didn't sync with svn for the upload, so I uploaded a second time with the > > > svn changes synched, which is why there's a second revision in the > > > attached diff. > > > > Applied the diff. Also applied one more patch to svn, so please do sync with > > that before further /run fixups. > > Hi Kel and other sysvinit developers, > > I've attached a further update for your consideration, which fixes a > few issues. If it's OK with you, this could be uploaded to > experimental (with your changes folded into the same version in the > changelog) as 2.88dsf-13.5. Unless you'd prefer to do a maintainer > upload. > > The logic used for mounting filesystems is duplicated entirely between > the various scripts doing mounting, and the mtab script used to > generate the initial mtab. This includes the domtab() function, which > is almost entirely identical to domount() with the use of -f with mount. > This patch removes the duplication, and uses the same codepaths for > both mounting and mtab generation, which will make the scripts much > more robust when making any changes. > > The reason for doing this was principally to allow for /remounting/ of > already mounted filesystems so that filesystems mounted in the > initramfs and subsequently moved onto the rootfs could be made to > use the mount options specified in /etc/fstab (and /etc/default/tmpfs, > where applicable). This means that all filesystems mounted by the > initramfs are entirely user-configurable, so mount options and policies > are not hardcoded in the initramfs. I also added remount/reload > argument support to mountkernfs/mountdevsubfs which means you can edit > /etc/defaults/* and/or /etc/fstab and then reload to make those changes > active. > > Other than that, we create relative rather than absolute symlinks, and > I've made the error checking and other parts of the scripts more > robust. > > Other than these changes, I'm not aware of anything outstanding in > initscripts needing changes to support /run. The symlinks neeed > making relative, and while I did the mount changes to allow for a > clean handover from the initramfs-mounted /run to the real system > so our configuration would still get applied, this is a general > change which applies to all initramfs-mounted filesystems via > creation of a suitable entry in /etc/fstab.
Patch now actually attached... -- .''`. Roger Leigh : :' : Debian GNU/Linux http://people.debian.org/~rleigh/ `. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/ `- GPG Public Key: 0x25BFB848 Please GPG sign your mail.
diff --git a/debian/changelog b/debian/changelog index bd28bab..1ec96fa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,40 @@ +sysvinit (2.88dsf-13.5) UNRELEASED; urgency=low + + [ Roger Leigh ] + * Non-maintainer upload. + * Unify mount logic shared between mountkernfs.sh, mountdevsubfs.sh + and mtab.sh + - all functions use domount() from /lib/init/mount-functions. This + merges in the functionality of domtab() in mtab.sh, which was + almost entirely identical. domount is now capable of mounting and + remounting (with and without mtab updates) as well as updating + /etc/mtab. + - mtab.sh calls mountkernfs.sh and mountdevsubfs with an "mtab" + argument to do the mtab generation for early mounts. This means + that the mount logic is not needlessly duplicated, and does not + require two copies to be kept exactly in sync. This reduces the + risk of problems as a consequence of subtle differences between + the two scripts. + - mount options may be specified in either /etc/default/tmpfs or + in /etc/fstab, and will supersede hard coded defaults. The + the values in fstab (if any) will supersede those in + /etc/default/tmpfs should an entry be present. These values are + also used for remounting, which means that filesystems mounted in + an initramfs and moved onto the root filesystem prior to init + starting will be remounted with the correct user-specified + options. + - Improve robustness of stat checks when comparing directories. + - mountkernfs.sh and mountdevsubfs.sh are idempotent, so allow for + repeated invocation. This is needed to allow the same code to + be used for mounting, remounting and mtab generation. + * Compatibility symbolic links are relative, not absolute. e.g. + /var/lock is ../run/lock rather than /run/lock. This means that if + you're using a chroot from the host system, you'll always be using + locations in the chroot, rather than the host, when following the + links. + + -- Roger Leigh <[email protected]> Fri, 22 Apr 2011 15:25:25 +0100 + sysvinit (2.88dsf-14) UNRELEASED; urgency=low * Consider rpcbind as alternative to portmap in mountnfs ifupdown diff --git a/debian/initscripts.postinst b/debian/initscripts.postinst index abb37c7..b395ee5 100755 --- a/debian/initscripts.postinst +++ b/debian/initscripts.postinst @@ -48,6 +48,9 @@ guest_environment() { return 0 } +# If the device/inode are the same, a bind mount already exists or the +# transition is complete, so set up is not required. Otherwise bind +# mount $SRC on $DEST. bind_mount () { SRC=$1 @@ -56,6 +59,9 @@ bind_mount () FSTYPE="" OPTS="" + ssrc="$(/usr/bin/stat -L --format="%d %i" "$SRC" 2>/dev/null || :)" + sdest="$(/usr/bin/stat -L --format="%d %i" "$DEST" 2>/dev/null || :)" + case "$(uname -s)" in Linux) FSTYPE=$SRC; OPTS="-orw -obind" ;; *FreeBSD) FSTYPE=nullfs; OPTS="-orw" ;; @@ -64,21 +70,30 @@ bind_mount () esac # Bind mount $SRC on $DEST - if mount -t $FSTYPE "$SRC" "$DEST" $OPTS ; then - return 0 + if [ -n "$ssrc" ] && [ "$ssrc" != "$sdest" ]; then + [ -d "$DEST" ] || mkdir "$DEST" + if mount -t $FSTYPE "$SRC" "$DEST" $OPTS ; then + return 0 + fi + return 1 fi - return 1 + return 0 } compat_link () { SRC=$1 DEST=$2 - echo "guest environment detected: Linking $DEST to $SRC" - ( rm -fr $DEST && - ln -fs $SRC $DEST) || - { echo "Can't symlink $DEST to $SRC; please fix manually."; return 1; } + ssrc="$(/usr/bin/stat -L --format="%d %i" "$SRC" 2>/dev/null || :)" + sdest="$(/usr/bin/stat -L --format="%d %i" "$DEST" 2>/dev/null || :)" + + if [ -n "$ssrc" ] && [ "$ssrc" != "$sdest" ]; then + echo "guest environment detected: Linking $DEST to $SRC" + ( rm -fr $DEST && + ln -fs $SRC $DEST) || + { echo "Can't symlink $DEST to $SRC; please fix manually."; return 1; } + fi return 0 } @@ -164,7 +179,7 @@ update-rc.d stop-bootlogd start 99 2 3 4 5 . >/dev/null || exit $? # # Remove scripts that were left behind by older glibc (<< 2.3.2.ds1-12) -# versions. We have the same functionality in mount{kern,devsub}fs.sh +# versions. We have the same functionality in mount{kern,devsub}fs.sh # # # In 2.86.ds1-10 the "mountvirtfs" script was replaced by @@ -187,14 +202,6 @@ done # without a system restart. # -# Device and inode of directories: -svarrun="$(/usr/bin/stat -L --format="%d %i" /var/run)" -svarlock="$(/usr/bin/stat -L --format="%d %i" /var/lock)" -sdevshm="$(/usr/bin/stat -L --format="%d %i" /dev/shm)" -# May not exist yet -srun="$(/usr/bin/stat -L --format="%d %i" /run 2>/dev/null || :)" -srunlock="$(/usr/bin/stat -L --format="%d %i" /run/lock 2>/dev/null || :)" -srunshm="$(/usr/bin/stat -L --format="%d %i" /run/shm 2>/dev/null || :)" # If in a chroot or vserver environment (i.e. a guest, which does not # run rcS scripts), do not do any messing around with mounts, and # don't migrate /var/run, /var/lock or /dev/shm. Bind mounting would @@ -206,57 +213,24 @@ srunshm="$(/usr/bin/stat -L --format="%d %i" /run/shm 2>/dev/null || :)" # locations and create compatibilty symlinks at their convenience # following the upgrade. if guest_environment; then - if [ ! -f /run/.ramfs ] && [ "$svarrun" != "$srun" ]; then - # Symlink /var/run from /run - if compat_link /var/run /run; then - # Symlink /var/lock from /run/lock - if [ "$svarlock" != "$srunlock" ]; then - compat_link /var/lock /run/lock - fi - - # Symlink /dev/shm from /run/shm - if [ "$sdevshm" != "$srunshm" ]; then - compat_link /dev/shm /run/shm - fi - fi + # Symlink /var/run from /run + # Note var/run is relative + if compat_link var/run /run; then + # Symlink /var/lock from /run/lock + # Note that it's really /var/run/lock + compat_link ../../var/lock /run/lock + + # Symlink /dev/shm from /run/shm + # Note that it's really /var/run/shm + compat_link ../../dev/shm /run/shm fi -# Not a chroot. If /run/.run-transition does not exist then -# skip. /run/.run-transition should not exist either before -# or after the transition. This file is used to ensure we -# don't perform the initial migration more than once if -# initscripts is upgraded again before a system restart (and -# hence transition completion). -elif [ ! -f /run/.run-transition ]; then - # If /run/.ramfs exists, then a ramfs already exists, - # and we assume it's all set up correctly. If the - # device/inode are the same, it's not set up entirely - # correctly, but a bind mount already exists for some - # reason, so again assume set up is not required. - if [ ! -f /run/.ramfs ] && [ "$svarrun" != "$srun" ]; then - # Bind mount /var/run on /run - if bind_mount /var/run /run; then - # Bind mount /var/lock on /run/lock - [ -d /run/lock ] || mkdir /run/lock - if [ "$svarlock" != "$srunlock" ]; then - bind_mount /var/lock /run/lock - fi - - # Bind mount /dev/shm on /run/shm - [ -d /run/shm ] || mkdir /run/shm - if [ "$sdevshm" != "$srunshm" ]; then - bind_mount /dev/shm /run/shm - fi - fi +# Host system, not a chroot. +else + if bind_mount /var/run /run; then + bind_mount /var/lock /run/lock + bind_mount /dev/shm /run/shm fi - # Create a /run/.run-transition stamp file. This is - # to ensure we don't repeat the above setup if the - # package is upgraded again prior to a system reboot. - # On reboot, it will be deleted by the init scripts - # and the transition will be completed. This means - # the transition will complete at the sysadmin's - # convenience, since the system will function - # identically before and after a reboot. echo "Please reboot to complete migration to tmpfs-based /run" > /run/.run-transition fi diff --git a/debian/src/initscripts/etc/default/tmpfs b/debian/src/initscripts/etc/default/tmpfs index b3303ad..c43699a 100644 --- a/debian/src/initscripts/etc/default/tmpfs +++ b/debian/src/initscripts/etc/default/tmpfs @@ -5,6 +5,15 @@ # filesystems can use. The size will be rounded down to a multiple of # the page size, 4096 bytes. If no size is set, TMPFS_SIZE will be # used as the default. +# +# Note that more complex mount options may be used by the creation of a +# suitable entry in /etc/fstab. For example: +# tmpfs /run tmpfs size=10% 0 0 +# is equivalent to RUN_SIZE=10%, and will override the RUN_SIZE +# setting. This will allow additional options such as nr_blocks and +# nr_inodes to be used, and also adjustment of the mode, nodev, +# nosuid, noexec options should any change from the defaults be +# necessary. # TMPFS_SIZE: maximum size for all tmpfs filesystems if no specific # size is provided. If no value is provided here, the kernel default @@ -20,13 +29,13 @@ TMPFS_SIZE=20% # is hundreds of KiB, maximum is tens of MiB. RUN_SIZE=10% -# LOCK_SIZE: maximum size of /run/lock (/var/lock) +# LOCK_SIZE: maximum size of /run/lock (was previously /var/lock) # # Typical usage: tens of KiB; maximum hundreds of KiB. Default of # 5MiB should ensure the limit is never reached. LOCK_SIZE=5242880 # 5MiB -# SHM_SIZE: maximum size of /run/shm (/dev/shm) +# SHM_SIZE: maximum size of /run/shm (was previously /dev/shm) # # No default size; the size required varies widely depending upon the # demands of the software being run. diff --git a/debian/src/initscripts/etc/init.d/mountdevsubfs.sh b/debian/src/initscripts/etc/init.d/mountdevsubfs.sh index 18f1c45..48c6cff 100755 --- a/debian/src/initscripts/etc/init.d/mountdevsubfs.sh +++ b/debian/src/initscripts/etc/init.d/mountdevsubfs.sh @@ -27,29 +27,31 @@ KERNEL="$(uname -s)" . /lib/lsb/init-functions . /lib/init/mount-functions.sh +# May be run several times, so must be idempotent. +# $1: Mount mode, to allow for remounting and mtab updating +mount_filesystems () { + MNTMODE="$1" -do_start () { - # # Mount a tmpfs on /run/shm - # if [ ! -d /run/shm ] then mkdir --mode=755 /run/shm [ -x /sbin/restorecon ] && /sbin/restorecon /run/shm fi - SHM_OPT= - [ "${SHM_SIZE:=$TMPFS_SIZE}" ] && SHM_OPT=",size=$SHM_SIZE" - [ "${SHM_MODE:=$TMPFS_MODE}" ] && SHM_OPT="$SHM_OPT,mode=$SHM_MODE" if [ yes = "$RAMSHM" ] ; then - domount tmpfs shmfs /run/shm tmpfs "-onosuid,nodev$SHM_OPT" + domount "$MNTMODE" tmpfs shmfs /run/shm tmpfs "-onosuid,nodev$SHM_OPT" else chmod "$SHM_MODE" /run/shm fi + # Migrate early, so /dev/shm is available from the start + + if [ "$MNTMODE" = mount_noupdate ] || [ "$MNTMODE" = mount_noupdate ] + then + run_migrate /dev/shm /run/shm ../run/shm + fi - # # Mount /dev/pts - # if [ "$KERNEL" = Linux ] then if [ ! -d /dev/pts ] @@ -57,21 +59,23 @@ do_start () { mkdir --mode=755 /dev/pts [ -x /sbin/restorecon ] && /sbin/restorecon /dev/pts fi - domount devpts "" /dev/pts devpts "-onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE" + domount "$MNTMODE" devpts "" /dev/pts devpts "-onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE" fi } case "$1" in "") echo "Warning: mountdevsubfs should be called with the 'start' argument." >&2 - do_start + mount_filesystems mount_noupdate ;; start) - do_start + mount_filesystems mount_noupdate + ;; + mtab) + mount_filesystems mtab ;; restart|reload|force-reload) - echo "Error: argument '$1' not supported" >&2 - exit 3 + mount_filesystems remount ;; stop) # No-op diff --git a/debian/src/initscripts/etc/init.d/mountkernfs.sh b/debian/src/initscripts/etc/init.d/mountkernfs.sh index 2525108..cba0594 100755 --- a/debian/src/initscripts/etc/init.d/mountkernfs.sh +++ b/debian/src/initscripts/etc/init.d/mountkernfs.sh @@ -18,7 +18,11 @@ PATH=/sbin:/bin . /lib/lsb/init-functions . /lib/init/mount-functions.sh -do_start () { +# May be run several times, so must be idempotent. +# $1: Mount mode, to allow for remounting and mtab updating +mount_filesystems () { + MNTMODE="$1" + # Needed to determine if root is being mounted read-only. read_fstab @@ -26,34 +30,25 @@ do_start () { # Get some writable area available before the root is checked # and remounted. # - RW_OPT= - [ "${RW_SIZE:=$TMPFS_SIZE}" ] && RW_OPT=",size=$RW_SIZE" - [ "${RW_MODE:=$TMPFS_MODE}" ] && RW_OPT="$RW_OPT,mode=$RW_MODE" - domount tmpfs shmfs /lib/init/rw tmpfs "-onosuid$RW_OPT" - touch /lib/init/rw/.ramfs - - RUN_OPT= - [ "${RUN_SIZE:=$TMPFS_SIZE}" ] && RUN_OPT=",size=$RUN_SIZE" - [ "${RUN_MODE:=$TMPFS_MODE}" ] && RUN_OPT="$RUN_OPT,mode=$RUN_MODE" - domount tmpfs shmfs /run tmpfs "-onosuid$RUN_OPT" - touch /run/.ramfs + domount "$MNTMODE" tmpfs shmfs /lib/init/rw tmpfs "-onosuid$RW_OPT" + [ -f /lib/init/rw/.ramfs ] || touch /lib/init/rw/.ramfs + + domount "$MNTMODE" tmpfs shmfs /run tmpfs "-onosuid$RUN_OPT" + [ -f /run/.ramfs ] || touch /run/.ramfs # Make lock directory as the replacement for /var/lock - mkdir --mode=755 /run/lock + [ -d /run/lock ] || mkdir --mode=755 /run/lock # Mount /run/lock as tmpfs if enabled. This prevents user DoS # of /run by filling /run/lock at the expense of using an # additional tmpfs. - LOCK_OPT= - [ "${LOCK_SIZE:=$TMPFS_SIZE}" ] && LOCK_OPT=",size=$LOCK_SIZE" - [ "${LOCK_MODE:=$TMPFS_MODE}" ] && LOCK_OPT="$LOCK_OPT,mode=$LOCK_MODE" if [ yes = "$RAMLOCK" ] ; then - domount tmpfs shmfs /run/lock tmpfs "-onodev,noexec,nosuid$LOCK_OPT" + domount "$MNTMODE" tmpfs shmfs /run/lock tmpfs "-onodev,noexec,nosuid$LOCK_OPT" else chmod "$LOCK_MODE" /run/lock fi - touch /run/lock/.ramfs + [ -f /run/lock/.ramfs ] || touch /run/lock/.ramfs # If /tmp is a symlink, make sure the linked-to directory exists. if [ -L /tmp ] && [ ! -d /tmp ]; then @@ -64,7 +59,7 @@ do_start () { # If root is read only, default to mounting a tmpfs on /tmp, # unless one is due to be mounted from fstab. if [ rw != "$rootmode" ]; then - if will_mount /tmp ; then + if read_fstab_entry /tmp ; then : else RAMTMP="yes" @@ -72,13 +67,11 @@ do_start () { fi # Mount /tmp as tmpfs if enabled. - TMP_OPT= - [ "${TMP_SIZE:=$TMPFS_SIZE}" ] && TMP_OPT=",size=$TMP_SIZE" - [ "${TMP_MODE:=$TMPFS_MODE}" ] && TMP_OPT="$TMP_OPT,mode=$TMP_MODE" if [ yes = "$RAMTMP" ] ; then - domount tmpfs shmfs /tmp tmpfs "-onodev,nosuid$TMP_OPT" + domount "$MNTMODE" tmpfs shmfs /tmp tmpfs "-onodev,nosuid$TMP_OPT" else - if [ rw = "$rootmode" ]; then + # When root is still read only, this will fail. + if [ mount_noupdate != "$MNTMODE" ] && [ rw = "$rootmode" ]; then chmod "$TMP_MODE" /tmp fi fi @@ -87,13 +80,13 @@ do_start () { # Note: /run transition: Move from /lib/init/rw to /run. # /lib/init/rw will be removed following transition of # /lib/init/rw users to /run. - mkdir --mode=755 /lib/init/rw/sendsigs.omit.d/ - mkdir --mode=755 /run/sendsigs.omit.d/ + [ -d /lib/init/rw/sendsigs.omit.d ] || mkdir --mode=755 /lib/init/rw/sendsigs.omit.d/ + [ -d /run/sendsigs.omit.d ] || mkdir --mode=755 /run/sendsigs.omit.d/ # # Mount proc filesystem on /proc # - domount proc "" /proc proc "-onodev,noexec,nosuid" + domount "$MNTMODE" proc "" /proc proc "-onodev,noexec,nosuid" # # Mount sysfs on /sys @@ -101,21 +94,23 @@ do_start () { # Only mount sysfs if it is supported (kernel >= 2.6) if grep -E -qs "sysfs\$" /proc/filesystems then - domount sysfs "" /sys sysfs "-onodev,noexec,nosuid" + domount "$MNTMODE" sysfs "" /sys sysfs "-onodev,noexec,nosuid" fi } case "$1" in "") echo "Warning: mountkernfs should be called with the 'start' argument." >&2 - do_start + mount_filesystems mount_noupdate ;; start) - do_start + mount_filesystems mount_noupdate + ;; + mtab) + mount_filesystems mtab ;; restart|reload|force-reload) - echo "Error: argument '$1' not supported" >&2 - exit 3 + mount_filesystems remount ;; stop) # No-op diff --git a/debian/src/initscripts/etc/init.d/mtab.sh b/debian/src/initscripts/etc/init.d/mtab.sh index 1ee9396..18c9bc7 100644 --- a/debian/src/initscripts/etc/init.d/mtab.sh +++ b/debian/src/initscripts/etc/init.d/mtab.sh @@ -29,109 +29,6 @@ KERNEL="$(uname -s)" . /lib/lsb/init-functions . /lib/init/mount-functions.sh -# Note any changes here must also be made in domount in mount-functions. -# $1: file system type -# $2: alternative file system type (or empty string if none) -# $3: mount point -# $4: mount device name -# $5... : extra mount program options -domtab () -{ - MTPT="$3" - KERNEL="$(uname -s)" - # Figure out filesystem type - FSTYPE= - OPTS= - if [ "$1" = proc ] - then - case "$KERNEL" in - Linux|GNU) FSTYPE=proc;; - *FreeBSD) FSTYPE=linprocfs ;; - *) FSTYPE=procfs ;; - esac - elif [ "$1" = bind ] - then - case "$KERNEL" in - Linux) FSTYPE=$4; OPTS="-obind" ;; - *FreeBSD) FSTYPE=nullfs ;; - GNU) FSTYPE=firmlink ;; - *) FSTYPE=none ;; - esac - elif [ "$1" = tmpfs ] - then # always accept tmpfs, to mount /run before /proc - case "$KERNEL" in - GNU) FSTYPE=none ;; # for now - *) FSTYPE=$1 ;; - esac - elif grep -E -qs "$1\$" /proc/filesystems - then - FSTYPE=$1 - elif grep -E -qs "$2\$" /proc/filesystems - then - FSTYPE=$2 - fi - - if [ ! "$FSTYPE" ] - then - if [ "$2" ] - then - log_warning_msg "Filesystem types '$1' and '$2' are not supported. Skipping mount." - else - log_warning_msg "Filesystem type '$1' is not supported. Skipping mount." - fi - return - fi - - # We give file system type as device name if not specified as - # an argument - if [ "$4" ] ; then - DEVNAME=$4 - else - DEVNAME=$FSTYPE - fi - - # Get the options from /etc/fstab. - if [ -f /etc/fstab ] - then - exec 9<&0 </etc/fstab - - while read TAB_DEV TAB_MTPT TAB_FSTYPE TAB_OPTS TAB_REST - do - case "$TAB_DEV" in ""|\#*) continue ;; esac - [ "$MTPT" = "$TAB_MTPT" ] || continue - [ "$FSTYPE" = "$TAB_FSTYPE" ] || continue - case "$TAB_OPTS" in - noauto|*,noauto|noauto,*|*,noauto,*) - exec 0<&9 9<&- - return - ;; - ?*) - OPTS="$OPTS -o$TAB_OPTS" - ;; - esac - break - done - - exec 0<&9 9<&- - fi - - if [ ! -d "$MTPT" ] - then - return - fi - - if ! mountpoint -q "$MTPT" - then - return # Not mounted - fi - - # Already recorded? - if ! grep -E -sq "^([^ ]+) +$MTPT +" /etc/mtab < /dev/null - then - mount -f -t $FSTYPE $5 $OPTS $DEVNAME $MTPT < /dev/null - fi -} - do_start () { # Needed to determine if root is being mounted read-only. read_fstab @@ -177,57 +74,13 @@ do_start () { restorecon /etc/mtab fi - # S02mountkernfs.sh - RW_OPT= - [ "${RW_SIZE:=$TMPFS_SIZE}" ] && RW_OPT=",size=$RW_SIZE" - [ "${RW_MODE:=$TMPFS_MODE}" ] && RW_OPT="$RW_OPT,mode=$RW_MODE" - domtab tmpfs shmfs /lib/init/rw tmpfs "-onosuid$RW_OPT" - - RUN_OPT= - [ "${RUN_SIZE:=$TMPFS_SIZE}" ] && RUN_OPT=",size=$RUN_SIZE" - [ "${RUN_MODE:=$TMPFS_MODE}" ] && RUN_OPT="$RUN_OPT,mode=$RUN_MODE" - domtab tmpfs shmfs /run tmpfs "-onosuid$RUN_OPT" - - if [ yes = "$RAMLOCK" ] ; then - LOCK_OPT= - [ "${LOCK_SIZE:=$TMPFS_SIZE}" ] && LOCK_OPT=",size=$LOCK_SIZE" - [ "${LOCK_MODE:=$TMPFS_MODE}" ] && LOCK_OPT="$LOCK_OPT,mode=$LOCK_MODE" - domtab tmpfs shmfs /run/lock tmpfs "-onodev,noexec,nosuid$LOCK_OPT" - fi - - if [ yes = "$RAMTMP" ] || [ rw != "$rootmode" ] ; then - TMP_OPT= - [ "${TMP_SIZE:=$TMPFS_SIZE}" ] && TMP_OPT=",size=$TMP_SIZE" - [ "${TMP_MODE:=$TMPFS_MODE}" ] && TMP_OPT="$TMP_OPT,mode=$TMP_MODE" - domtab tmpfs shmfs /tmp tmpfs "-onodev,nosuid$TMP_OPT" - fi - - domtab proc "" /proc proc "-onodev,noexec,nosuid" - - if grep -E -qs "sysfs\$" /proc/filesystems - then - domtab sysfs "" /sys sysfs "-onodev,noexec,nosuid" - fi - - if [ -d /proc/bus/usb ] - then - domtab usbfs "" /proc/bus/usb "procbususb" - fi - + # Add entries for mounts created in early boot + # S01mountkernfs.sh + /etc/init.d/mountkernfs.sh mtab # S03udev - domtab tmpfs "" /dev "udev" "-omode=0755" - - # S04mountdevsubfs - if [ yes = "$RAMSHM" ] ; then - SHM_OPT= - [ "${SHM_SIZE:=$TMPFS_SIZE}" ] && SHM_OPT=",size=$SHM_SIZE" - [ "${SHM_MODE:=$TMPFS_MODE}" ] && SHM_OPT="$SHM_OPT,mode=$SHM_MODE" - domtab tmpfs "" /dev/shm tmpfs "-onosuid,nodev$SHM_OPT" - fi - if [ "$KERNEL" = Linux ] - then - domtab devpts "" /dev/pts "devpts" "-onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE" - fi + domount mtab tmpfs "" /dev "udev" "-omode=0755" + # S03mountdevsubfs.sh + /etc/init.d/mountdevsubfs.sh mtab # Add everything else in /proc/mounts into /etc/mtab, with # special exceptions. @@ -245,7 +98,7 @@ do_start () { continue ;; esac - domtab "$FTYPE" "" "$FDIR" "$FDEV" "-o$FOPTS" + domount mtab "$FTYPE" "" "$FDIR" "$FDEV" "-o$FOPTS" done exec 0<&8 8<&- } diff --git a/debian/src/initscripts/lib/init/mount-functions.sh b/debian/src/initscripts/lib/init/mount-functions.sh index 5f1042a..ab6f693 100644 --- a/debian/src/initscripts/lib/init/mount-functions.sh +++ b/debian/src/initscripts/lib/init/mount-functions.sh @@ -78,112 +78,117 @@ read_fstab () { exec 0<&9 9<&- } -will_mount () { - exec 9<&0 </etc/fstab +# Find a specific fstab entry +# $1=mountpoint +# $2=fstype (optional) +# returns 0 on success, 1 on failure (not found or no fstab) +read_fstab_entry () { + # Not found by default. + found=1 - found=1 # Not found + if [ -f /etc/fstab ]; then - while read DEV MTPT FSTYPE OPTS DUMP PASS JUNK - do - case "$DEV" in - ""|\#*) - continue; - ;; - esac - if [ "$MTPT" = "$1" ]; then - found=0; # Found - fi - done + exec 9<&0 </etc/fstab - exec 0<&9 9<&- - return $found + while read MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MAN_PASS MAN_JUNK + do + case "$MNT_FSNAME" in + ""|\#*) + continue; + ;; + esac + if [ "$MNT_DIR" = "$1" ]; then + if [ -n "$2" ]; then + [ "$MNT_TYPE" = "$2" ] || continue; + fi + # Found + found=0; + break + fi + done + + exec 0<&9 9<&- + + return $found + fi } # Called before mtab is writable to mount kernel and device file systems. # Note any changes here must also be made in domtab in mtab.sh. -# $1: file system type -# $2: alternative file system type (or empty string if none) -# $3: mount point -# $4: mount device name -# $5... : extra mount program options +# $1: mount mode (mount, remount, mtab) +# $2: file system type +# $3: alternative file system type (or empty string if none) +# $4: mount point +# $5: mount device name +# $6... : extra mount program options domount () { - MTPT="$3" + MOUNTMODE="$1" + PRIFSTYPE="$2" + ALTFSTYPE="$3" + MTPT="$4" + DEVNAME="$5" + CALLER_OPTS="$6" + KERNEL="$(uname -s)" - # Figure out filesystem type + # Figure out filesystem type from primary and alternative type FSTYPE= - OPTS= - if [ "$1" = proc ] - then + # Filesystem-specific mount options + FS_OPTS= + # Mount options from fstab + FSTAB_OPTS= + + if [ "$PRIFSTYPE" = proc ]; then case "$KERNEL" in Linux|GNU) FSTYPE=proc ;; *FreeBSD) FSTYPE=linprocfs ;; *) FSTYPE=procfs ;; esac - elif [ "$1" = bind ] - then + elif [ "$PRIFSTYPE" = bind ]; then case "$KERNEL" in - Linux) FSTYPE=$4; OPTS="-obind" ;; + Linux) FSTYPE="$DEVNAME"; FS_OPTS="-obind" ;; *FreeBSD) FSTYPE=nullfs ;; GNU) FSTYPE=firmlink ;; *) FSTYPE=none ;; esac - elif [ "$1" = tmpfs ] - then # always accept tmpfs, to mount /run before /proc + elif [ "$PRIFSTYPE" = tmpfs ]; then + # always accept tmpfs, to mount /run before /proc case "$KERNEL" in GNU) FSTYPE=none ;; # for now - *) FSTYPE=$1 ;; + *) FSTYPE=$PRIFSTYPE ;; esac - elif grep -E -qs "$1\$" /proc/filesystems - then - FSTYPE=$1 - elif grep -E -qs "$2\$" /proc/filesystems - then - FSTYPE=$2 + elif grep -E -qs "$PRIFSTYPE\$" /proc/filesystems; then + FSTYPE=$PRIFSTYPE + elif grep -E -qs "$ALTFSTYPE\$" /proc/filesystems; then + FSTYPE=$ALTFSTYPE fi - if [ ! "$FSTYPE" ] - then - if [ "$2" ] - then - log_warning_msg "Filesystem types '$1' and '$2' are not supported. Skipping mount." + # Filesystem not supported by kernel + if [ ! "$FSTYPE" ]; then + if [ "$ALTFSTYPE" ]; then + log_warning_msg "Filesystem types '$PRIFSTYPE' and '$ALTFSTYPE' are not supported. Skipping mount." else - log_warning_msg "Filesystem type '$1' is not supported. Skipping mount." + log_warning_msg "Filesystem type '$PRIFSTYPE' is not supported. Skipping mount." fi return fi # We give file system type as device name if not specified as # an argument - if [ "$4" ] ; then - DEVNAME=$4 - else + if [ -z "$DEVNAME" ] ; then DEVNAME=$FSTYPE fi - # Get the options from /etc/fstab. - if [ -f /etc/fstab ] - then - exec 9<&0 </etc/fstab - - while read TAB_DEV TAB_MTPT TAB_FSTYPE TAB_OPTS TAB_REST - do - case "$TAB_DEV" in ""|\#*) continue ;; esac - [ "$MTPT" = "$TAB_MTPT" ] || continue - [ "$FSTYPE" = "$TAB_FSTYPE" ] || continue - case "$TAB_OPTS" in - noauto|*,noauto|noauto,*|*,noauto,*) - exec 0<&9 9<&- + # Get the mount options from /etc/fstab + if read_fstab_entry "$MTPT" "$FSTYPE"; then + case "$MNT_OPTS" in + noauto|*,noauto|noauto,*|*,noauto,*) return ;; - ?*) - OPTS="$OPTS -o$TAB_OPTS" + ?*) + FSTAB_OPTS="-o$MNT_OPTS" ;; - esac - break - done - - exec 0<&9 9<&- + esac fi if [ ! -d "$MTPT" ] @@ -192,18 +197,52 @@ domount () { return fi - if mountpoint -q "$MTPT" - then - return # Already mounted + if [ "$MOUNTMODE" = "mount_noupdate" ]; then + MOUNTFLAGS="-n" + MOUNTMODE=mount fi - - if [ "$VERBOSE" != "no" ]; then - is_empty_dir "$MTPT" >/dev/null 2>&1 || log_warning_msg "Files under mount point '$MTPT' will be hidden." - fi - mount -n -t $FSTYPE $5 $OPTS $DEVNAME $MTPT - if [ "$FSTYPE" = "tmpfs" -a -x /sbin/restorecon ]; then - /sbin/restorecon $MTPT + if [ "$MOUNTMODE" = "remount_noupdate" ]; then + MOUNTFLAGS="-n" + MOUNTMODE=remount fi + + case "$MOUNTMODE" in + mount) + if mountpoint -q "$MTPT"; then + # Already mounted, probably moved from the + # initramfs, so remount with the + # user-specified mount options. + mount $MOUNTFLAGS -oremount $CALLER_OPTS $FSTAB_OPTS $MTPT + else + if [ "$VERBOSE" != "no" ]; then + is_empty_dir "$MTPT" >/dev/null 2>&1 || log_warning_msg "Files under mount point '$MTPT' will be hidden." + fi + mount $MOUNTFLAGS -t $FSTYPE $CALLER_OPTS $FSTAB_OPTS $FS_OPTS $DEVNAME $MTPT + if [ "$FSTYPE" = "tmpfs" -a -x /sbin/restorecon ]; then + /sbin/restorecon $MTPT + fi + fi + ;; + remount) + if mountpoint -q "$MTPT"; then + # Remount with user-specified mount options + mount $MOUNTFLAGS -oremount $CALLER_OPTS $FSTAB_OPTS $MTPT + fi + ;; + mtab) + # Update mtab with correct mount options if + # the filesystem is mounted + MOUNTFLAGS="-f" + + if mountpoint -q "$MTPT"; then + # Already recorded? + if ! grep -E -sq "^([^ ]+) +$MTPT +" /etc/mtab < /dev/null + then + mount $MOUNTFLAGS -t $FSTYPE $CALLER_OPTS $FSTAB_OPTS $FS_OPTS $DEVNAME $MTPT < /dev/null + fi + fi + ;; + esac } # @@ -226,6 +265,7 @@ run_migrate () { OLD=$1 RUN=$2 + RUNLINK=$3 KERNEL="$(uname -s)" OPTS="" @@ -236,11 +276,18 @@ run_migrate () *) FSTYPE=none ;; esac + # Create relative symlink if not already present. This is to + # upgrade from older versions which created absolute links. + if [ -L "$OLD" ] && [ "$(readlink "$OLD")" = "$RUN" ]; then + rm -f "$OLD" + ln -fs "$RUNLINK" "$OLD" + fi + # If both directories are the same, we don't need to do # anything further. - sold="$(/usr/bin/stat -L --format="%d %i" "$OLD")" - srun="$(/usr/bin/stat -L --format="%d %i" "$RUN")" - if [ "$sold" = "$srun" ]; then + sold="$(/usr/bin/stat -L --format="%d %i" "$OLD" 2>/dev/null || :)" + srun="$(/usr/bin/stat -L --format="%d %i" "$RUN" 2>/dev/null || :)" + if [ -n "$sold" ] && [ "$sold" = "$srun" ]; then return 0 fi @@ -262,10 +309,11 @@ run_migrate () mount -t $FSTYPE "$RUN" "$OLD" $OPTS else # Create symlink if not already present. - if [ -L "$OLD" ] && [ "$(readlink "$OLD")" = "$RUN" ]; then + if [ -L "$OLD" ] && [ "$(readlink "$OLD")" = "$RUNLINK" ]; then : else - ln -fs "$RUN" "$OLD" + rm -f "$OLD" + ln -fs "$RUNLINK" "$OLD" fi fi @@ -289,7 +337,7 @@ post_mountall () # filesystems are mounted, we replace the directory with a # symlink where possible. - run_migrate /var/run /run - run_migrate /var/lock /run/lock - run_migrate /dev/shm /run/shm + run_migrate /var/run /run ../run + run_migrate /var/lock /run/lock ../run/lock + run_migrate /dev/shm /run/shm ../run/shm } diff --git a/debian/src/initscripts/lib/init/tmpfs.sh b/debian/src/initscripts/lib/init/tmpfs.sh index ed8efd6..412e274 100644 --- a/debian/src/initscripts/lib/init/tmpfs.sh +++ b/debian/src/initscripts/lib/init/tmpfs.sh @@ -30,3 +30,23 @@ RW_MODE=755 if [ -f /etc/default/tmpfs ]; then . /etc/default/tmpfs fi + +RUN_OPT= +[ "${RUN_SIZE:=$TMPFS_SIZE}" ] && RUN_OPT=",size=$RUN_SIZE" +[ "${RUN_MODE:=$TMPFS_MODE}" ] && RUN_OPT="$RUN_OPT,mode=$RUN_MODE" + +LOCK_OPT= +[ "${LOCK_SIZE:=$TMPFS_SIZE}" ] && LOCK_OPT=",size=$LOCK_SIZE" +[ "${LOCK_MODE:=$TMPFS_MODE}" ] && LOCK_OPT="$LOCK_OPT,mode=$LOCK_MODE" + +SHM_OPT= +[ "${SHM_SIZE:=$TMPFS_SIZE}" ] && SHM_OPT=",size=$SHM_SIZE" +[ "${SHM_MODE:=$TMPFS_MODE}" ] && SHM_OPT="$SHM_OPT,mode=$SHM_MODE" + +TMP_OPT= +[ "${TMP_SIZE:=$TMPFS_SIZE}" ] && TMP_OPT=",size=$TMP_SIZE" +[ "${TMP_MODE:=$TMPFS_MODE}" ] && TMP_OPT="$TMP_OPT,mode=$TMP_MODE" + +RW_OPT= +[ "${RW_SIZE:=$TMPFS_SIZE}" ] && RW_OPT=",size=$RW_SIZE" +[ "${RW_MODE:=$TMPFS_MODE}" ] && RW_OPT="$RW_OPT,mode=$RW_MODE"
signature.asc
Description: Digital signature
_______________________________________________ Pkg-sysvinit-devel mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/pkg-sysvinit-devel

