[Lunar-commits] CVS: moonbase/filesys/e2fsprogs/init.d mount, 1.2, 1.3

Jaime Buffery nestu at lunar-linux.org
Mon Nov 8 09:36:47 UTC 2004


Update of /var/cvs/lunar/moonbase/filesys/e2fsprogs/init.d
In directory espresso.foo-projects.org:/tmp/cvs-serv20306

Modified Files:
	mount 
Log Message:
Modified mount script that now includes udev support


Index: mount
===================================================================
RCS file: /var/cvs/lunar/moonbase/filesys/e2fsprogs/init.d/mount,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mount	2 Jan 2004 00:59:43 -0000	1.2
+++ mount	8 Nov 2004 09:36:45 -0000	1.3
@@ -4,7 +4,7 @@
 
 # Lunar devfsd save location
 DEVFSDD=/var/state/devfsd
- 
+
 chkresult() {
   if [ $? -eq "0" ] ; then
     echo -e $RESULT_OK
@@ -24,244 +24,347 @@
 
 }
 
+
+isUdevInstalled()
+{
+    echo         -n " * Trying to default to udev:"      
+    if [ -x /sbin/udevstart ]; then
+	chkresult
+	return 0
+    else
+	chkresult
+	return 1
+    fi
+}
+
+isDevfsInstalled()
+{
+    echo         -n " *    Trying to default to devfs:"      
+    if [ -x /sbin/devfsd ]; then
+	chkresult
+	return 0
+    else
+	chkresult
+	return 1
+    fi
+}
+
+staticWarning()
+{
+    echo       -n "* Assuming a static /dev"
+    echo       -e $RESULT_WARN	      
+    return 0
+}
+
 start() {
 
   echo "Mounting filesystems:"
   mount       -n -o  remount,ro / >& /dev/null
 
-  # I hate this, but it's required to make swapoff work if devfs is runing on /dev
-  # it's clean and also simplifies the devfsd module
-  # This scews up mtab
-  grep -v '#' /etc/fstab | grep -v ^$ | grep -v noauto | \
-  while read DEVICE MOUNTPOINT FSTYPE REST ; do 
-    if [ "$DEVICE" = "devfs" ] ; then
-      echo         -n " * Mounting: $MOUNTPOINT"     
-      mount        -n $MOUNTPOINT  &> /dev/null
-      if [ $? -eq "0" ] ; then
-        if [ -x /sbin/devfsd ] ; then
-          echo     -e $RESULT_OK
-          echo     -n "   * Starting devfsd on $MOUNTPOINT:"
-          devfsd   $MOUNTPOINT  &> /dev/null
-          chkresult
-        fi
-      else
-        echo  -e $RESULT_FAIL
-      fi
-    fi
-  done
-
-  echo        -n " * Mounting swap"
-  swapon      -a &> /dev/null
+  # this was reordered since it has to be proc -> sys -> ramfs -> udev
+  echo     -n " * Mounting proc on /proc:"
+  mount -t proc proc /proc
   chkresult
+  
+#  I can use /proc/cmdline since it is mounted now *before*
+  DEVNODES=`cat /proc/cmdline | grep -ow "dev=\(udev\|devfs\)" | sed 's/dev=//g'`
+  test -z "$DEVNODES" && DEVNODES=`cat /proc/cmdline | grep -ow "dev=static" | sed 's/dev=//g'`
 
+#  echo "DEVNODES: \"${DEVNODES}\""
+  
+  UNAMER=`uname -r`
+  
+  case $UNAMER in
+      2.4*)
+	  if [ "$DEVNODES" = "udev" ]; then # *sigh*
+	      echo       -n "* No udev for 2.4 kernels. Please unset udev commandline option"
+	      echo       -e $RESULT_WARN	      
+	      DEVNODES=""
+	  fi
+	  ;;
+  esac
+  
+  
+  if [ -z "$DEVNODES" ]; then
+      
+      # fallbacks if no cmdline has been supplied, or if the luser wanted udev for 2.4 *sigh*
+      case $UNAMER in
+	  2.4*)
+	      # if no kernel cmdline param, and devfsd is there, default to devfs on 2.4 installs
+	      # I.O.C., static /dev
+	      
+	      if isDevfsInstalled ; then
+		  DEVNODES="devfs" 
+	      else
+		  staticWarning
+		  DEVNODES="static"
+	      fi
+	      
+	      ;;
+	  
+	  2.6*)
+	  # if no kernel cmdline param, and udevstart is there, default to udev on 2.6 installs
+	  # if no udev, then try if devfs is there.
+	  # I.O.C., static /dev
+	      if isUdevInstalled ; then
+		  DEVNODES="udev"
+	      elif isDevfsInstalled ; then
+		  DEVNODES="devfs" 
+	      else
+		  staticWarning
+		  DEVNODES="static"
+	      fi
+	      
+	      ;;
+      esac
+  fi
+  
+  if [ "$DEVNODES" = "devfs" ]; then
+      # I hate this, but it's required to make swapoff work if devfs is runing on /dev
+      # it's clean and also simplifies the devfsd module
+      # This scews up mtab
+      grep -v '#' /etc/fstab | grep -v ^$ | grep -v noauto | \
+	  while read DEVICE MOUNTPOINT FSTYPE REST ; do 
+	  if [ "$DEVICE" = "devfs" ] ; then
+	      echo         -n " * Mounting: $MOUNTPOINT"     
+	      mount        -n $MOUNTPOINT  &> /dev/null
+	      if [ $? -eq "0" ] ; then
+		  if [ -x /sbin/devfsd ] ; then
+		      echo     -e $RESULT_OK
+		      echo     -n "   * Starting devfsd on $MOUNTPOINT:"
+		      devfsd   $MOUNTPOINT  &> /dev/null
+		      chkresult
+		  fi
+	      else
+		  echo  -e $RESULT_FAIL
+	      fi
+	  fi
+      done
+  fi
+  
+  if [ "$DEVNODES" = "udev" ]; then
+      echo    -n " * Mounting sysfs on /sys :"
+      mount -t sysfs sysfs /sys
+      chkresult  
+
+      echo     -n " * Creating ramfs on /dev :"
+      mount -t ramfs none /dev
+      chkresult
+
+      echo     -n " * Creating udev device nodes on /dev :"
+      /sbin/udevstart
+      chkresult
+
+      echo     -n " * Creating missing dirs on /dev :"     
+      mkdir /dev/{pts,shm}
+      chkresult
+
+  fi
+  
   if  [ ! -e /fastboot ] ; then 
-    if [ -e /forcefsck ] ; then
-      FORCE="-f"
-    fi
-    echo      -n " * Checking all file systems"
-    fsck      -A -y
-    if [ "$?" -eq "0" ] ; then
-      echo    -e $RESULT_OK
-    else
-      if [ "$?" -eq "1" ] ; then    # Don't force the poor guy into rescue mode, if fsck cleaned it
-        echo  -e $RESULT_WARN
+      if [ -e /forcefsck ] ; then
+	  FORCE="-f"
+      fi
+      echo      -n " * Checking all file systems"
+      fsck      -A -y -a &> /dev/null
+      if [ "$?" -eq "0" ] ; then
+	  echo    -e $RESULT_OK
       else
-        echo  -e " * fsck failed.$RESULT_FAIL"
-        echo  "  * Please repair your file system"
-        echo  "  * manually by running /sbin/fsck"
-        echo  "  * without the -a option"
-        sulogin
-        reboot  -f
+	  if [ "$?" -eq "1" ] ; then    # Don't force the poor guy into resuce mode, if fscked cleaned it
+              echo  -e $RESULT_WARN
+	  else
+              echo  -e " * fsck failed.$RESULT_FAIL"
+              echo  "  * Please repair your file system"
+              echo  "  * manually by running /sbin/fsck"
+              echo  "  * without the -a option"
+              sulogin
+              reboot  -f
+	  fi
       fi
-    fi
   fi
-
+  
   echo       -n " * Remounting root readwrite"
   mount      -n -o remount,rw /  &> /dev/null
   echo       > /etc/mtab
   rm         -f /etc/mtab~*      &> /dev/null
   mount      -f -o remount,rw /  &> /dev/null
   chkresult  
-
-  echo       " * Mounting remaining filesystems:"
   
-  # Mounting /proc to maintain compatibility with LVM
-  echo -n "  * Mounting: /proc"
-  mount      /proc    &> /dev/null
+  # the other case left apart from devfs and udev is a static dev. This doesn't need any setup.
+  
+  echo        -n " * Mounting swap"
+  swapon      -a &> /dev/null
   chkresult
-
-  # Enable LVM or LVM2 if configured
-  if [ -e /etc/config.d/lvm -a -x /sbin/vgscan -a -x /sbin/vgchange ]; then
-      /sbin/vgscan
-      /sbin/vgchange -a y
-  fi
-
+  
+  echo       " * Mounting remaining filesystems:"
+  
   # /etc/fast should be in order
   # ex. /usr should comes before /usr/local
   # and /proc before /proc/bus/usb
   # better to fail if a mounting dosn't exist than, do it silently
-  grep -v '#' /etc/fstab | grep -v ^$ | grep -v noauto | grep -v ^proc |
+  grep -v '#' /etc/fstab | grep -v ^$ | grep -v noauto | 
   while  read  DEVICE MOUNTPOINT FSTYPE REST;  do
   
     # Filter out already mounted fs's: devfs and root
     # We should have mounted all devfs before, now a hack to get it into /etc/mtab
-    if [ "$DEVICE" == "devfs" ] ; then
-      mount -f -t devfs devfs $MOUNTPOINT
-      continue
-    fi 
-    if [ "$MOUNTPOINT" == "/" ] ; then
-      continue
-    fi
+      if [ "$DEVICE" == "devfs" ] ; then
+	  if [ "$DEVNODES" = "devfs" ]; then
+	      mount -f -t devfs devfs $MOUNTPOINT
+	  fi
+	  continue
+      fi 
+      if [ "$MOUNTPOINT" == "/" ] ; then
+	  continue
+      fi
 
+      # these have been mounted previously, so don't remount them
+      test "$MOUNTPOINT" = "/proc" && continue
+      test "$MOUNTPOINT" = "/sys"  && continue
+      
     # we don't do networked fs's yet!
-    case "$FSTYPE" in
-      nfs|smbfs) continue ;;
-    esac
-
+      case "$FSTYPE" in
+	  nfs|smbfs) continue ;;
+      esac
+      
     # End filter
-
-    if [ "$MOUNTPOINT" != "none" ] ; then
-      echo    -n "  * Mounting: $MOUNTPOINT"
-      mount   $MOUNTPOINT         &> /dev/null
-      if [ $? -ne "0" ] ; then
-        if [ "$DEVICE" == "usbdevfs" ] || [ "$DEVICE" == "usbfs" ] ; then          # Load the module for usbdevfs if need
-          modprobe usbcore        &> /dev/null
-          mount    $MOUNTPOINT    &> /dev/null
-          chkresult
-        else
-          echo -e $RESULT_FAIL
-        fi
-      else
-        echo  -e $RESULT_OK
+      
+      if [ "$MOUNTPOINT" != "none" ] ; then
+	  echo    -n "  * Mounting: $MOUNTPOINT"
+	  mount   $MOUNTPOINT         &> /dev/null
+	  if [ $? -ne "0" ] ; then
+              if [ "$DEVICE" == "usbdevfs" ] || [ "$DEVICE" == "usbfs" ] ; then          # Load the module for usbdevfs if need
+		  modprobe usbcore        &> /dev/null
+		  mount    $MOUNTPOINT    &> /dev/null
+		  chkresult
+              else
+		  echo -e $RESULT_FAIL
+              fi
+	  else
+              echo  -e $RESULT_OK
+	  fi
       fi
-    fi
-
+      
   done
-
+  
   rm         -f /fastboot /forcefsck
 }
 
 
 stop() {
-
+    
   # Establish where to get mount table from, save these since the files change if we unmount something
-  if [ -r /proc/mounts ] ; then
-    MOUNTS=/proc/mounts
-  else
-    MOUNTS=/etc/mtab
-  fi
-	
+    if [ -r /proc/mounts ] ; then
+	MOUNTS=/proc/mounts
+    else
+	MOUNTS=/etc/mtab
+    fi
+    
   # Umount all tmpfs mounts fist
   # cat it with a pipe cause it  will change if we umount anything 
-
+    
   # write wtmp in /var before umounting /var
-  reboot -w
-
-  echo -n " * Deactivating swap space:"
-  swapoff  -a
-  chkresult
-
-  echo "Umounting all filesystems:"
-
-  cat $MOUNTS | flip | \
-  while read TYPE PNT FS REST ; do
+    reboot -w
     
-    SIG="-3"
-
-    if [ "$FS" == "nfs" ] || [ "$FS" == "smbfs" ] ; then              # Don't umount smbfs and nfs because they should of been handled by another script
-      continue                                                        # and if they are here that means they are frozen, don't want anymore freezing
-    fi
-    if [ "$PNT" == "/" ] || [ "$PNT" == "/proc" ] ; then              # Leave these two for last
-      continue
-    fi
-    if [ "$PNT" == "/dev" ] ; then                                    # No need to umount /dev, and it has some unwanted sideffects anyways
-      continue
-    fi
-
-    echo  -n " * Umounting: $PNT"
-    sync ; sync                                                       # Flush buffers
-
-    if [[ "$TYPE" == "/dev/loop*" ]] ; then
-      if [ -e $PNT ] ; then                                           # Devfs and some loopback devices (iso images)
-        echo:      -n "  * Deataching loopback device $PNT:"          # can take care of them selfs
-        losetup    -d $PNT &> /dev/null
-        chkresult
-        continue                                                      # Not much we can do with loop devices
-      fi
-    fi
-
-    for TRY in "1" "2" "3" "4" ; do
-      if [ "$TRY" -eq "1" ] ; then
-        umount    $PNT  &> /dev/null
-      else
-        sleep      1                                                 # Do a little break before trying again, this helps a lot in some cases
-        if [ "$TRY" -eq "3" ] ; then
-          SIG="-9"
-        fi
-        fuser      -s -km $SIG $PNT &> /dev/null
-        sleep      1                                                 # Small delay, to make sure it gets killed
-        if [ "$TRY" -eq "4" ] ; then                                 # A real last resort
-          umount   -lf $PNT &> /dev/null
-          sleep    4                                                 # Hudge delay here, since it's lazy umount
-          sync; sync   
-        else
-          umount   $PNT &> /dev/null 
-        fi
-      fi
-
-      TEST=$(cat $MOUNTS | grep "$PNT" | awk '{ print $1}')
-      if [ -z "$TEST" ] ; then
-        echo       -e $RESULT_OK
-        continue   2
-      fi
-
-      # Debug!!!!!
-      # fuser -m -v $PNT
-
-      if [ "$TEST" == "$TYPE" ] && [ $TRY -eq "3" ] ; then            # Last resort
-        echo       -e $RESULT_WARN
-        echo       -n "  * Attempting to remount read only: $PNT"
-        sleep      1                                                  # This can help sometimes, so why not wait?
-        mount      -o remount,ro $PNT &> /dev/null
-        chkresult
-      fi
+    echo "Umounting all filesystems:"
+    
+    cat $MOUNTS | flip | \
+	while read TYPE PNT FS REST ; do
+	    
+	    SIG="-3"
+	    
+	    if [ "$FS" == "nfs" ] || [ "$FS" == "smbfs" ] ; then              # Don't umount smbfs and nfs because they should of been handled by another script
+		continue                                                        # and if they are here that means they are frozen, don't want anymore freezing
+	    fi
+	    if [ "$PNT" == "/" ] || [ "$PNT" == "/proc" ] ; then              # Leave these two for last
+		continue
+	    fi
+	    if [ "$PNT" == "/dev" ] ; then                                    # No need to umount /dev, and it has some unwanted sideffects anyways
+		continue
+	    fi
+	    
+	    echo  -n " * Umounting: $PNT"
+	    sync ; sync                                                       # Flush buffers
+	    
+	    if [[ "$TYPE" == "/dev/loop*" ]] ; then
+		if [ -e $PNT ] ; then                                           # Devfs and some loopback devices (iso images)
+		    echo:      -n "  * Deataching loopback device $PNT:"          # can take care of them selfs
+		    losetup    -d $PNT &> /dev/null
+		    chkresult
+		    continue                                                      # Not much we can do with loop devices
+		fi
+	    fi
+	    
+	    for TRY in "1" "2" "3" "4" ; do
+		if [ "$TRY" -eq "1" ] ; then
+		    umount    $PNT  &> /dev/null
+		else
+		    sleep      1                                                 # Do a little break before trying again, this helps a lot in some cases
+		    if [ "$TRY" -eq "3" ] ; then
+			SIG="-9"
+		    fi
+		    fuser      -s -km $SIG $PNT &> /dev/null
+		    sleep      1                                                 # Small delay, to make sure it gets killed
+		    if [ "$TRY" -eq "4" ] ; then                                 # A real last resort
+			umount   -lf $PNT &> /dev/null
+			sleep    4                                                 # Hudge delay here, since it's lazy umount
+			sync; sync   
+		    else
+			umount   $PNT &> /dev/null 
+		    fi
+		fi
+		
+		TEST=$(cat $MOUNTS | grep "$PNT" | awk '{ print $1}')
+		if [ -z "$TEST" ] ; then
+		    echo       -e $RESULT_OK
+		    continue   2
+		fi
+		
+                # Debug!!!!!
+                # fuser -m -v $PNT
+		
+		if [ "$TEST" == "$TYPE" ] && [ $TRY -eq "3" ] ; then            # Last resort
+		    echo       -e $RESULT_WARN
+		    echo       -n "  * Attempting to remount read only: $PNT"
+		    sleep      1                                                  # This can help sometimes, so why not wait?
+		    mount      -o remount,ro $PNT &> /dev/null
+		    chkresult
+		fi
+	    done
     done
-  done
-  
-  # Deactivate LVM or LVM2
-  if [ -e /etc/config.d/lvm -a -x /sbin/vgchange ]; then
-      /sbin/vgchange -a n
-  fi
-  
-  sync; sync
-
+    
+    echo -n " * Deactivating swap space:"
+    swapoff  -a
+    chkresult
+    
+    sync; sync
+    
   # Don't umpunt /proc because it can and will crash when umounting any remaining filesystems
   # on some systems
-
-  echo     -n " * Remounting root readonly"
-  mount    -no remount,ro / &> /dev/null
-  if [ "$?" -ne  "0" ] ; then                                         # Lazy remount, last resort
-    umount -L -O remount,ro / &> /dev/null
-    sleep  4                                                          # Again lazy needs a long timeout
-  fi
-   
-  if [ $? -ne "0" ] ; then
-    echo   -e $RESULT_FAIL
-    read   -n 1  -t 30  -p  "Do you want to login? (y/n) "  CONFIRM
-    echo   ""
-    case $CONFIRM in
-      y|Y)  sulogin ;;
-    esac
-  else
-    echo   -e $RESULT_OK
-  fi
-
+    
+    echo     -n " * Remounting root readonly"
+    mount    -no remount,ro / &> /dev/null
+    if [ "$?" -ne  "0" ] ; then                                         # Lazy remount, last resort
+	umount -L -O remount,ro / &> /dev/null
+	sleep  4                                                          # Again lazy needs a long timeout
+    fi
+    
+    if [ $? -ne "0" ] ; then
+	echo   -e $RESULT_FAIL
+	read   -n 1  -t 30  -p  "Do you want to login? (y/n) "  CONFIRM
+	echo   ""
+	case $CONFIRM in
+	    y|Y)  sulogin ;;
+	esac
+    else
+	echo   -e $RESULT_OK
+    fi
+    
   # Last chance to flush before reboot
-  sync; sync
-
+    sync; sync
+    
   # Should probly use hdparm at this point to put the hds to sleep
   # Give the hd a chance to slow down
-  sleep 2
+    sleep 2
 }
 
 # to avoid confusion we force only these options as being valid:



More information about the Lunar-commits mailing list