rc.initdiskless revision 75931
166830Sobrien# Copyright (c) 1999 Matt Dillion 266830Sobrien# All rights reserved. 366830Sobrien# 466830Sobrien# Redistribution and use in source and binary forms, with or without 566830Sobrien# modification, are permitted provided that the following conditions 666830Sobrien# are met: 766830Sobrien# 1. Redistributions of source code must retain the above copyright 866830Sobrien# notice, this list of conditions and the following disclaimer. 966830Sobrien# 2. Redistributions in binary form must reproduce the above copyright 1066830Sobrien# notice, this list of conditions and the following disclaimer in the 1166830Sobrien# documentation and/or other materials provided with the distribution. 1266830Sobrien# 1366830Sobrien# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1466830Sobrien# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1566830Sobrien# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1666830Sobrien# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1766830Sobrien# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1866830Sobrien# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1966830Sobrien# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2066830Sobrien# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2166830Sobrien# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2266830Sobrien# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2366830Sobrien# SUCH DAMAGE. 2466830Sobrien# 2551231Ssheldonh# $FreeBSD: head/etc/rc.initdiskless 75931 2001-04-25 05:46:40Z imp $ 2651231Ssheldonh# 2766830Sobrien 2866830Sobrien# 2955520Sluigi# /etc/rc.diskless1 - general BOOTP startup 3043803Sdillon# 3155520Sluigi# BOOTP has mounted / for us. Assume a read-only mount. We must then 3255520Sluigi# - figure out our IP by querying the interface 3375746Sbsd# - copy /etc temporarily out of the way to /tmp/etc 3475746Sbsd# - mount /etc as an MFS 3575746Sbsd# - repopulate /etc with the saved off copy 3675746Sbsd# - override files in /etc with files from /conf/*/etc where 3775746Sbsd# '*' is default, netmask of client, ip-address of client 3843803Sdillon# 3955520Sluigi# WARNING: i thing you should not change /etc/rc or strange things could 4055520Sluigi# happen. 4143803Sdillon# 4255520Sluigi# The operator is in charge of setting /conf/*/etc/* things as appropriate. 4355520Sluigi# Typically rc.conf and fstab need to be changed, but possibly 4455520Sluigi# also other files such as inetd.conf etc. 4543803Sdillon 4643803Sdillon# chkerr: 4743803Sdillon# 4843803Sdillon# Routine to check for error 4943803Sdillon# 5043803Sdillon# checks error code and drops into shell on failure. 5143803Sdillon# if shell exits, terminates script as well as /etc/rc. 5251231Ssheldonh# 5343803Sdillonchkerr() { 5451231Ssheldonh case $1 in 5551231Ssheldonh 0) 5651231Ssheldonh ;; 5751231Ssheldonh *) 5843803Sdillon echo "$2 failed: dropping into /bin/sh" 5943803Sdillon /bin/sh 6043803Sdillon # RESUME 6151231Ssheldonh ;; 6251231Ssheldonh esac 6343803Sdillon} 6443803Sdillon 6575931Simpmount_md() { 6675931Simp /sbin/mdconfig -a -t malloc -s $1 -u $3 6775931Simp /sbin/disklabel -r -w md$3 auto 6875931Simp /sbin/newfs /dev/md$3c 6975931Simp /sbin/mount /dev/md$3c $2 7075931Simp} 7175931Simp 7243803Sdillon# DEBUGGING 7343803Sdillon# 7455520Sluigi# set -v 7543803Sdillon 7651231Ssheldonh# Figure out our interface and IP. 7743803Sdillon# 7855520Sluigibootp_ifc="" 7955520Sluigibootp_ipa="" 8055520Sluigibootp_ipbca="" 8155520Sluigiiflist=`ifconfig -l` 8255520Sluigifor i in ${iflist} ; do 8355520Sluigi set `ifconfig ${i}` 8455520Sluigi while [ $# -ge 1 ] ; do 8555520Sluigi if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then 8655520Sluigi bootp_ifc=${i} ; bootp_ipa=${2} ; shift 8755520Sluigi fi 8855520Sluigi if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then 8955520Sluigi bootp_ipbca=$2; shift 9055520Sluigi fi 9155520Sluigi shift 9255520Sluigi done 9355520Sluigi if [ "${bootp_ifc}" != "" ] ; then 9455520Sluigi break 9555520Sluigi fi 9655520Sluigidone 9755520Sluigiecho "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}" 9843803Sdillon 9975101Sbsd 10075746Sbsd# Create an MFS /tmp to temporarily hold files from /etc until we 10175746Sbsd# can bootstrap /etc as an MFS. 10275101Sbsd 10375931Simpmount_md 4096 /tmp 0 10475931Simpchmod 1777 /tmp 10575746Sbsdchkerr $? "MFS mount on /tmp" 10675746Sbsd/bin/cp -Rp /etc /tmp 10775746Sbsdchkerr $? "cp /etc to /tmp/etc MFS" 10875101Sbsd 10975931Simpmount_md 4096 /etc 1 11075746Sbsdchkerr $? "MFS mount on /etc" 11175746Sbsd/bin/chmod 755 /etc 11243803Sdillon 11375746Sbsd/bin/cp -Rp /tmp/etc/* /etc 11475746Sbsdchkerr $? "cp /tmp/etc to /etc MFS" 11575746Sbsd 11675746Sbsdrm -rf /tmp/etc 11775746Sbsd/sbin/umount /tmp 11875931Simp/sbin/mdconfig -d -u 0 11975746Sbsd 12075746Sbsd# Allow for override files to replace files in /etc. Use /conf/*/etc 12175746Sbsd# to find the override files. First choice is default files that 12275746Sbsd# always override, then files that from the directory that matches the 12375746Sbsd# client's broadcast address, finally followed by overrides that match 12475746Sbsd# the client's IP address. 12543803Sdillon# 12675746Sbsd# This way we have some flexibility to handle clusters of machines 12775746Sbsd# on separate subnets. 12875746Sbsd# 12943803Sdillon 13075746Sbsdfor i in default ${bootp_ipbca} ${bootp_ipa} ; do 13175746Sbsd if [ -d /conf/${i}/etc ]; then 13275746Sbsd cp -Rp /conf/${i}/etc/* /etc 13375746Sbsd fi 13475746Sbsddone 13575746Sbsd 13643803Sdillon# Tell /etc/rc to run the specified script after 13743803Sdillon# it does its mounts but before it does anything 13843803Sdillon# else. 13943803Sdillon# 14043803Sdillon# This script is responsible for setting up the 14151231Ssheldonh# diskless mount environment. This can be 14243803Sdillon# overriden by /conf/ME/rc.conf.local if, for 14343803Sdillon# example, you do not want to run the standard 14443803Sdillon# system /etc/rc.diskless2 14543803Sdillon 14643803Sdillondiskless_mount="/etc/rc.diskless2" 147