home *** CD-ROM | disk | FTP | other *** search
/ ftp.sberbank.sumy.ua / 2014.11.ftp.sberbank.sumy.ua.tar / ftp.sberbank.sumy.ua / incoming / sxtech / etc / rc.diskless1 < prev    next >
Text File  |  2014-08-29  |  7KB  |  231 lines

  1. # Copyright (c) 1999-2002  Matt Dillon.  Terms and conditions based on
  2. # the FreeBSD copyright as found at the base of the source distribution.
  3. #
  4. # $FreeBSD: src/etc/rc.diskless1,v 1.5.2.14 2004/03/24 11:41:56 luigi Exp $
  5. #
  6. # /etc/rc.diskless1 - general BOOTP startup
  7. #
  8. # On entry to this script the entire system consists of a read-only root
  9. # mounted via NFS.  We use the contents of /conf to create and populate
  10. # memory filesystems.  The kernel has run BOOTP and configured an interface
  11. # (otherwise it would not have been able to mount the NFS root!)
  12. #
  13. # The following directories are scanned.  Each sucessive directory overrides
  14. # (is merged into) the previous one.
  15. #
  16. #    /conf/base        universal base
  17. #    /conf/default        modified by a secondary universal base
  18. #    /conf/${ipba}        modified based on the assigned broadcast IP
  19. #    /conf/${ip}        modified based on the machine's assigned IP
  20. #
  21. # Each of these directories may contain any number of subdirectories which
  22. # represent directories in / on the diskless machine.  The existance of
  23. # these subdirectories causes this script to create a MEMORY FILESYSTEM for
  24. # /<sub_directory_name>.  For example, if /conf/base/etc exists then a
  25. # memory filesystem will be created for /etc.
  26. #
  27. # If a subdirectory contains the file 'diskless_remount' the contents of
  28. # the file is used to remount the subdirectory prior to it being copied to
  29. # the memory filesystem.  For example, if /conf/base/etc/diskless_remount
  30. # contains the string 'my.server.com:/etc' then my.server.com:/etc will be
  31. # mounted in place of the subdirectory.  This allows you to avoid making
  32. # duplicates of system directories in /conf.
  33. #
  34. # If a subdirectory contains the file 'md_size', the contents of the
  35. # file is used to determine the size of the memory filesystem, in 512
  36. # byte sectors.  The default is 8192 (4MB).  You only have to specify an
  37. # md_size if the default doesn't work for you (i.e. if it is too big or
  38. # too small).  Note that in -current the default is 4096 (2MB).  For
  39. # example, /conf/base/etc/md_size might contain '16384'.
  40. #
  41. # If /conf/<special_dir>/SUBDIR.cpio.gz exists, the file is cpio'd into
  42. # the specified /SUBDIR (and a memory filesystem is created for /SUBDIR
  43. # if necessary).
  44. #
  45. # If /conf/<special_dir>/SUBDIR.remove exists, the file contains a list
  46. # of paths which are rm -rf'd relative to /SUBDIR.
  47. #
  48. # You will almost universally want to create a /conf/base/etc containing
  49. # a diskless_remount and possibly an md_size file.  You will then almost
  50. # universally want to override rc.conf, rc.local, and fstab by creating
  51. # /conf/default/etc/{rc.conf,rc.local,fstab}.  Your fstab should be sure
  52. # to mount a /usr... typically an NFS readonly /usr.
  53. #
  54. # NOTE!  rc.diskless2 will create /var, /tmp, and /dev.  Those filesystems
  55. # should not be specified in /conf.  At least not yet.
  56.  
  57. # chkerr:
  58. #
  59. # Routine to check for error
  60. #
  61. #    checks error code and drops into shell on failure.
  62. #    if shell exits, terminates script as well as /etc/rc.
  63. #
  64. chkerr() {
  65.     case $1 in
  66.     0)
  67.     ;;
  68.     *)
  69.     echo "$2 failed: dropping into /bin/sh"
  70.     /bin/sh
  71.     # RESUME
  72.     ;;
  73.     esac
  74. }
  75.  
  76. # Create a generic memory disk
  77. #
  78. mount_md() {
  79.     /sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 dummy $2
  80. }
  81.  
  82. # Create the memory filesystem if it has not already been created
  83. #
  84. create_md() {
  85.     if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
  86.     if [ "x`eval echo \\$md_size_$1`" = "x" ]; then
  87.         md_size=8192
  88.     else
  89.         md_size=`eval echo \\$md_size_$1`
  90.     fi
  91.     mount_md $md_size /$1
  92.     /bin/chmod 755 /$1
  93.     eval md_created_$1=created
  94.     fi
  95. }
  96.  
  97. # DEBUGGING
  98. #
  99. # set -v
  100.  
  101. # Figure out our interface and IP.
  102. #
  103. bootp_ifc=""
  104. bootp_ipa=""
  105. bootp_ipbca=""
  106. iflist=`ifconfig -l`
  107. for i in ${iflist} ; do
  108.     set `ifconfig ${i}`
  109.     while [ $# -ge 1 ] ; do
  110.         if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
  111.             bootp_ifc=${i} ; bootp_ipa=${2} ; shift
  112.         fi
  113.         if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
  114.             bootp_ipbca=$2; shift
  115.         fi
  116.         shift
  117.     done
  118.     if [ "${bootp_ifc}" != "" ] ; then
  119.         break
  120.     fi
  121. done
  122. # Insert the directories passed with the T134 bootp cookie
  123. # in the list of paths used for templates.
  124. #
  125. bootp_cookie="`/sbin/sysctl -n kern.bootp_cookie`"
  126. if [ "${bootp_cookie}" != "" ] ; then
  127.     bootp_ipbca="${bootp_ipbca} ${bootp_cookie}"
  128. fi
  129.  
  130. echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
  131.  
  132. # Figure out our NFS root path
  133. set `mount -t nfs`
  134. while [ $# -ge 1 ] ; do
  135.     if [ "$2" = "on" -a "$3" = "/" ]; then
  136.     nfsroot="$1"
  137.     break
  138.     fi
  139.     shift
  140. done
  141.  
  142. # Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
  143. # and /conf/${bootp_ipa}.  For each subdirectory found within these 
  144. # directories:
  145. #
  146. # - calculate memory filesystem sizes.  If the subdirectory (prior to
  147. #   NFS remounting) contains the file 'md_size', the contents specified
  148. #   in 512 byte sectors will be used to size the memory filesystem.  Otherwise
  149. #   8192 sectors (4MB) is used.
  150. #
  151. # - handle NFS remounts.  If the subdirectory contains the file
  152. #   diskless_remount, the contents of the file is NFS mounted over
  153. #   the directory.  For example /conf/base/etc/diskless_remount
  154. #   might contain 'myserver:/etc'.  NFS remounts allow you to avoid
  155. #   having to dup your system directories in /conf.  Your server must
  156. #   be sure to export those filesystems -alldirs, however.
  157. #   If the diskless_remount file contains a string beginning with a
  158. #   '/' it is assumed that the local nfsroot should be prepended to
  159. #   it before attemping to the remount.  This allows the root to be
  160. #   relocated without needing to change the remount files.
  161. #
  162. for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
  163.     for j in /conf/$i/* ; do
  164.     # memory filesystem size specification
  165.     #
  166.     subdir=${j##*/}
  167.     if [ -d $j -a -f $j/md_size ]; then
  168.         eval md_size_$subdir=`cat $j/md_size`
  169.     fi
  170.  
  171.     # NFS remount
  172.     #
  173.     if [ -d $j -a -f $j/diskless_remount ]; then
  174.         nfspt=`/bin/cat $j/diskless_remount`
  175.         if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then
  176.         nfspt="${nfsroot}${nfspt}"
  177.         fi
  178.         mount_nfs $nfspt $j
  179.         chkerr $? "mount_nfs $nfspt $j"
  180.     fi
  181.     done
  182. done
  183.  
  184. # - Create all required MFS filesystems and populate them from
  185. #   our templates.  Support both a direct template and a dir.cpio.gz
  186. #   archive.  Support dir.remove files containing a list of relative
  187. #   paths to remove.
  188. #
  189. # The dir.cpio.gz form is there to make the copy process more efficient,
  190. # so if the cpio archive is present, it prevents the files from dir/
  191. # from being copied.
  192.  
  193. for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
  194.     for j in /conf/$i/* ; do
  195.     subdir=${j##*/}
  196.     if [ -d $j -a ! -f $j.cpio.gz  ]; then
  197.         create_md $subdir
  198.         cp -Rp $j/* /$subdir
  199.     fi
  200.     done
  201.     for j in /conf/$i/*.cpio.gz ; do
  202.     subdir=${j%*.cpio.gz}
  203.     subdir=${subdir##*/}
  204.     if [ -f $j ]; then
  205.         create_md $subdir
  206.         echo "Loading /$subdir from cpio archive $j"
  207.         (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d )
  208.     fi
  209.     done
  210.     for j in /conf/$i/*.remove ; do
  211.     subdir=${j%*.remove}
  212.     subdir=${subdir##*/}
  213.     if [ -f $j ]; then
  214.         # doubly sure it is a memory disk before rm -rf'ing
  215.         create_md $subdir
  216.         (cd /$subdir; rm -rf `/bin/cat $j`)
  217.     fi
  218.     done
  219. done
  220.  
  221. # Tell /etc/rc to run the specified script after
  222. # it does its mounts but before it does anything
  223. # else.
  224. #
  225. # This script is responsible for setting up the
  226. # diskless mount environment.
  227.  
  228. diskless_mount="/etc/rc.diskless2"
  229.  
  230.