rc.initdiskless revision 89437
198184Sgordon# Copyright (c) 1999  Matt Dillion
298184Sgordon# All rights reserved.
398184Sgordon#
498184Sgordon# Redistribution and use in source and binary forms, with or without
598184Sgordon# modification, are permitted provided that the following conditions
698184Sgordon# are met:
798184Sgordon# 1. Redistributions of source code must retain the above copyright
898184Sgordon#    notice, this list of conditions and the following disclaimer.
998184Sgordon# 2. Redistributions in binary form must reproduce the above copyright
1098184Sgordon#    notice, this list of conditions and the following disclaimer in the
1198184Sgordon#    documentation and/or other materials provided with the distribution.
1298184Sgordon#
1398184Sgordon# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1498184Sgordon# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1598184Sgordon# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1698184Sgordon# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1798184Sgordon# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1898184Sgordon# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1998184Sgordon# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2098184Sgordon# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2198184Sgordon# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2298184Sgordon# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2398184Sgordon# SUCH DAMAGE.
2498184Sgordon#
2598184Sgordon# $FreeBSD: head/etc/rc.initdiskless 89437 2002-01-17 00:08:44Z rwatson $
2698184Sgordon#
2798184Sgordon
2898184Sgordon#
2998184Sgordon# /etc/rc.diskless1 - general BOOTP startup
3098184Sgordon#
3198184Sgordon# BOOTP has mounted / for us.  Assume a read-only mount.  We must then
3298184Sgordon# - figure out our IP by querying the interface
3398184Sgordon# - mount /etc as an MFS
3498184Sgordon# - populate /etc from /conf/default version
3598184Sgordon# - override files in /etc with files from /conf/*/etc where
3698184Sgordon#   '*' is default, netmask of client, ip-address of client
3798184Sgordon#
3898184Sgordon# The operator is in charge of setting /conf/*/etc/* things as appropriate.
3998184Sgordon# Typically rc.conf and fstab need to be changed, but possibly also other
4098184Sgordon# files such as inetd.conf etc.
4198184Sgordon
4298184Sgordon# chkerr:
4398184Sgordon#
4498184Sgordon# Routine to check for error
4598184Sgordon#
4698184Sgordon#	checks error code and drops into shell on failure.
4798184Sgordon#	if shell exits, terminates script as well as /etc/rc.
4898184Sgordon#
4998184Sgordonchkerr() {
5098184Sgordon	case $1 in
5198184Sgordon	0)
5298184Sgordon		;;
5398184Sgordon	*)
5498184Sgordon		echo "$2 failed: dropping into /bin/sh"
5598184Sgordon		/bin/sh
5698184Sgordon		# RESUME
5798184Sgordon		;;
5898184Sgordon	esac
5998184Sgordon}
6098184Sgordon
6198184Sgordonmount_md() {
6298184Sgordon	/sbin/mdconfig -a -t malloc -s $1 -u $3
6398184Sgordon	/sbin/disklabel -r -w md$3 auto
6498184Sgordon	/sbin/newfs /dev/md$3c
6598184Sgordon	/sbin/mount /dev/md$3c $2
6698184Sgordon}
6798184Sgordon
6898184Sgordon# DEBUGGING
6998184Sgordon#
7098184Sgordon# set -v
71
72# Figure out our interface and IP.
73#
74bootp_ifc=""
75bootp_ipa=""
76bootp_ipbca=""
77iflist=`ifconfig -l`
78for i in ${iflist} ; do
79    set `ifconfig ${i}`
80    while [ $# -ge 1 ] ; do
81        if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then
82            bootp_ifc=${i} ; bootp_ipa=${2} ; shift
83        fi
84        if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then
85            bootp_ipbca=$2; shift
86        fi
87        shift
88    done
89    if [ "${bootp_ifc}" != "" ] ; then
90        break
91    fi
92done
93echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
94
95
96mount_md 4096 /etc 0
97chkerr $? "MFS mount on /etc"
98/bin/chmod 755 /etc
99
100/bin/cp -Rp /conf/default/etc/* /etc
101chkerr $? "cp /conf/default/etc to /etc MFS"
102
103# Allow for override files to replace files in /etc.  Use /conf/*/etc
104# to find the override files.  First choice is default files that
105# always override, then files that from the directory that matches the
106# client's broadcast address, finally followed by overrides that match
107# the client's IP address.
108#
109# This way we have some flexibility to handle clusters of machines
110# on separate subnets.
111#
112
113for i in ${bootp_ipbca} ${bootp_ipa} ; do
114	if [ -d /conf/${i}/etc ]; then
115		cp -Rp /conf/${i}/etc/* /etc
116	fi
117done
118
119# Tell /etc/rc to run the specified script after
120# it does its mounts but before it does anything
121# else.
122#
123# This script is responsible for setting up the
124# diskless mount environment.  This can be
125# overriden by /conf/ME/rc.conf.local if, for
126# example, you do not want to run the standard
127# system /etc/rc.diskless2
128
129diskless_mount="/etc/rc.diskless2"
130