NoPaste

weiterer L?sungsansatz

von Sledge Hammer

SNIPPET_TEXT:
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          mtab
  4. # Required-Start:    checkroot
  5. # Required-Stop:
  6. # Default-Start:     S
  7. # Default-Stop:
  8. # Short-Description: Update mtab file.
  9. # Description:       Update the mount program's mtab file after
  10. #                    all local filesystems have been mounted.
  11. ### END INIT INFO
  12.  
  13. #
  14. # The main purpose of this script is to update the mtab file to reflect
  15. # the fact that virtual filesystems were mounted early on, before mtab
  16. # was writable.
  17. #
  18.  
  19. PATH=/lib/init:/sbin:/bin
  20. . /lib/init/vars.sh
  21.  
  22. TTYGRP=5
  23. TTYMODE=620
  24. [ -f /etc/default/devpts ] && . /etc/default/devpts
  25.  
  26. TMPFS_SIZE=
  27. [ -f /etc/default/tmpfs ] && . /etc/default/tmpfs
  28.  
  29. KERNEL="$(uname -s)"
  30.  
  31. . /lib/lsb/init-functions
  32. . /lib/init/mount-functions.sh
  33.  
  34. # $1 - fstype
  35. # $2 - mount point
  36. # $3 - mount name/device
  37. # $4 - mount options
  38. domtab ()
  39. {
  40.         # Directory present?
  41.         if [ ! -d $2 ]
  42.         then
  43.                 return
  44.         fi
  45.  
  46.         # Not mounted?
  47.         if ! mountpoint -q $2 < /dev/null
  48.         then
  49.                 return
  50.         fi
  51.  
  52.         if [ -n "$3" ]
  53.         then
  54.                 NAME="$3"
  55.         else
  56.                 NAME="$1"
  57.         fi
  58.  
  59.         # Already recorded?
  60.         if ! grep -E -sq "^([^ ]+) +$2 +" /etc/mtab < /dev/null
  61.         then
  62.                 mount -f -t $1 $OPTS $4 $NAME $2 < /dev/null
  63.         fi
  64. }
  65.  
  66. do_start () {
  67.         DO_MTAB=""
  68.         MTAB_PATH="$(readlink -f /etc/mtab || :)"
  69.         case "$MTAB_PATH" in
  70.           /proc/*)
  71.                 # Assume that /proc/ is not writable
  72.                 ;;
  73.           /*)
  74.                 # Only update mtab if it is known to be writable
  75.                 # Note that the touch program is in /usr/bin
  76.                 #if ! touch "$MTAB_PATH" >/dev/null 2>&1
  77.                 #then
  78.                 #       return
  79.                 #fi
  80.                 ;;
  81.           "")
  82.                 [ -L /etc/mtab ] && MTAB_PATH="$(readlink /etc/mtab)"
  83.                 if [ "$MTAB_PATH" ]
  84.                 then
  85.                         log_failure_msg "Cannot initialize ${MTAB_PATH}."
  86.                 else
  87.                         log_failure_msg "Cannot initialize /etc/mtab."
  88.                 fi
  89.                 ;;
  90.           *)
  91.                 log_failure_msg "Illegal mtab location '${MTAB_PATH}'."
  92.                 ;;
  93.         esac
  94.  
  95.         #
  96.         # Initialize mtab file if necessary
  97.         #
  98.         if [ ! -f /etc/mtab ]
  99.         then
  100.                 :> /etc/mtab
  101.                 chmod 644 /etc/mtab
  102.         fi
  103.         if selinux_enabled && which restorecon >/dev/null 2>&1 && [ -r /etc/mtab ]
  104.         then
  105.                 restorecon /etc/mtab
  106.         fi
  107.  
  108.         # S02mountkernfs.sh
  109.         RW_OPT=
  110.         [ "${RW_SIZE:=$TMPFS_SIZE}" ] && RW_OPT=",size=$RW_SIZE"
  111.         domtab tmpfs /lib/init/rw tmpfs -omode=0755,nosuid$RW_OPT
  112.  
  113.         domtab proc /proc "proc" -onodev,noexec,nosuid
  114.         if grep -E -qs "sysfs\$" /proc/filesystems
  115.         then
  116.                 domtab sysfs /sys sysfs -onodev,noexec,nosuid
  117.         fi
  118.         if [ yes = "$RAMRUN" ] ; then
  119.                 RUN_OPT=
  120.                 [ "${RUN_SIZE:=$TMPFS_SIZE}" ] && RUN_OPT=",size=$RUN_SIZE"
  121.                 domtab tmpfs /var/run "varrun" -omode=0755,nosuid$RUN_OPT
  122.         fi
  123.         if [ yes = "$RAMLOCK" ] ; then
  124.                 LOCK_OPT=
  125.                 [ "${LOCK_SIZE:=$TMPFS_SIZE}" ] && LOCK_OPT=",size=$LOCK_SIZE"
  126.                 domtab tmpfs /var/lock "varlock" -omode=1777,nodev,noexec,nosuid$LOCK_OPT
  127.         fi
  128.         if [ -d /proc/bus/usb ]
  129.         then
  130.                 domtab usbfs /proc/bus/usb "procbususb"
  131.         fi
  132.  
  133.         # S03udev
  134.         domtab tmpfs /dev "udev" -omode=0755
  135.  
  136.         # S04mountdevsubfs
  137.         SHM_OPT=
  138.         [ "${SHM_SIZE:=$TMPFS_SIZE}" ] && SHM_OPT=",size=$SHM_SIZE"
  139.         domtab tmpfs /dev/shm tmpfs -onosuid,nodev$SHM_OPT
  140.         domtab devpts /dev/pts "devpts" -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
  141.  
  142.         # Add everything else in /proc/mounts into /etc/mtab, with
  143.         # special exceptions.
  144.         exec 9<&0 0</proc/mounts
  145.         while read FDEV FDIR FTYPE FOPTS REST
  146.         do
  147.                 case "$FDIR" in
  148.                         /lib/modules/*/volatile)
  149.                                 FDEV="lrm"
  150.                                 ;;
  151.                         /dev/.static/dev)
  152.                                 # Not really useful to show in 'df',
  153.                                 # and it isn't accessible for non-root
  154.                                 # users.
  155.                                 continue
  156.                                 ;;
  157.                 esac
  158.                 domtab "$FTYPE" "$FDIR" "$FDEV" "-o$FOPTS"
  159.         done
  160.         exec 0<&9 9<&-
  161. }
  162.  
  163. case "$1" in
  164.   start|"")
  165.         do_start
  166.         ;;
  167.   restart|reload|force-reload)
  168.         echo "Error: argument '$1' not supported" >&2
  169.         exit 3
  170.         ;;
  171.   stop)
  172.         # No-op
  173.         ;;
  174.   *)
  175.         echo "Usage: mountall-mtab.sh [start|stop]" >&2
  176.         exit 3
  177.         ;;
  178. esac
  179.  
  180. :

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN