rc.initdiskless revision 95280
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 95280 2002-04-22 21:42:18Z obrien $ 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# - mount /etc as an MFS 3488496Srwatson# - populate /etc from /conf/default version 3575746Sbsd# - override files in /etc with files from /conf/*/etc where 3675746Sbsd# '*' is default, netmask of client, ip-address of client 3743803Sdillon# 3855520Sluigi# The operator is in charge of setting /conf/*/etc/* things as appropriate. 3989437Srwatson# Typically rc.conf and fstab need to be changed, but possibly also other 4089437Srwatson# files such as inetd.conf etc. 4143803Sdillon 4243803Sdillon# chkerr: 4343803Sdillon# 4443803Sdillon# Routine to check for error 4543803Sdillon# 4643803Sdillon# checks error code and drops into shell on failure. 4743803Sdillon# if shell exits, terminates script as well as /etc/rc. 4851231Ssheldonh# 4943803Sdillonchkerr() { 5051231Ssheldonh case $1 in 5151231Ssheldonh 0) 5251231Ssheldonh ;; 5351231Ssheldonh *) 5443803Sdillon echo "$2 failed: dropping into /bin/sh" 5543803Sdillon /bin/sh 5643803Sdillon # RESUME 5751231Ssheldonh ;; 5851231Ssheldonh esac 5943803Sdillon} 6043803Sdillon 6175931Simpmount_md() { 6275931Simp /sbin/mdconfig -a -t malloc -s $1 -u $3 6375931Simp /sbin/disklabel -r -w md$3 auto 6475931Simp /sbin/newfs /dev/md$3c 6575931Simp /sbin/mount /dev/md$3c $2 6675931Simp} 6775931Simp 6843803Sdillon# DEBUGGING 6943803Sdillon# 7055520Sluigi# set -v 7143803Sdillon 7251231Ssheldonh# Figure out our interface and IP. 7343803Sdillon# 7455520Sluigibootp_ifc="" 7555520Sluigibootp_ipa="" 7655520Sluigibootp_ipbca="" 7755520Sluigiiflist=`ifconfig -l` 7855520Sluigifor i in ${iflist} ; do 7955520Sluigi set `ifconfig ${i}` 8055520Sluigi while [ $# -ge 1 ] ; do 8155520Sluigi if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then 8255520Sluigi bootp_ifc=${i} ; bootp_ipa=${2} ; shift 8355520Sluigi fi 8455520Sluigi if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then 8555520Sluigi bootp_ipbca=$2; shift 8655520Sluigi fi 8755520Sluigi shift 8855520Sluigi done 8955520Sluigi if [ "${bootp_ifc}" != "" ] ; then 9055520Sluigi break 9155520Sluigi fi 9255520Sluigidone 9355520Sluigiecho "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}" 9443803Sdillon 9595280Sobrienif [ -z "`hostname -s`" ]; then 9695280Sobrien hostname=`kenv dhcp.host-name` 9795280Sobrien hostname $hostname 9895280Sobrien echo "Hostname is $hostname" 9995280Sobrienfi 10095280Sobrien 10191074Sobrienif [ -d /conf/default/etc ]; then 10291074Sobrien mount_md 4096 /etc 0 10391074Sobrien chkerr $? "MFS mount on /etc" 10491074Sobrien /bin/chmod 755 /etc 10575101Sbsd 10691074Sobrien /bin/cp -Rp /conf/default/etc/* /etc 10791074Sobrien chkerr $? "cp /conf/default/etc to /etc MFS" 10891074Sobrienfi 10943803Sdillon 11089438Srwatson# Allow for override files to replace files in /etc. Use /conf/*/etc to find 11189438Srwatson# the override files. First choice is default files that # always override, 11289438Srwatson# then files that from the directory that matches the client's broadcast 11389438Srwatson# address, finally followed by overrides that match the client's IP address. 11443803Sdillon# 11589438Srwatson# This way we have some flexibility to handle clusters of machines on 11689438Srwatson# separate subnets. 11743803Sdillon 11895280Sobrienfor i in ${bootp_ipbca} ${bootp_ipa} ${hostname} ; do 11975746Sbsd if [ -d /conf/${i}/etc ]; then 12075746Sbsd cp -Rp /conf/${i}/etc/* /etc 12175746Sbsd fi 12275746Sbsddone 12375746Sbsd 12495280Sobrien# 12595280Sobrien# if the info is available via dhcp/kenv 12695280Sobrien# build the resolv.conf 12795280Sobrien# 12895280Sobrienif [ ! -e /etc/resolv.conf ]; then 12995280Sobrien echo domain `kenv dhcp.domain-name` > /etc/resolv.conf 13095280Sobrien 13195280Sobrien set `kenv dhcp.domain-name-servers` 13295280Sobrien for ns in `IFS=','; echo $*`; do 13395280Sobrien echo nameserver $ns >> /etc/resolv.conf; 13495280Sobrien done 13595280Sobrienfi 13695280Sobrien 13789438Srwatson# Tell /etc/rc to run the specified script after it does its mounts but 13889438Srwatson# before it does anything else. 13943803Sdillon# 14089438Srwatson# This script is responsible for setting up the diskless mount environment. 14189438Srwatson# This can be overriden by /conf/ME/rc.conf.local if, for example, you do not 14289438Srwatson# want to run the standard system /etc/rc.diskless2 14343803Sdillon 14443803Sdillondiskless_mount="/etc/rc.diskless2" 145