]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.diskless1
Add missing ca_ES, lt_LT, sr_YU aliases
[FreeBSD/FreeBSD.git] / etc / rc.diskless1
1 # Copyright (c) 1999-2002  Matt Dillion.  Terms and conditions based on
2 # the FreeBSD copyright as found at the base of the source distribution.
3 #
4 # $FreeBSD$
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/mdconfig -a -t malloc -s $1 -u $3
80     /sbin/disklabel -r -w md$3 auto
81     /sbin/newfs -i 4096 /dev/md$3c
82     /sbin/mount /dev/md$3c $2
83 }
84
85 # Create the memory filesystem if it has not already been created
86 #
87 create_md() {
88     if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
89         if [ "x`eval echo \$md_size_$1`" = "x" ]; then
90             md_size=4096
91         else
92             md_size=`eval echo \\$md_size_$1`
93         fi
94         mount_md $md_size /$1 0
95         /bin/chmod 755 /$1
96         eval md_created_$1=created
97     fi
98 }
99
100 # DEBUGGING
101 #
102 # set -v
103
104 # Figure out our interface and IP.
105 #
106 bootp_ifc=""
107 bootp_ipa=""
108 bootp_ipbca=""
109 iflist=`ifconfig -l`
110 for i in ${iflist} ; do
111     set `ifconfig ${i}`
112     while [ $# -ge 1 ] ; do
113         if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
114             bootp_ifc=${i} ; bootp_ipa=${2} ; shift
115         fi
116         if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
117             bootp_ipbca=$2; shift
118         fi
119         shift
120     done
121     if [ "${bootp_ifc}" != "" ] ; then
122         break
123     fi
124 done
125 echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
126
127 # Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
128 # and /conf/${bootp_ipa}.  For each subdirectory found within these 
129 # directories:
130 #
131 # - calculate memory filesystem sizes.  If the subdirectory (prior to
132 #   NFS remounting) contains the file 'md_size', the contents specified
133 #   in 512 byte sectors will be used to size the memory filesystem.  Otherwise
134 #   8192 sectors (4MB) is used.
135 #
136 # - handle NFS remounts.  If the subdirectory contains the file
137 #   diskless_remount, the contents of the file is NFS mounted over
138 #   the directory.  For example /conf/base/etc/diskless_remount
139 #   might contain 'myserver:/etc'.  NFS remounts allow you to avoid
140 #   having to dup your system directories in /conf.  Your server must
141 #   be sure to export those filesystems -alldirs, however.
142 #
143 for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
144     for j in /conf/$i/* ; do
145         # memory filesystem size specification
146         #
147         subdir=${j##*/}
148         if [ -d $j -a -f $j/md_size ]; then
149             eval md_size_$subdir=`cat $j/md_size`
150         fi
151
152         # NFS remount
153         #
154         if [ -d $j -a -f $j/diskless_remount ]; then
155             nfspt=`/bin/cat $j/diskless_remount`
156             mount_nfs $nfspt $j
157             chkerr $? "mount_nfs $nfspt $j"
158         fi
159     done
160 done
161
162 # - Create all required MFS filesystems and populate them from
163 #   our templates.  Support both a direct template and a dir.cpio.gz
164 #   archive.  Support dir.remove files containing a list of relative
165 #   paths to remove.
166 #
167 # TODO:
168 #   + find a way to assign a 'group' identifier to a machine
169 #       so we can use group-specific configurations;
170
171 for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
172     for j in /conf/$i/* ; do
173         subdir=${j##*/}
174         if [ -d $j ]; then
175             create_md $subdir
176             cp -Rp $j/* /$subdir
177         fi
178     done
179     for j in /conf/$i/*.cpio.gz ; do
180         subdir=${j%*.cpio.gz}
181         subdir=${subdir##*/}
182         if [ -f $j ]; then
183             create_md $subdir
184             echo "Loading /$subdir from cpio archive $j"
185             (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d )
186         fi
187     done
188     for j in /conf/$i/*.remove ; do
189         subdir=${j%*.remove}
190         subdir=${subdir##*/}
191         if [ -f $j ]; then
192             # doubly sure it is a memory disk before rm -rf'ing
193             create_md $subdir
194             (cd /$subdir; rm -rf `/bin/cat $j`)
195         fi
196     done
197 done
198
199 if [ -z "`hostname -s`" ]; then
200         hostname=`kenv dhcp.host-name`
201         hostname $hostname
202         echo "Hostname is $hostname"
203 fi
204
205 # if the info is available via dhcp/kenv
206 # build the resolv.conf
207 #
208 if [ ! -e /etc/resolv.conf ]; then
209         echo domain `kenv dhcp.domain-name` > /etc/resolv.conf
210
211         set `kenv dhcp.domain-name-servers`
212         for ns in `IFS=','; echo $*`; do
213                 echo nameserver $ns >> /etc/resolv.conf;
214         done
215 fi
216
217 # Tell /etc/rc to run the specified script after it does its mounts but
218 # before it does anything else.
219 #
220 # This script is responsible for setting up the diskless mount environment.
221 # This can be overriden by /conf/ME/rc.conf.local if, for example, you do not
222 # want to run the standard system /etc/rc.diskless2
223
224 diskless_mount="/etc/rc.diskless2"
225