# Copyright (c) 1999 Matt Dillion # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # # # /etc/rc.diskless1 - general BOOTP startup # # We assume that the shared readonly partition has been created with # the script /usr/share/examples/diskless/clone_root or similar # methods. # # BOOTP has mounted / for us. We assume a read-only mount, and that the # /conf subdirectory contains the following: # + /conf/base/etc # a copy of /etc, prepared by e.g. the clone_root script # + /conf/default # default files that override the ones in the readonly root # + /conf/${ipba} (${ipba} is the subnet broadcast address for the host) # subnet-specific files that override the ones in the readonly root # + /conf/${ip} (${ip} is the ip address for the host) # host-specific files that override the ones in the readonly root # # Now we need to do the following: # + figure out our IP by querying the interface # + mount /etc as an MFS # + populate /etc from /conf/base/etc # + override files in /etc with files from /conf/{default,${ipba},${ip}/etc # # The operator is in charge of setting /conf/*/etc/* things as appropriate. # Typically rc.conf and fstab need to be changed, but possibly # also other files such as inetd.conf etc. # chkerr: # # Routine to check for error # # checks error code and drops into shell on failure. # if shell exits, terminates script as well as /etc/rc. # chkerr() { case $1 in 0) ;; *) echo "$2 failed: dropping into /bin/sh" /bin/sh # RESUME ;; esac } mount_md() { /sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 dummy $2 } # DEBUGGING # # set -v # Figure out our interface and IP. # bootp_ifc="" bootp_ipa="" bootp_ipbca="" iflist=`ifconfig -l` for i in ${iflist} ; do set `ifconfig ${i}` while [ $# -ge 1 ] ; do if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then bootp_ifc=${i} ; bootp_ipa=${2} ; shift fi if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then bootp_ipbca=$2; shift fi shift done if [ "${bootp_ifc}" != "" ] ; then break fi done echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}" # Create an MFS /tmp to temporarily hold files from /etc until we # can bootstrap /etc as an MFS. mount_md 8192 /etc 0 chkerr $? "MFS mount on /etc" /bin/chmod 755 /etc # Populate /etc, and then override the base setup with increasingly # specific files. # The copy, especially the one with the initial content, touches # a large number of files, and can be very slow if the server is # far away. So, if there exists a cpio archive with the proper # content, use that one instead. # # TODO: # + find a way to assign a 'group' identifier to a machine # so we can use group-specific configurations; # + implement a way to _delete_ files when overriding configs. for i in base default ${bootp_ipbca} ${bootp_ipa} ; do if [ -f /conf/${i}/etc.cpio.gz ]; then echo "Loading ${i}/etc from cpio archive" (cd / ; /stand/gzip -d < /conf/${i}/etc.cpio.gz | \ /stand/cpio --extract -d ) elif [ -d /conf/${i}/etc ]; then cp -Rp /conf/${i}/etc/* /etc fi done # Tell /etc/rc to run the specified script after # it does its mounts but before it does anything # else. # # This script is responsible for setting up the # diskless mount environment. diskless_mount="/etc/rc.diskless2"