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.
4 # $FreeBSD: src/etc/rc.diskless1,v 1.5.2.11 2003/04/14 18:12:05 jhay Exp $
5 # $DragonFly: src/etc/Attic/rc.diskless1,v 1.2 2003/06/17 04:24:45 dillon Exp $
7 # /etc/rc.diskless1 - general BOOTP startup
9 # On entry to this script the entire system consists of a read-only root
10 # mounted via NFS. We use the contents of /conf to create and populate
11 # memory filesystems. The kernel has run BOOTP and configured an interface
12 # (otherwise it would not have been able to mount the NFS root!)
14 # The following directories are scanned. Each sucessive directory overrides
15 # (is merged into) the previous one.
17 # /conf/base universal base
18 # /conf/default modified by a secondary universal base
19 # /conf/${ipba} modified based on the assigned broadcast IP
20 # /conf/${ip} modified based on the machine's assigned IP
22 # Each of these directories may contain any number of subdirectories which
23 # represent directories in / on the diskless machine. The existance of
24 # these subdirectories causes this script to create a MEMORY FILESYSTEM for
25 # /<sub_directory_name>. For example, if /conf/base/etc exists then a
26 # memory filesystem will be created for /etc.
28 # If a subdirectory contains the file 'diskless_remount' the contents of
29 # the file is used to remount the subdirectory prior to it being copied to
30 # the memory filesystem. For example, if /conf/base/etc/diskless_remount
31 # contains the string 'my.server.com:/etc' then my.server.com:/etc will be
32 # mounted in place of the subdirectory. This allows you to avoid making
33 # duplicates of system directories in /conf.
35 # If a subdirectory contains the file 'md_size', the contents of the
36 # file is used to determine the size of the memory filesystem, in 512
37 # byte sectors. The default is 8192 (4MB). You only have to specify an
38 # md_size if the default doesn't work for you (i.e. if it is too big or
39 # too small). Note that in -current the default is 4096 (2MB). For
40 # example, /conf/base/etc/md_size might contain '16384'.
42 # If /conf/<special_dir>/SUBDIR.cpio.gz exists, the file is cpio'd into
43 # the specified /SUBDIR (and a memory filesystem is created for /SUBDIR
46 # If /conf/<special_dir>/SUBDIR.remove exists, the file contains a list
47 # of paths which are rm -rf'd relative to /SUBDIR.
49 # You will almost universally want to create a /conf/base/etc containing
50 # a diskless_remount and possibly an md_size file. You will then almost
51 # universally want to override rc.conf, rc.local, and fstab by creating
52 # /conf/default/etc/{rc.conf,rc.local,fstab}. Your fstab should be sure
53 # to mount a /usr... typically an NFS readonly /usr.
55 # NOTE! rc.diskless2 will create /var, /tmp, and /dev. Those filesystems
56 # should not be specified in /conf. At least not yet.
60 # Routine to check for error
62 # checks error code and drops into shell on failure.
63 # if shell exits, terminates script as well as /etc/rc.
70 echo "$2 failed: dropping into /bin/sh"
77 # Create a generic memory disk
80 /sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 dummy $2
83 # Create the memory filesystem if it has not already been created
86 if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
87 if [ "x`eval echo \\$md_size_$1`" = "x" ]; then
90 md_size=`eval echo \\$md_size_$1`
94 eval md_created_$1=created
102 # Figure out our interface and IP.
108 for i in ${iflist} ; do
110 while [ $# -ge 1 ] ; do
111 if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
112 bootp_ifc=${i} ; bootp_ipa=${2} ; shift
114 if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
115 bootp_ipbca=$2; shift
119 if [ "${bootp_ifc}" != "" ] ; then
123 echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
125 # Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
126 # and /conf/${bootp_ipa}. For each subdirectory found within these
129 # - calculate memory filesystem sizes. If the subdirectory (prior to
130 # NFS remounting) contains the file 'md_size', the contents specified
131 # in 512 byte sectors will be used to size the memory filesystem. Otherwise
132 # 8192 sectors (4MB) is used.
134 # - handle NFS remounts. If the subdirectory contains the file
135 # diskless_remount, the contents of the file is NFS mounted over
136 # the directory. For example /conf/base/etc/diskless_remount
137 # might contain 'myserver:/etc'. NFS remounts allow you to avoid
138 # having to dup your system directories in /conf. Your server must
139 # be sure to export those filesystems -alldirs, however.
141 for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
142 for j in /conf/$i/* ; do
143 # memory filesystem size specification
146 if [ -d $j -a -f $j/md_size ]; then
147 eval md_size_$subdir=`cat $j/md_size`
152 if [ -d $j -a -f $j/diskless_remount ]; then
153 nfspt=`/bin/cat $j/diskless_remount`
155 chkerr $? "mount_nfs $nfspt $j"
160 # - Create all required MFS filesystems and populate them from
161 # our templates. Support both a direct template and a dir.cpio.gz
162 # archive. Support dir.remove files containing a list of relative
166 # + find a way to assign a 'group' identifier to a machine
167 # so we can use group-specific configurations;
169 for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
170 for j in /conf/$i/* ; do
177 for j in /conf/$i/*.cpio.gz ; do
178 subdir=${j%*.cpio.gz}
182 echo "Loading /$subdir from cpio archive $j"
183 (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d )
186 for j in /conf/$i/*.remove ; do
190 # doubly sure it is a memory disk before rm -rf'ing
192 (cd /$subdir; rm -rf `/bin/cat $j`)
197 # Tell /etc/rc to run the specified script after
198 # it does its mounts but before it does anything
201 # This script is responsible for setting up the
202 # diskless mount environment.
204 diskless_mount="/etc/rc.diskless2"