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.rootfsck < prev    next >
Text File  |  2006-02-01  |  5KB  |  186 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.rootfsck
  7. #
  8. ### BEGIN INIT INFO
  9. # Provides:          boot.rootfsck
  10. # Required-Start:
  11. # Required-Stop:
  12. # Default-Start:     B
  13. # Default-Stop:
  14. # Description:       check and mount root filesystem
  15. ### END INIT INFO
  16.  
  17. . /etc/rc.status
  18.  
  19. # to get max number of parallel fsck processes
  20. . /etc/sysconfig/boot
  21.  
  22. if [ -f /etc/sysconfig/dump ]; then
  23.     . /etc/sysconfig/dump
  24. fi
  25.  
  26. export FSCK_MAX_INST
  27.  
  28. rc_reset
  29.  
  30. case "$1" in
  31.   start)
  32.     #
  33.     # fsck may need a huge amount of memory, so make sure, it is there.
  34.     #
  35.     # However, in the case of an active LKCD configuration, we need to
  36.     # recover the crash dump from the swap partition first, so we cannot
  37.     # yet activate them.
  38.     #
  39.     if [ "$DUMP_ACTIVE" != "1" ]; then
  40.         echo "Activating swap-devices in /etc/fstab..."
  41.         swapon -ae &> /dev/null
  42.         rc_status -v1 -r
  43.     fi
  44.     
  45.     #
  46.     # If we use a serial console, don't use the fsck progress bar
  47.     #
  48.     FSCK_PROGRESSBAR="-V"
  49.         [ -x /sbin/showconsole ] && [ "`/sbin/showconsole`" = "/dev/tty1" ] && FSCK_PROGRESSBAR="-C"
  50.     #
  51.     # do fsck and start sulogin, if it fails.
  52.     #
  53.     FSCK_RETURN=0
  54.     MAY_FSCK=1
  55.  
  56.     # we may get ROOTFS_BLKDEV passed from initrd, skip extra actions
  57.     if [ -n "$ROOTFS_BLKDEV" ]  ; then
  58.         if [ -n "$ROOTFS_REALDEV" ]  ; then
  59.         ROOTFS_BLKDEV=$ROOTFS_REALDEV
  60.         fi
  61.     else
  62.         # if not booted via initrd, /dev is empty.
  63.         # use private devnode with proper permissions
  64.         ROOTFS_BLKDEV="/dev/shm/root"
  65.         rootcpio=`echo / | /bin/cpio --quiet -o -H newc`
  66.         rootmajor=0x${rootcpio:62:8}
  67.         rootminor=0x${rootcpio:70:8}
  68.         if [ $((rootmajor)) -ne 0 ] ; then
  69.             echo /bin/mknod -m600 $ROOTFS_BLKDEV b $((rootmajor)) $((rootminor))
  70.             /bin/mknod -m600 $ROOTFS_BLKDEV b $((rootmajor)) $((rootminor))
  71.         fi
  72.         MAY_FSCK=0
  73.         if test -n "$ROOTFS_BLKDEV" -a "$ROOTFS_BLKDEV" != "/" -a -b "$ROOTFS_BLKDEV" ; then
  74.         MAY_FSCK=1
  75.         fi
  76.         fi
  77.     #
  78.         FSCK_FORCE=""
  79.     if test -f /forcefsck ; then
  80.         FSCK_FORCE="-f"
  81.         ROOTFS_FSCK=""
  82.         fi
  83.     if test "$ROOTFS_FSCK" = "0" ; then
  84.         # already checked and ok, skip the rest
  85.             MAY_FSCK=0
  86.         fi
  87.     if test ! -f /fastboot -a -z "$fastboot" -a $MAY_FSCK -eq 1 ; then
  88.         # on an umsdos root fs this mount will fail,
  89.         # so direct error messages to /dev/null.
  90.         # this seems to be ugly, but should not really be a problem.
  91.         mount -n -o remount,ro / 2> /dev/null
  92.         if test $? = 0; then
  93.         if test -n "$ROOTFS_FSCK" ; then
  94.             FSCK_RETURN=$ROOTFS_FSCK
  95.         else
  96.             echo "Checking root file system..."
  97.             fsck $FSCK_PROGRESSBAR -a $FSCK_FORCE $ROOTFS_BLKDEV
  98.             # A return code of 1 indicates that file system errors
  99.             # were corrected, but that the boot may proceed.
  100.             # A return code of 2 or larger indicates failure.
  101.             FSCK_RETURN=$?
  102.         fi
  103.         test $FSCK_RETURN -lt 4
  104.         rc_status -v1 -r
  105.         if test $FSCK_RETURN -gt 1 -a $FSCK_RETURN -lt 4 ; then
  106.             # if appropriate, switch bootsplash to verbose 
  107.             # mode to make text messages visible.
  108.             test -f /proc/splash && echo "verbose" > /proc/splash
  109.             echo
  110.             echo "fsck succeed, but reboot is required."
  111.             echo
  112.             sleep 1
  113.             sync
  114.             reboot -f
  115.         elif test $FSCK_RETURN -gt 3; then
  116.             # if appropriate, switch bootsplash to verbose 
  117.             # mode to make text messages visible.
  118.             test -f /proc/splash && echo "verbose" > /proc/splash
  119.             # Stop blogd since we reboot after sulogin
  120.             test -x /sbin/blogd && killproc -QUIT /sbin/blogd
  121.             if test -x /etc/init.d/kbd ; then
  122.             /etc/init.d/kbd start
  123.             fi
  124.                 echo
  125.                 echo "fsck failed.  Please repair manually and reboot. The root"
  126.                 echo "file system is currently mounted read-only. To remount it"
  127.                 echo "read-write do:"
  128.                 echo
  129.                 echo "   bash# mount -n -o remount,rw /"
  130.                 echo
  131.                 echo "Attention: Only CONTROL-D will reboot the system in this"
  132.                 echo "maintanance mode. shutdown or reboot will not work."
  133.                 echo
  134.                 PS1="(repair filesystem) # "
  135.                 export PS1
  136.                 /sbin/sulogin /dev/console
  137.  
  138.                 # if the user has mounted something rw, this should be umounted
  139.                 echo "Unmounting file systems (ignore error messages)"
  140.                 umount -avn
  141.  
  142.                 # on umsdos fs this would lead to an error message.
  143.             # so direct errors to /dev/null
  144.                 mount -no remount,ro / 2> /dev/null
  145.  
  146.                 sync
  147.                 reboot -f
  148.             fi
  149.             sync
  150.             mount -n -o remount,rw /
  151.         test $FSCK_RETURN -gt 0 && touch /fsck_corrected_errors
  152.         else
  153.         echo
  154.         echo '*** ERROR!  Cannot fsck because root is not read-only!'
  155.         echo
  156.         fi
  157.     else
  158.         if test "$ROOTFS_FSCK" != "0" ; then
  159.         echo "root file system (/) is NOT being checked."
  160.         fi
  161.         # remount in any case to apply additional options like xattr
  162.         mount -n -o remount,rw /
  163.     fi
  164.         # start with a clean mtab and enter root fs entry
  165.     rm -f /etc/mtab*
  166.     mount -f /
  167.     ;;
  168.     stop)
  169.     ;;
  170.     restart)
  171.     rc_failed 3
  172.     rc_status -v
  173.     ;;
  174.     status)
  175.     rc_failed 4
  176.     rc_status -v
  177.     ;;
  178.     *)
  179.     echo "Usage: $0 {start|stop|status|restart}"
  180.     exit 1
  181.     ;;
  182. esac
  183.  
  184. rc_exit
  185.  
  186.