home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20110725.etc.tar.gz / bradford.20110725.etc.tar / etc / init.d / boot.localfs < prev    next >
Text File  |  2006-04-20  |  7KB  |  294 lines

  1. #! /bin/sh
  2. #
  3. # Copyright (c) 2001-2002 SuSE Linux AG, Nuernberg, Germany.
  4. # All rights reserved.
  5. #
  6. # /etc/init.d/boot.localfs
  7. #
  8. ### BEGIN INIT INFO
  9. # Provides:          boot.localfs
  10. # Required-Start:    boot.udev boot.loadmodules
  11. # Should-Start: boot.ibmsis boot.md boot.lvm dasd_devfs_compat boot.scsidev boot.multipath
  12. # Required-Stop:
  13. # Default-Start:     B
  14. # Default-Stop:
  15. # Description:       check and mount local filesystems except /
  16. ### END INIT INFO
  17.  
  18. . /etc/rc.status
  19.  
  20. # to get max number of parallel fsck processes
  21. . /etc/sysconfig/boot
  22. . /etc/sysconfig/kernel
  23.  
  24. if [ -f /etc/sysconfig/dump ]; then
  25.     . /etc/sysconfig/dump
  26. fi
  27.  
  28. export FSCK_MAX_INST
  29.  
  30. # helper shell function
  31. #
  32. reverse ()
  33. {
  34.     local _line
  35.     while read -r _line ; do
  36.     reverse
  37.     echo "$_line"
  38.     break
  39.     done
  40. }
  41.  
  42. list_missed ()
  43. {
  44.     local dev
  45.     local mount_opts="-t nonfs,nonfs4,noproc,nodevpts,nosmbfs,nocifs -O no_netdev"
  46.  
  47.     mount -afnv $mount_opts 2> /dev/null | while read line ; do
  48.     dev="${line%% *}"
  49.     case "$line" in
  50.     *mounted*)
  51.         continue      ;;
  52.     *)  test -b $dev && continue
  53.         echo "${dev}" ;;
  54.     esac
  55.     done
  56. }
  57.  
  58. wait_for_udev ()
  59. {
  60.     missing=$(list_missed)
  61.     if [ -z "$missing" ]; then
  62.     return
  63.     fi
  64.     echo -n "Waiting for $missing "
  65.     timeout=30
  66.     while [ "$timeout" -gt 0 ] ; do
  67.     sleep 1
  68.     echo ". "
  69.     still_missing=""
  70.     for dev in $missing; do
  71.         if [ ! -b $dev ] ; then
  72.         still_missing="$dev $still_missing"
  73.         fi
  74.     done
  75.     if [ -z "$still_missing" ]; then
  76.         echo "ok"
  77.         break;
  78.     fi
  79.     missing="$still_missing"
  80.     if [ ! -d /dev/.udev/queue ] ; then
  81.         echo "no more events"
  82.         break;
  83.     fi
  84.     timeout=$(( $timeout - 1 ))
  85.     done
  86.     if [ "$timeout" -eq 0 ] ; then
  87.     echo "timeout"
  88.     fi
  89. }
  90.  
  91. rc_reset
  92.  
  93. case "$1" in
  94.   start)
  95.     # rootfs is mounted rw, lvm et al should be up now
  96.     wait_for_udev
  97.     #
  98.     # If we use a serial console, don't use the fsck progress bar
  99.     #
  100.     FSCK_PROGRESSBAR="-V"
  101.         [ -x /sbin/showconsole ] && [ "`/sbin/showconsole`" = "/dev/tty1" ] && FSCK_PROGRESSBAR="-C"
  102.     #
  103.     # do fsck and start sulogin, if it fails.
  104.     #
  105.     FSCK_RETURN=0
  106.     if test ! -f /fastboot -a -z "$fastboot" ; then
  107.         FSCK_FORCE=""
  108.         test -f /forcefsck && FSCK_FORCE="-f"
  109.             echo "Checking file systems..."
  110.             fsck $FSCK_PROGRESSBAR -R -A -m -a $FSCK_FORCE -t noopts=hotplug
  111.             # A return code of 1 indicates that file system errors
  112.             # were corrected, but that the boot may proceed.
  113.             # A return code of 2 or larger indicates failure.
  114.             FSCK_RETURN=$?
  115.         test $FSCK_RETURN -lt 4
  116.         rc_status -v1 -r
  117.         if test $FSCK_RETURN -gt 1 -a $FSCK_RETURN -lt 4 ; then
  118.             # if appropriate, switch bootsplash to verbose 
  119.             # mode to make text messages visible.
  120.             test -f /proc/splash && echo "verbose" > /proc/splash
  121.             echo
  122.             echo "fsck succeed, but reboot is required."
  123.             echo
  124.             sleep 1
  125.             sync
  126.             reboot -f
  127.         elif test $FSCK_RETURN -gt 3; then
  128.             # if appropriate, switch bootsplash to verbose 
  129.             # mode to make text messages visible.
  130.             test -f /proc/splash && echo "verbose" > /proc/splash
  131.             # Stop blogd since we reboot after sulogin
  132.             test -x /sbin/blogd && killproc -QUIT /sbin/blogd
  133.             if test -x /etc/init.d/kbd ; then
  134.             /etc/init.d/kbd start
  135.             fi
  136.                 echo
  137.                 echo "fsck failed for at least one filesystem (not /)."
  138.             echo "Please repair manually and reboot."
  139.             echo "The root file system is is already mounted read-write."
  140.                 echo
  141.                 echo "Attention: Only CONTROL-D will reboot the system in this"
  142.                 echo "maintanance mode. shutdown or reboot will not work."
  143.                 echo
  144.                 PS1="(repair filesystem) # "
  145.                 export PS1
  146.                 /sbin/sulogin /dev/console
  147.  
  148.                 # if the user has mounted something rw, this should be umounted
  149.                 echo "Unmounting file systems (ignore error messages)"
  150.                 umount -avn
  151.  
  152.                 # on umsdos fs this would lead to an error message.
  153.             # so direct errors to /dev/null
  154.                 mount -no remount,ro / 2> /dev/null
  155.  
  156.                 sync
  157.                 reboot -f
  158.             fi
  159.             if test $FSCK_RETURN -gt 0; then
  160.                 sync
  161.             touch /fsck_corrected_errors
  162.         fi
  163.     fi
  164.  
  165.     #
  166.     # clean up
  167.     #
  168.     rm -f /etc/nologin /nologin /fastboot /forcefsck /success
  169.  
  170.     rc_status -v -r
  171.  
  172.     #
  173.     # Mount local filesystems in '/etc/fstab' (and create an entry
  174.     # for / and /proc).
  175.     #
  176.     echo "Mounting local file systems..."
  177.     mount -fv -t proc proc /proc
  178.     mount -fv -t sysfs sysfs /sys
  179.     while read a b ; do
  180.         if test "$b" = "debugfs" ; then
  181.         mount -fv -t debugfs debugfs /sys/kernel/debug
  182.         fi
  183.     done < /proc/filesystems
  184.     mount -fv -t tmpfs udev /dev
  185.     rc_status
  186.     if test ! -d /sys/block/loop0 ; then
  187.         /sbin/modprobe loop
  188.     fi
  189.     optpts="-o mode=0620,gid=5"
  190.     mount -fv -t devpts $optpts devpts /dev/pts
  191.     rc_status
  192.     mount -av -t nonfs,nonfs4,noproc,nodevpts,nosmbfs,nocifs -O no_netdev
  193.     rc_status -v1 -r
  194.     ;;
  195.     stop)
  196.     mounts=/etc/fstab
  197.     test -r /proc/mounts && mounts=/proc/mounts
  198.  
  199.     # move to intermezzo package ?
  200.     # First umount intermezzo filesystems
  201.     if test -x /usr/sbin/umountizo ; then
  202.         while read line ; do
  203.         case "$line" in
  204.         *[Ii][Nn][Tt][Ee][Rr][Mm][Ee][Zz][Zz][Oo]*)
  205.             /usr/sbin/umountizo >/dev/null 2>&1
  206.         esac
  207.         done < $mounts
  208.     fi
  209.  
  210.     reverse < $mounts | \
  211.     while read des fs type rest; do
  212.         case "$des"  in
  213.             ""|\#*)    continue ;;
  214.             /dev/loop*)
  215.                        umount $fs
  216.                        losetup $des &> /dev/null
  217.                        test $? -eq 0 && losetup -d $des ;;
  218.         esac
  219.         case "$fs"   in
  220.             /proc)     continue ;;
  221.             /dev/pts)  continue ;;
  222.             /dev)      continue ;;
  223.             /dev/shm)  continue ;;
  224.         esac
  225.         case "$type" in
  226.             proc)      umount -t proc     $fs ;;
  227.             devpts)    umount -t devpts   $fs ;;
  228.             tmpfs)     umount -t tmpfs    $fs ;;
  229.             usbfs)     umount -t usbfs    $fs ;;
  230.         esac
  231.     done
  232.  
  233.     while read major minor blocks name ; do
  234.         des=/dev/$name
  235.         case "$name" in
  236.         ""|\#*)    continue ;;
  237.         loop*)
  238.                    des=/dev/loop/${name#loop}
  239.                    losetup $des &> /dev/null
  240.                    test $? -eq 0 && losetup -d $des
  241.                des=/dev/$name
  242.                    losetup $des &> /dev/null
  243.                    test $? -eq 0 && losetup -d $des
  244.         esac
  245.     done < /proc/partitions
  246.  
  247.     UMOUNT_FAILED=false
  248.     echo "Unmounting file systems"
  249.     umount -avt noproc,nonfs,nonfs4,nosmbfs,nocifs,notmpfs || {
  250.         rc_status
  251.         UMOUNT_FAILED=true
  252.     }
  253.     rc_status -v1 -r
  254.  
  255.     if test "$UMOUNT_FAILED" = true ; then
  256.         echo "Oops: umount failed :-(  --  trying to remount readonly..."
  257.         mounts=/etc/fstab
  258.         test -r /proc/mounts && mounts=/proc/mounts
  259.         # Use cat and a pipe because umount changes
  260.         # /proc/mounts during direct read call
  261.         cat $mounts | \
  262.         while read des fs type rest; do
  263.             case "$des" in ""|\#*) continue ;; esac
  264.             case "$type" in
  265.                 swap)     continue ;; # No umount on swap devices
  266.                 proc)     continue ;; # Required
  267.                 nfs|nfs4)      continue ;; # Avoid hanging reboot/halt
  268.                 smbfs|cifs)    continue ;; # Avoid hanging reboot/halt
  269.             esac
  270.             mount -v -n -o remount,ro $fs
  271.         done
  272.  
  273.         echo "extra sync..."
  274.         sync; sync
  275.         echo "... hope now it's ok to reboot."
  276.     fi
  277.     ;;
  278.     restart)
  279.     rc_failed 3
  280.     rc_status -v
  281.     ;;
  282.     status)
  283.     rc_failed 4
  284.     rc_status -v
  285.     ;;
  286.     *)
  287.     echo "Usage: $0 {start|stop|status|restart}"
  288.     exit 1
  289.     ;;
  290. esac
  291.  
  292. rc_exit
  293.  
  294.