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.
6 # /etc/rc.diskless1 - general BOOTP startup
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!)
13 # The following directories are scanned. Each sucessive directory overrides
14 # (is merged into) the previous one.
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
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.
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.
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'.
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
45 # If /conf/<special_dir>/SUBDIR.remove exists, the file contains a list
46 # of paths which are rm -rf'd relative to /SUBDIR.
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.
54 # NOTE! rc.diskless2 will create /var, /tmp, and /dev. Those filesystems
55 # should not be specified in /conf. At least not yet.
59 # Routine to check for error
61 # checks error code and drops into shell on failure.
62 # if shell exits, terminates script as well as /etc/rc.
69 echo "$2 failed: dropping into /bin/sh"
76 # Create a generic memory disk
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
85 # Create the memory filesystem if it has not already been created
88 if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
89 if [ "x`eval echo \$md_size_$1`" = "x" ]; then
92 md_size=`eval echo \\$md_size_$1`
94 mount_md $md_size /$1 0
96 eval md_created_$1=created
104 # Figure out our interface and IP.
110 for i in ${iflist} ; do
112 while [ $# -ge 1 ] ; do
113 if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
114 bootp_ifc=${i} ; bootp_ipa=${2} ; shift
116 if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
117 bootp_ipbca=$2; shift
121 if [ "${bootp_ifc}" != "" ] ; then
125 echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
127 # Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
128 # and /conf/${bootp_ipa}. For each subdirectory found within these
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.
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.
143 for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
144 for j in /conf/$i/* ; do
145 # memory filesystem size specification
148 if [ -d $j -a -f $j/md_size ]; then
149 eval md_size_$subdir=`cat $j/md_size`
154 if [ -d $j -a -f $j/diskless_remount ]; then
155 nfspt=`/bin/cat $j/diskless_remount`
157 chkerr $? "mount_nfs $nfspt $j"
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
168 # + find a way to assign a 'group' identifier to a machine
169 # so we can use group-specific configurations;
171 for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
172 for j in /conf/$i/* ; do
179 for j in /conf/$i/*.cpio.gz ; do
180 subdir=${j%*.cpio.gz}
184 echo "Loading /$subdir from cpio archive $j"
185 (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d )
188 for j in /conf/$i/*.remove ; do
192 # doubly sure it is a memory disk before rm -rf'ing
194 (cd /$subdir; rm -rf `/bin/cat $j`)
199 if [ -z "`hostname -s`" ]; then
200 hostname=`kenv dhcp.host-name`
202 echo "Hostname is $hostname"
205 # if the info is available via dhcp/kenv
206 # build the resolv.conf
208 if [ ! -e /etc/resolv.conf ]; then
209 echo domain `kenv dhcp.domain-name` > /etc/resolv.conf
211 set `kenv dhcp.domain-name-servers`
212 for ns in `IFS=','; echo $*`; do
213 echo nameserver $ns >> /etc/resolv.conf;
217 # Tell /etc/rc to run the specified script after it does its mounts but
218 # before it does anything else.
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
224 diskless_mount="/etc/rc.diskless2"