head	1.42;
access;
symbols
	RELENG_5_5_0_RELEASE:1.38.2.5
	RELENG_5_5:1.38.2.5.0.2
	RELENG_5_5_BP:1.38.2.5
	RELENG_5_4_0_RELEASE:1.38.2.2
	RELENG_5_4:1.38.2.2.0.2
	RELENG_5_4_BP:1.38.2.2
	RELENG_5_3_0_RELEASE:1.38.2.1
	RELENG_5_3:1.38.2.1.0.2
	RELENG_5_3_BP:1.38.2.1
	RELENG_5:1.38.0.2
	RELENG_5_BP:1.38
	RELENG_5_2_1_RELEASE:1.28
	RELENG_5_2_0_RELEASE:1.28
	RELENG_5_2:1.28.0.2
	RELENG_5_2_BP:1.28
	RELENG_5_1_0_RELEASE:1.23
	RELENG_5_1:1.23.0.2
	RELENG_5_1_BP:1.23
	RELENG_5_0_0_RELEASE:1.21
	RELENG_5_0:1.21.0.2
	RELENG_5_0_BP:1.21
	old_RELENG_4_6_1_RELEASE:1.5.2.9
	old_RELENG_4_6_0_RELEASE:1.5.2.9
	old_RELENG_4_6:1.5.2.9.0.2
	old_RELENG_4_6_BP:1.5.2.9
	old_RELENG_4_5_0_RELEASE:1.5.2.6
	old_RELENG_4_5:1.5.2.6.0.4
	old_RELENG_4_5_BP:1.5.2.6
	old_RELENG_4_4_0_RELEASE:1.5.2.6
	old_RELENG_4_4:1.5.2.6.0.2
	old_RELENG_4_4_BP:1.5.2.6
	old_RELENG_4_3_0_RELEASE:1.5.2.5
	old_RELENG_4_3:1.5.2.5.0.2
	old_RELENG_4_3_BP:1.5.2.5
	old_RELENG_4_2_0_RELEASE:1.5.2.1
	old_RELENG_4_1_1_RELEASE:1.5
	old_PRE_SMPNG:1.5
	old_RELENG_4_1_0_RELEASE:1.5
	old_RELENG_3_5_0_RELEASE:1.1.2.1
	old_RELENG_4_0_0_RELEASE:1.5
	old_RELENG_4:1.5.0.2
	old_RELENG_4_BP:1.5
	old_RELENG_3_4_0_RELEASE:1.1.2.1
	old_RELENG_3_3_0_RELEASE:1.1.2.1
	old_RELENG_3_2_PAO:1.1.2.1.0.2
	old_RELENG_3_2_PAO_BP:1.1.2.1
	old_RELENG_3_2_0_RELEASE:1.1.2.1
	old_RELENG_3:1.1.0.2;
locks; strict;
comment	@# @;


1.42
date	2005.04.29.23.02.56;	author brooks;	state dead;
branches;
next	1.41;

1.41
date	2004.12.12.08.04.26;	author obrien;	state Exp;
branches;
next	1.40;

1.40
date	2004.11.05.07.35.31;	author mtm;	state Exp;
branches;
next	1.39;

1.39
date	2004.10.07.13.55.26;	author mtm;	state Exp;
branches;
next	1.38;

1.38
date	2004.06.06.11.46.29;	author schweikh;	state Exp;
branches
	1.38.2.1;
next	1.37;

1.37
date	2004.04.28.13.18.22;	author phk;	state Exp;
branches;
next	1.36;

1.36
date	2004.04.28.09.09.26;	author ru;	state Exp;
branches;
next	1.35;

1.35
date	2004.04.27.15.42.34;	author phk;	state Exp;
branches;
next	1.34;

1.34
date	2004.04.15.17.52.53;	author brooks;	state Exp;
branches;
next	1.33;

1.33
date	2004.03.31.08.43.20;	author luigi;	state Exp;
branches;
next	1.32;

1.32
date	2004.03.31.07.24.15;	author luigi;	state Exp;
branches;
next	1.31;

1.31
date	2004.03.12.04.40.16;	author brooks;	state Exp;
branches;
next	1.30;

1.30
date	2004.03.09.23.06.50;	author phk;	state Exp;
branches;
next	1.29;

1.29
date	2004.03.08.12.25.05;	author pjd;	state Exp;
branches;
next	1.28;

1.28
date	2003.10.13.08.20.55;	author dougb;	state Exp;
branches;
next	1.27;

1.27
date	2003.10.13.08.18.05;	author dougb;	state Exp;
branches;
next	1.26;

1.26
date	2003.10.12.00.19.45;	author kris;	state Exp;
branches;
next	1.25;

1.25
date	2003.08.07.21.06.32;	author fjoe;	state Exp;
branches;
next	1.24;

1.24
date	2003.06.30.21.47.06;	author brooks;	state Exp;
branches;
next	1.23;

1.23
date	2003.02.15.16.29.20;	author jhay;	state Exp;
branches;
next	1.22;

1.22
date	2002.12.22.22.18.41;	author dillon;	state Exp;
branches;
next	1.21;

1.21
date	2002.10.12.10.31.31;	author schweikh;	state Exp;
branches;
next	1.20;

1.20
date	2002.10.02.00.59.14;	author dd;	state Exp;
branches;
next	1.19;

1.19
date	2002.09.22.09.48.02;	author phk;	state Exp;
branches;
next	1.18;

1.18
date	2002.07.28.03.41.53;	author dd;	state Exp;
branches;
next	1.17;

1.17
date	2002.06.13.22.14.36;	author gordon;	state Exp;
branches;
next	1.16;

1.16
date	2002.04.22.21.42.18;	author obrien;	state Exp;
branches;
next	1.15;

1.15
date	2002.02.23.01.49.20;	author obrien;	state Exp;
branches;
next	1.14;

1.14
date	2002.02.22.19.05.22;	author obrien;	state Exp;
branches;
next	1.13;

1.13
date	2002.01.17.00.10.28;	author rwatson;	state Exp;
branches;
next	1.12;

1.12
date	2002.01.17.00.08.44;	author rwatson;	state Exp;
branches;
next	1.11;

1.11
date	2001.12.26.17.00.55;	author rwatson;	state Exp;
branches;
next	1.10;

1.10
date	2001.05.09.15.13.51;	author bsd;	state Exp;
branches;
next	1.9;

1.9
date	2001.04.25.05.46.40;	author imp;	state Exp;
branches;
next	1.8;

1.8
date	2001.04.20.23.10.11;	author bsd;	state Exp;
branches;
next	1.7;

1.7
date	2001.04.03.00.24.01;	author bsd;	state Exp;
branches;
next	1.6;

1.6
date	2000.10.08.19.18.24;	author obrien;	state Exp;
branches;
next	1.5;

1.5
date	2000.01.06.18.17.38;	author luigi;	state Exp;
branches
	1.5.2.1;
next	1.4;

1.4
date	99.09.13.17.09.07;	author peter;	state Exp;
branches;
next	1.3;

1.3
date	99.09.13.15.44.18;	author sheldonh;	state Exp;
branches;
next	1.2;

1.2
date	99.08.25.16.01.34;	author sheldonh;	state Exp;
branches;
next	1.1;

1.1
date	99.02.09.17.17.18;	author dillon;	state Exp;
branches
	1.1.2.1;
next	;

1.1.2.1
date	99.03.09.17.04.40;	author luigi;	state Exp;
branches;
next	;

1.5.2.1
date	2000.10.30.10.40.11;	author obrien;	state Exp;
branches;
next	1.5.2.2;

1.5.2.2
date	2001.03.06.01.58.45;	author obrien;	state Exp;
branches;
next	1.5.2.3;

1.5.2.3
date	2001.03.06.02.15.04;	author obrien;	state Exp;
branches;
next	1.5.2.4;

1.5.2.4
date	2001.04.17.22.53.34;	author bsd;	state Exp;
branches;
next	1.5.2.5;

1.5.2.5
date	2001.04.20.23.21.11;	author bsd;	state Exp;
branches;
next	1.5.2.6;

1.5.2.6
date	2001.05.11.17.46.57;	author bsd;	state Exp;
branches;
next	1.5.2.7;

1.5.2.7
date	2002.02.12.17.25.11;	author luigi;	state Exp;
branches;
next	1.5.2.8;

1.5.2.8
date	2002.02.12.18.36.23;	author luigi;	state Exp;
branches;
next	1.5.2.9;

1.5.2.9
date	2002.03.15.08.00.37;	author luigi;	state Exp;
branches;
next	;

1.38.2.1
date	2004.10.10.09.50.53;	author mtm;	state Exp;
branches;
next	1.38.2.2;

1.38.2.2
date	2005.02.14.01.15.45;	author obrien;	state Exp;
branches;
next	1.38.2.3;

1.38.2.3
date	2005.09.22.17.55.29;	author rwatson;	state Exp;
branches;
next	1.38.2.4;

1.38.2.4
date	2006.01.11.06.22.21;	author brooks;	state Exp;
branches;
next	1.38.2.5;

1.38.2.5
date	2006.01.24.05.54.18;	author brooks;	state Exp;
branches;
next	;


desc
@@


1.42
log
@To allow /etc to be as minimal as possible in a diskless setup, we need
to run initdiskless before we run rcorder on /etc/rc.d.  To allow this,
move /etc/rc.d/initdiskless to /etc/rc.initdiskless and run it directly
from /etc/rc.

Remove /etc/rc.d/preseedrandom as it is no longer necessicary (we start
with entropy unblocked) and was only used by initdiskless when it
was needed.

Discussed on:	freebsd-rc
Repocopy by:	peter
@
text
@#!/bin/sh
#
# Copyright (c) 1999  Matt Dillon
# 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: src/etc/rc.d/initdiskless,v 1.41 2004/12/12 08:04:26 obrien Exp $
#
# PROVIDE: initdiskless
# REQUIRE: preseedrandom
# BEFORE: rcconf
# KEYWORD: nojail


# On entry to this script the entire system consists of a read-only root
# mounted via NFS. The kernel has run BOOTP and configured an interface
# (otherwise it would not have been able to mount the NFS root!)
#
# We use the contents of /conf to create and populate memory filesystems
# that are mounted on top of this root to implement the writable
# (and host-specific) parts of the root filesystem, and other volatile
# filesystems.
#
# The hierarchy in /conf has the form /conf/T/M/ where M are directories
# for which memory filesystems will be created and filled,
# and T is one of the "template" directories below:
#
#  base		universal base, typically a replica of the original root;
#  default	secondary universal base, typically overriding some
#		of the files in the original root;
#  ${ipba}	where ${ipba} is the assigned broadcast IP address
#  ${class}	where ${class} is a list of directories supplied by
#		bootp/dhcp through the T134 option.
#		${ipba} and ${class} are typicall used to configure features
#		for group of diskless clients, or even individual features;
#  ${ip}	where ${ip} is the machine's assigned IP address, typically
#		used to set host-specific features;
#
# Template directories are scanned in the order they are listed above,
# with each sucessive directory overriding (merged into) the previous one;
# non-existing directories are ignored.
#
# The existence of a directory /conf/T/M causes this script to create a
# memory filesystem mounted as /M on the client.
#
# Some files in /conf have special meaning, namely:
#
# Filename	Action
# ----------------------------------------------------------------
# /conf/T/M/remount
#		The contents of the file is a mount command. E.g. if
# 		/conf/1.2.3.4/foo/remount contains "mount -o ro /dev/ad0s3",
#		then /dev/ad0s3 will be be mounted on /conf/1.2.3.4/foo/
#
# /conf/T/M/diskless_remount
#		The contents of the file points to an NFS filesystem. E.g. if
#		/conf/base/etc/diskless_remount contains "foo.com:/etc",
#		then foo.com:/etc will be be mounted on /conf/base/etc/
#		If the file contains a pathname starting with "/", then
#		the root path is prepended to it; this allows relocation of
#		the root filesystem withouth changing configuration files.
#
# /conf/T/M/md_size
#		The contents of the file specifies the size of the memory
#		filesystem to be created, in 512 byte blocks.
#		The default size is 10240 blocks (5MB). E.g. if
#		/conf/base/etc/md_size contains "30000" then a 15MB MFS
#		will be created. In case of multiple entries for the same
#		directory M, the last one in the scanning order is used.
#		NOTE: If you only need to create a memory filesystem but not
#		initialize it from a template, it is preferrable to specify
#		it in fstab e.g. as  "md /tmp mfs -s=30m,rw 0 0"
#
# /conf/T/SUBDIR.cpio.gz
#		The file is cpio'd into /SUBDIR (and a memory filesystem is
#		created for /SUBDIR if necessary). The presence of this file
#		prevents the copy from /conf/T/SUBDIR/
#
# /conf/T/SUBDIR.remove
#		The list of paths contained in the file are rm -rf'd
#		relative to /SUBDIR.
#
# You will almost universally want to create the following files under /conf
#
# File				Content
# ----------------------------	------------------------------------------
# /conf/base/etc/md_size	size of /etc filesystem
# /conf/base/diskless_remount	"/etc"
# /conf/default/etc/rc.conf	generic diskless config parameters
# /conf/default/etc/fstab	generic diskless fstab e.g. like this
#
#	foo:/root_part		/	nfs	ro		0 0
#	foo:/usr_part		/usr	nfs     ro		0 0
#	foo:/home_part		/home   nfs     rw      	0 0
#	md			/tmp	mfs     -s=30m,rw	0 0
#	md			/var	mfs	-s=30m,rw	0 0
#	proc			/proc	procfs	rw		0 0
#
# plus, possibly, overrides for password files etc.
#
# NOTE!  /var, /tmp, and /dev will be typically created elsewhere, e.g.
# as entries in the fstab as above.
# Those filesystems should not be specified in /conf.
#
# (end of documentation, now get to the real code)

dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
[ ${dlv:=0} -eq 0 ] && [ ! -f /etc/diskless ] && exit 0

# 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
}

# Create a generic memory disk
#
mount_md() {
    /sbin/mdmfs -i 4096 -s $1 -M md $2
}

# Create the memory filesystem if it has not already been created
#
create_md() {
    if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
	if [ "x`eval echo \\$md_size_$1`" = "x" ]; then
	    md_size=10240
	else
	    md_size=`eval echo \\$md_size_$1`
	fi
	mount_md $md_size /$1
	/bin/chmod 755 /$1
	eval md_created_$1=created
    fi
}

# DEBUGGING
#
# set -v

# Figure out our interface and IP.
#
bootp_ifc=""
bootp_ipa=""
bootp_ipbca=""
if [ ${dlv:=0} -ne 0 ] ; then
	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
	# Insert the directories passed with the T134 bootp cookie
	# in the list of paths used for templates.
	i="`/sbin/sysctl -n kern.bootp_cookie`"
	[ "${i}" != "" ] && bootp_ipbca="${bootp_ipbca} ${i}"

	echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}"
fi

# Figure out our NFS root path
#
set -- `mount -t nfs`
while [ $# -ge 1 ] ; do
    if [ "$2" = "on" -a "$3" = "/" ]; then
	nfsroot="$1"
	break
    fi
    shift
done

# The list of directories with template files
templates="base default ${bootp_ipbca} ${bootp_ipa}"

# The list of filesystems to umount after the copy
to_umount=""

# If /conf/diskless_remount exists, remount all of /conf.  This allows
# multiple roots to share the same conf files.
if [ -d /conf -a -f /conf/diskless_remount ]; then
    nfspt=`/bin/cat /conf/diskless_remount`
    if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then
	nfspt="${nfsroot}${nfspt}"
    fi
    mount_nfs $nfspt /conf
    chkerr $? "mount_nfs $nfspt /conf"
    to_umount="/conf"
fi

# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca},
# and /conf/${bootp_ipa}.  For each subdirectory found within these
# directories:
#
# - calculate memory filesystem sizes.  If the subdirectory (prior to
#   NFS remounting) contains the file 'md_size', the contents specified
#   in 512 byte sectors will be used to size the memory filesystem.  Otherwise
#   8192 sectors (4MB) is used.
#
# - handle NFS remounts.  If the subdirectory contains the file
#   diskless_remount, the contents of the file is NFS mounted over
#   the directory.  For example /conf/base/etc/diskless_remount
#   might contain 'myserver:/etc'.  NFS remounts allow you to avoid
#   having to dup your system directories in /conf.  Your server must
#   be sure to export those filesystems -alldirs, however.
#   If the diskless_remount file contains a string beginning with a
#   '/' it is assumed that the local nfsroot should be prepended to
#   it before attemping to the remount.  This allows the root to be
#   relocated without needing to change the remount files.
#
for i in ${templates} ; do
    for j in /conf/$i/* ; do
	# memory filesystem size specification
	#
	subdir=${j##*/}
	if [ -d $j -a -f $j/md_size ]; then
	    eval md_size_$subdir=`cat $j/md_size`
	fi

	# remount
	#
	if [ -d $j -a -f $j/remount ]; then
	    nfspt=`/bin/cat $j/remount`
	    $nfspt $j
	    chkerr $? "$nfspt $j"
	    to_umount="${to_umount} $j" # XXX hope it is really a mount!
	fi

	# NFS remount
	#
	if [ -d $j -a -f $j/diskless_remount ]; then
	    nfspt=`/bin/cat $j/diskless_remount`
	    if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then
		nfspt="${nfsroot}${nfspt}"
	    fi
	    mount_nfs $nfspt $j
	    chkerr $? "mount_nfs $nfspt $j"
	    to_umount="${to_umount} $j"
	fi
    done
done

# - Create all required MFS filesystems and populate them from
#   our templates.  Support both a direct template and a dir.cpio.gz
#   archive.  Support dir.remove files containing a list of relative
#   paths to remove.
#
# The dir.cpio.gz form is there to make the copy process more efficient,
# so if the cpio archive is present, it prevents the files from dir/
# from being copied.

for i in ${templates} ; do
    for j in /conf/$i/* ; do
	subdir=${j##*/}
	if [ -d $j -a ! -f $j.cpio.gz  ]; then
	    create_md $subdir
	    cp -Rp $j/* /$subdir
	fi
    done
    for j in /conf/$i/*.cpio.gz ; do
	subdir=${j%*.cpio.gz}
	subdir=${subdir##*/}
	if [ -f $j ]; then
	    create_md $subdir
	    echo "Loading /$subdir from cpio archive $j"
	    (cd / ; /rescue/pax -x cpio -r -z -p e -f $j)
	fi
    done
    for j in /conf/$i/*.remove ; do
	subdir=${j%*.remove}
	subdir=${subdir##*/}
	if [ -f $j ]; then
	    # doubly sure it is a memory disk before rm -rf'ing
	    create_md $subdir
	    (cd /$subdir; rm -rf `/bin/cat $j`)
	fi
    done
done

# umount partitions used to fill the memory filesystems
[ -n "${to_umount}" ] && umount $to_umount
@


1.41
log
@Use utils from /rescue vs. /stand.  Also use pax rather than cpio & gzip.
@
text
@d27 1
a27 1
# $FreeBSD$
@


1.40
log
@- Make the header conform to standard rc.d style.
- The 'before ipfw' directive seems bogus, and should instead
  be 'before rcconf'.
@
text
@d308 1
a308 1
	    (cd / ; /stand/gzip -d < $j | /stand/cpio --extract -d )
@


1.39
log
@Remove the requirement for the FreeBSD keyword as it no longer
makes any sense.

Discussed with: dougb, brooks
MFC after: 3 days
@
text
@d29 1
d31 1
a31 1
# PROVIDE: initdiskless
a32 1
# BEFORE: ipfw
@


1.38
log
@Removed whitespace at BOF, EOL & EOF.
@
text
@d31 1
a31 1
# KEYWORD: FreeBSD nojail
@


1.38.2.1
log
@RCS file: /home/ncvs/src/etc/rc,v
----------------------------
revision 1.335
date: 2004/10/08 14:23:49;  author: mtm;  state: Exp;  lines: +0 -1
Remove an unused variable.

Submitted by: Pawel Worach <pawel.worach@@telia.com>
----------------------------
revision 1.334
date: 2004/10/07 13:55:25;  author: mtm;  state: Exp;  lines: +1 -1
Remove the requirement for the FreeBSD keyword as it no longer
makes any sense.

Discussed with: dougb, brooks
MFC after: 3 days
=============================================================================
RCS file: /home/ncvs/src/etc/rc.d/nsswitch,v
----------------------------
revision 1.4
date: 2004/09/16 17:03:12;  author: keramida;  state: Exp;  lines: +1 -1
Fix requirement of `network' to `NETWORK' because the former isn't
provided by any rc.d script.

Approved by:	mtm
=============================================================================
RCS file: /home/ncvs/src/etc/rc.d/pflog,v
----------------------------
revision 1.3
date: 2004/09/16 17:04:20;  author: keramida;  state: Exp;  lines: +1 -1
We don't have any providers of `beforenetlkm' in FreeBSD.  Remove the
dependency to it from our rc.d scripts.

Approved by:	mtm
=============================================================================

Approved by: re/scottl
@
text
@d31 1
a31 1
# KEYWORD: nojail
@


1.38.2.2
log
@MFC: rev 1.41: use utils from /rescue vs. /stand, and pax vs. cpio & gzip.
@
text
@d308 1
a308 1
	    (cd / ; /rescue/pax -x cpio -r -z -p e -f $j)
@


1.38.2.3
log
@Merge rc.initdiskless:1.45 from HEAD to RELENG_5:

  Use sysctl -q when querying for kern.bootp_cookie in order to avoid
  printing boot-time errors that don't reflect true error conditions.
@
text
@d198 1
a198 1
	i="`/sbin/sysctl -qn kern.bootp_cookie`"
@


1.38.2.4
log
@MFC revs 1.46 and 1.47 (from src/etc/rc.initdiskless).

Switch from pax to tar for extracting cpio archives.  pax requires a
writable /tmp (or TMPDIR) and thus is unsuitable for this job.

The pax command used was also invalid.

PR:		conf/88293
@
text
@d308 1
a308 1
	    (cd / ; /rescue/tar -xpf $j)
@


1.38.2.5
log
@MFC etc/rc.initdiskless rev 1.49: Don't create memory backed file
systems with soft-updates enabled.

PR:		conf/85558
Submitted by:	Ralf Wenk <RZ dash FreeBSD0605 at hs dash karlsruhe dot de>
@
text
@d152 1
a152 1
    /sbin/mdmfs -S -i 4096 -s $1 -M md $2
@


1.37
log
@Initdiskless must run before ipfw, or people will not be able to
use the conf/* stuff for their firewall configuration.

Running ipfw before could seem to make sense in that it would allow
one to setup access to the NFS server on a "default-deny" kernel,
but it is pretty obvious to the casual observer that such a configuration
never makes it far enough to mount the NFS-root in the first place.
@
text
@d58 1
a58 1
#		
@


1.36
log
@Replace shell's positional parameters safely.
@
text
@d32 1
@


1.35
log
@When using this in non-NFSroot circumstances, `mount -t nfs` may
return empty.  Add a dummy element to prevent the alternate action
of the shell builtin "set"
@
text
@d181 1
a181 1
	    set `ifconfig ${i}`
d205 1
a205 2
# The 'x' is there in case the list is empty.
set x `mount -t nfs`
@


1.34
log
@Band-aid diskless booting by running a new preseedrandom script before
initdiskless.  The output of several commands and if available the
contents of /entropy are feed into /dev/random to kickstart the PRNG.
/etc/rc.d/initrandom is left alone to maintain the previous behavior as
much as possiable.

Further work in this area is probably needed.

Discussed with:	markm
@
text
@d205 2
a206 1
set `mount -t nfs`
@


1.33
log
@Extensive documentation changes to the script, but only
comments and empty lines have been touched.

All of this should go in the diskless(8) manpage, now if we had
some kind of 'literate programming' tool to extract the comments
from the script and put them in a reasonable nroff format, it
would be a lot easier to keep code and docs in sync
@
text
@d29 1
@


1.32
log
@Minor changes mostly as discussed on the lists a few days ago:

 + SUBDIR.cpio.gz prevents files from SUBDIR/ to be copied when
   priming the memory filesystems. This restores the old behaviour
   and makes the copy process a lot more efficient

 + look for templates also in the list of directories supplied by
   bootp/dhcp via the T134 option aka kern.bootp_cookie

 + keep track of directories temporarily mounted with "remount"
   or "diskless_remount" commands and unmount them once we are done
   with them (at the end of this script).
@
text
@d34 1
a34 2
# mounted via NFS.  We use the contents of /conf to create and populate
# memory filesystems.  The kernel has run BOOTP and configured an interface
d37 79
a115 2
# The following directories are scanned.  Each sucessive directory overrides
# (is merged into) the previous one.
d117 1
a117 42
#	/conf/base		universal base
#	/conf/default		modified by a secondary universal base
#	/conf/${ipba}		modified based on the assigned broadcast IP
#	/conf/${ip}		modified based on the machine's assigned IP
#
# Each of these directories may contain any number of subdirectories which
# represent directories in / on the diskless machine.  The existance of
# these subdirectories causes this script to create a MEMORY FILESYSTEM for
# /<sub_directory_name>.  For example, if /conf/base/etc exists then a
# memory filesystem will be created for /etc.
#
# If a subdirectory contains the file 'remount' the contents of the file
# is a mount command used to remount the subdirectory prior to it being
# copied.  An example contents could be: "mount -o ro /dev/ad0s3".  Note
# that the directory to be mounted on is supplied by this script.
#
# If a subdirectory contains the file 'diskless_remount' the contents of
# the file is used to remount the subdirectory prior to it being copied to
# the memory filesystem.  For example, if /conf/base/etc/diskless_remount
# contains the string 'my.server.com:/etc' then my.server.com:/etc will be
# mounted in place of the subdirectory.  This allows you to avoid making
# duplicates of system directories in /conf.  Special processing is done
# to allow specifications relative to the root filesystem.
#
# If a subdirectory contains the file 'md_size', the contents of the
# file is used to determine the size of the memory filesystem, in 512
# byte sectors.  The default is 10240 (5MB).  You only have to specify an
# md_size if the default doesn't work for you (i.e. if it is too big or
# too small).  For example, /conf/base/etc/md_size might contain '16384'.
#
# If /conf/<special_dir>/SUBDIR.cpio.gz exists, the file is cpio'd into
# the specified /SUBDIR (and a memory filesystem is created for /SUBDIR
# if necessary).
#
# If /conf/<special_dir>/SUBDIR.remove exists, the file contains a list
# of paths which are rm -rf'd relative to /SUBDIR.
#
# You will almost universally want to create a /conf/base/etc containing
# a diskless_remount and possibly an md_size file.  You will then almost
# universally want to override rc.conf, rc.local, and fstab by creating
# /conf/default/etc/{rc.conf,rc.local,fstab}.  Your fstab should be sure
# to mount a /usr... typically an NFS readonly /usr.
d119 2
a120 1
# NOTE!  /var, /tmp, and /dev will be created elsewhere.
d122 2
@


1.31
log
@If /conf/diskless_remount exists, use it to remount the entire /conf
directory.  This allows multiple roots (say for different architectures)
to share the same set of /conf files.
@
text
@d156 5
d175 6
d190 1
d213 1
a213 1
for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
d228 1
d240 1
d250 3
a252 3
# TODO:
#   + find a way to assign a 'group' identifier to a machine
#	so we can use group-specific configurations;
d254 1
a254 1
for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
d257 1
a257 1
	if [ -d $j ]; then
d282 2
@


1.30
log
@Make this file more generally usable:

Trigger not only on diskless booting sysctls being set, but also
on the existence of the file "/etc/diskless".  But do not try to
extract IP# related keywords in that case.

Add a general "remount" facility to allow non-NFS remounting.
@
text
@d84 2
a85 2
# NOTE!  /etc/rc.d/diskless will create /var, /tmp, and /dev.
# Those filesystems should not be specified in /conf.  At least not yet.
d169 11
@


1.29
log
@Mark scripts as not usable inside a jail by adding keyword 'nojail'.

Some suggestions from:	rwatson, Ruben de Groot <mail25@@bzerk.org>
@
text
@d52 5
d62 2
a63 1
# duplicates of system directories in /conf.
d88 1
a88 1
[ ${dlv:=0} -eq 0 ] && exit 0
d139 19
a157 17
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}"
d197 8
@


1.28
log
@Remove trailing whitespace
@
text
@d30 1
a30 1
# KEYWORD: FreeBSD
@


1.27
log
@Update references to rc.diskless[12]
@
text
@d32 1
a32 1
 
d152 1
a152 1
# 
d163 1
a163 1
# and /conf/${bootp_ipa}.  For each subdirectory found within these 
@


1.26
log
@Bump default /etc size from 2MB to 5MB to deal with bloat^Wgrowth in
the size of /etc.
@
text
@d78 2
a79 2
# NOTE!  rc.diskless2 will create /var, /tmp, and /dev.  Those filesystems
# should not be specified in /conf.  At least not yet.
@


1.25
log
@Correct typo in Matt's name.
@
text
@d61 1
a61 1
# byte sectors.  The default is 8192 (4MB).  You only have to specify an
d63 1
a63 2
# too small).  Note that in -current the default is 4096 (2MB).  For
# example, /conf/base/etc/md_size might contain '16384'.
d114 1
a114 1
	    md_size=4096
@


1.24
log
@Allow diskless_remount files to contain path beginning with / which will
be mounted relative to the NFS root mountpoint.

Reviewed by:	dillon at backplane.com
MFC After:	3 days
@
text
@d3 1
a3 1
# Copyright (c) 1999  Matt Dillion
@


1.23
log
@Add another backslash ('\').
@
text
@d152 11
d178 4
d196 3
@


1.22
log
@Do not unconditionally load the configuration files for the RCNG case.
Instead, load them as part of the rc.d system.  This allows us to prioritize
the initidiskless script so it runs before the configuration files are loaded
and allows us to get rid of the exit 2 hack in /etc/rc.  The exit 2 never
worked anyway since it did not unset the prior configuration, causing the
diskless code to not operate properly.

Do a major cleanup and revamping of the diskless code for RCNG.  This will
be backported to the non-RCNG scripts as well as -stable.

With suggestions from: Mike Makonnen <mtm@@identd.net>
MFC after:	7 days
@
text
@d114 1
a114 1
	if [ "x`eval echo \$md_size_$1`" = "x" ]; then
@


1.21
log
@Fix style bugs:
* Space -> tabs conversion.
* Removed blanks before semicolon in "if ... ; then".
* Proper indentation of misindented lines.
* Put a full stop after some comments.
* Removed whitespace at end of line.

Approved by:	silence from gordon
@
text
@a28 1

d32 50
a84 12
#
# BOOTP has mounted / for us.  Assume a read-only mount.  We must then
# - figure out our IP by querying the interface
# - mount /etc as an MFS
# - populate /etc from /conf/default version
# - override files in /etc with files from /conf/*/etc where
#   '*' is default, netmask of client, ip-address of client
#
# 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.

d92 10
a101 11
chkerr()
{
	case $1 in
	0)
		;;
	*)
		echo "$2 failed: dropping into /bin/sh"
		/bin/sh
		# RESUME
		;;
	esac
d104 19
a122 3
mount_md()
{
	/sbin/mdmfs -i 4096 -s $1 -M md$3 $2
d136 13
a148 13
	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
d152 31
a182 26
if [ -z "`hostname -s`" ]; then
	hostname=`kenv dhcp.host-name`
	hostname $hostname
	echo "Hostname is $hostname"
fi

if [ -d /conf/default/etc ]; then
	mount_md 4096 /etc 0
	chkerr $? "MFS mount on /etc"
	/bin/chmod 755 /etc

	/bin/cp -Rp /conf/default/etc/* /etc
	chkerr $? "cp /conf/default/etc to /etc MFS"
fi

# Allow for override files to replace files in /etc.  Use /conf/*/etc to find
# the override files.  First choice is default files that # always override,
# then files that from the directory that matches the client's broadcast
# address, finally followed by overrides that match the client's IP address.
#
# This way we have some flexibility to handle clusters of machines on
# separate subnets.

for i in ${bootp_ipbca} ${bootp_ipa} ${hostname} ; do
	if [ -d /conf/${i}/etc ]; then
		cp -Rp /conf/${i}/etc/* /etc
d184 1
d187 36
a222 12
#
# if the info is available via dhcp/kenv
# build the resolv.conf
#
if [ ! -e /etc/resolv.conf ]; then
	echo domain `kenv dhcp.domain-name` > /etc/resolv.conf

	set `kenv dhcp.domain-name-servers`
	for ns in `IFS=','; echo $*`; do
		echo nameserver $ns >> /etc/resolv.conf;
	done
fi
a223 1
exit 2		# Tell /etc/rc to re-source rc.conf
@


1.20
log
@In a diskless setup, rc.d/initdiskless may overwrite parts of /etc on
a per-machine or per-cluster (with different ways of expressing what's
part of a cluster) basis.  In order for this to be effective, rc.conf
has to be reread after initdiskless is finished.  Implement this by
adding a hook to etc/rc which rereads rc.conf by request.  This can
also be implemented by renaming initdiskless to initdiskless.sh and
sourcing rc.conf there manually, but it was decided that, that would
be uglier than a hook in etc/rc.

Developed in concert with:	gordon
@
text
@d84 13
a96 13
    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
@


1.19
log
@Use mdmfs(8) rather than rolling our own RAM-disks.

Sponsored by:	DARPA & NAI Labs.
@
text
@d141 2
@


1.18
log
@Stock -current has more than 300 files in /etc, so 255 inodes for the
/etc filesystem isn't enough; consequently, add "-i 4096" to the newfs
command for /etc.  This results in 1022 inodes, which should be enough
for the forseeable future (although I don't know why we would ever
have more than 1000 files in a default /etc).

Silence by:	-current
@
text
@d70 1
a70 4
	/sbin/mdconfig -a -t malloc -s $1 -u $3
	/sbin/disklabel -r -w md$3 auto
	/sbin/newfs -i 4096 /dev/md$3c
	/sbin/mount /dev/md$3c $2
@


1.17
log
@Merge in all the changes that Mike Makonnen has been maintaining for a
while. This is only the script pieces, the glue for the build comes next.

Submitted by:   Mike Makonnen <makonnen@@pacbell.net>
Reviewed by:    silence on -current and -hackers
Prodded by:     rwatson
@
text
@d72 1
a72 1
	/sbin/newfs /dev/md$3c
@


1.16
log
@Utilize dhcp information in the kernel environment if we don't have
hostname and DNS information already.

Submitted by:	Danny Braniss <danny@@cs.huji.ac.il>
@
text
@d1 2
d27 1
a27 1
# $FreeBSD: src/etc/rc.diskless1,v 1.15 2002/02/23 01:49:20 obrien Exp $
d30 6
a35 2
#
# /etc/rc.diskless1 - general BOOTP startup
d55 2
a56 1
chkerr() {
d68 2
a69 1
mount_md() {
d104 2
a105 2
        hostname=`kenv dhcp.host-name`
        hostname $hostname
d137 1
a137 1
        echo domain `kenv dhcp.domain-name` > /etc/resolv.conf
d139 4
a142 4
        set `kenv dhcp.domain-name-servers`
        for ns in `IFS=','; echo $*`; do
                echo nameserver $ns >> /etc/resolv.conf;
        done
a143 9

# 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.
# This can be overriden by /conf/ME/rc.conf.local if, for example, you do not
# want to run the standard system /etc/rc.diskless2

diskless_mount="/etc/rc.diskless2"
@


1.15
log
@The usage of 'newaliases' needs to be after we know for sure that /usr
is mounted.

Submitted by:	rizzo
@
text
@d25 1
a25 1
# $FreeBSD$
d95 6
d118 1
a118 1
for i in ${bootp_ipbca} ${bootp_ipa} ; do
d123 13
@


1.14
log
@The existing bazaar and site-specific policy in rc.diskless1 is Just Wrong;
and looks like no other Unix diskless configuration I've ever seen.
Thus allow a more traditional /etc.

Note, the use of an MFS /var should also be settable.
Otherwise installing ports(packages) is just a total PITA.
@
text
@a117 5
# Since we are starting with a very fresh /etc on an MFS:
if [ -d /conf/default/etc ]; then
	newaliases
if

@


1.13
log
@o Improve the line-wrapping of additional comments, some of which appeared
  to be wrapped around 60, others around 40 columns.
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.12 2002/01/17 00:08:44 rwatson Exp $
d95 8
a102 7

mount_md 4096 /etc 0
chkerr $? "MFS mount on /etc"
/bin/chmod 755 /etc

/bin/cp -Rp /conf/default/etc/* /etc
chkerr $? "cp /conf/default/etc to /etc MFS"
d117 5
@


1.12
log
@o Remove a somewhat less comprehensible comment about modifying /etc/rc.
o Improve line-wrapping of another comment for consistency.
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.11 2001/12/26 17:00:55 rwatson Exp $
d103 4
a106 8
# Allow for override files to replace files in /etc.  Use /conf/*/etc
# to find the override files.  First choice is default files that
# always override, then files that from the directory that matches the
# client's broadcast address, finally followed by overrides that match
# the client's IP address.
#
# This way we have some flexibility to handle clusters of machines
# on separate subnets.
d108 2
d117 6
a122 9
# 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.  This can be
# overriden by /conf/ME/rc.conf.local if, for
# example, you do not want to run the standard
# system /etc/rc.diskless2
@


1.11
log
@Remove incorrect comments about the population of /etc: no attempt is
made to copy the NFS-mounted on to /tmp/etc, instead, it is populated
entirely from /conf/default, then overriden from /conf/IP.
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.10 2001/05/09 15:13:51 bsd Exp $
a37 3
# WARNING: i thing you should not change /etc/rc or strange things could
# happen.
#
d39 2
a40 2
# Typically rc.conf and fstab need to be changed, but possibly
# also other files such as inetd.conf etc.
@


1.10
log
@  * Simplify the population of the /etc memory filesystem.  To avoid
    the null mount, we currently create a temporary mfs on /tmp, copy
    /etc to /tmp, then mount /etc as mfs and copy everything back from
    /tmp, then delete the /tmp mfs.

    The patch eliminates the temporary /tmp mfs and the subsequent
    copying and simply populates the /etc mfs by copying from
    /conf/default/etc.  This requires that /conf/default/etc contain a
    complete copy of all the /etc stuff instead of just overrides.  I
    don't think that is too much of an extra step in setting up a
    diskless environment.

  * Provide the ability to make /tmp a memory filesystem independent
    of /var.  This removes the requirement that /tmp be a symlink to
    /var/tmp and this makes the diskless code work with the default
    filesystem layout.  If a seperate /tmp memory filesystem is
    created, the 'tmpsize' environment variable is used to determine
    its size (default to 10 Meg).

  * Reduce diffs between the -current and -stable versions of these
    files to a bare minimum.  Only the definition of the shell
    function 'mount_md' is different.

Not Objected to by: -arch@@, -small@@

MFC after: 2 days
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.9 2001/04/25 05:46:40 imp Exp $
a32 1
# - copy /etc temporarily out of the way to /tmp/etc
d34 1
a34 1
# - repopulate /etc with the saved off copy
a97 3

# Create an MFS /tmp to temporarily hold files from /etc until we
# can bootstrap /etc as an MFS.
@


1.9
log
@Move to using md.
o create a simple wrapper function mount_md that makes it easy to
  move from mount_mfs.

# NOTE: you will need to MAKEDEV md[0123] in order for this to work.

Reviewed by: bsd, keichii
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.8 2001/04/20 23:10:11 bsd Exp $
d103 1
a103 7
mount_md 4096 /tmp 0
chmod 1777 /tmp
chkerr $? "MFS mount on /tmp"
/bin/cp -Rp /etc /tmp
chkerr $? "cp /etc to /tmp/etc MFS"

mount_md 4096 /etc 1
d107 2
a108 6
/bin/cp -Rp /tmp/etc/* /etc
chkerr $? "cp /tmp/etc to /etc MFS"

rm -rf /tmp/etc
/sbin/umount /tmp
/sbin/mdconfig -d -u 0
d120 1
a120 1
for i in default ${bootp_ipbca} ${bootp_ipa} ; do
@


1.8
log
@Eliminate the null mount for /etc for diskless clients.
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.7 2001/04/03 00:24:01 bsd Exp $
d65 7
d103 2
a104 1
/sbin/mount_mfs -s 4096 -T qp120at dummy /tmp
d109 1
a109 1
/sbin/mount_mfs -s 4096 -T qp120at dummy /etc
d118 1
a118 1

@


1.7
log
@Change the order in which /etc files are copied into place; copy
default first, then network-specific files, then host-specific files.
I think this was the original intent, as Matt indicated the previous
code appeared to be a bug.
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.6 2000/10/08 19:18:24 obrien Exp $
d33 5
a37 4
# - fill /conf/etc (writable) with files from /etc, and then update
#   per-machine files from /conf/*/ where * is the IP of the host,
#   the IP of the subnet, "default", or nothing.
# - mount /conf/etc over /etc so we can see the new files.
d91 27
a117 5
 
# Files in /etc are copied to /conf/etc which is writable. Then
# per-machine configs from /conf/ip.address/etc are copied onto this
# directory. First choice is using the client's IP, then the client's
# broadcast address, then a default configuration.
a120 6
# WARNING! null mounts cannot handle mmap, and since many programs
# use mmap (such as 'cp'), we have to copy.
#
mount_mfs -s 2048 -T qp120at dummy /conf/etc
cp -Rp /etc/* /conf/etc
chkerr $? "MFS mount on /conf/etc"
d122 5
a126 18
# Pick up default, network-specific, and host-specific config, in that
# order

if [ -d /conf/default/etc/ ]; then
	cp -Rp /conf/default/etc/* /conf/etc
fi

if [ -d /conf/${bootp_ipbca} ] ; then
	cp -Rp /conf/${bootp_ipbca}/etc/* /conf/etc
fi

if [ -d /conf/${bootp_ipa} ] ; then
	cp -Rp /conf/${bootp_ipa}/etc/* /conf/etc
fi

# Make the new directory available as /etc
#
mount_null /conf/etc /etc
@


1.6
log
@Add copyright notices.  Other systems have been barrowing our /etc files
w/o giving any credit.
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.5 2000/01/06 18:17:38 luigi Exp $
d105 11
d117 1
a117 5
        cp -Rp /conf/${bootp_ipa}/etc/* /conf/etc
elif [ -d /conf/${bootp_ipbca} ] ; then
        cp -Rp /conf/${bootp_ipbca}/etc/* /conf/etc
else
        cp -Rp /conf/default/etc/* /conf/etc
@


1.5
log
@Cleanup diskless support in current, mostly aligning it to the one
in the 3.x branch. Also remove the dependency on /usr to find the
boot address/interface.
Mostly-submitted-abd-tested-by: MIHIRA Sanpei Yoshiro <sanpei@@sanpei.org>
@
text
@d1 27
a27 1
# $FreeBSD: src/etc/rc.diskless1,v 1.4 1999/09/13 17:09:07 peter Exp $
@


1.5.2.1
log
@MFC: Add copyright.
@
text
@d1 1
a1 27
# 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$
#

@


1.5.2.2
log
@MFC: add copyright notices
@
text
@d25 1
a25 27
# 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: src/etc/rc.diskless1,v 1.5.2.1 2000/10/30 10:40:11 obrien Exp $
@


1.5.2.3
log
@Grrr. patch really did a number on me with these.
@
text
@d25 27
a51 1
# $FreeBSD: src/etc/rc.diskless1,v 1.5.2.2 2001/03/06 01:58:45 obrien Exp $
@


1.5.2.4
log
@MFC rev 1.7 : Re-order how files are copied into the new /etc
              directory.  Copy default first, then network-specific,
              finally followed by host-specific files.

Approved by:	jkh
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.5.2.3 2001/03/06 02:15:04 obrien Exp $
a104 11
# Pick up default, network-specific, and host-specific config, in that
# order

if [ -d /conf/default/etc/ ]; then
	cp -Rp /conf/default/etc/* /conf/etc
fi

if [ -d /conf/${bootp_ipbca} ] ; then
	cp -Rp /conf/${bootp_ipbca}/etc/* /conf/etc
fi

d106 5
a110 1
	cp -Rp /conf/${bootp_ipa}/etc/* /conf/etc
@


1.5.2.5
log
@MFC Rev 1.8: Eliminate the null mount for /etc for diskless clients.
             This works around the stabilily problems of null mounts.

Approved by:	jkh
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.5.2.4 2001/04/17 22:53:34 bsd Exp $
d33 4
a36 5
# - copy /etc temporarily out of the way to /tmp/etc
# - mount /etc as an MFS
# - repopulate /etc with the saved off copy
# - override files in /etc with files from /conf/*/etc where
#   '*' is default, netmask of client, ip-address of client
d90 21
d112 3
d116 3
a118 2
# Create an MFS /tmp to temporarily hold files from /etc until we
# can bootstrap /etc as an MFS.
d120 1
a120 21
/sbin/mount_mfs -s 4096 -T qp120at dummy /tmp
chkerr $? "MFS mount on /tmp"
/bin/cp -Rp /etc /tmp
chkerr $? "cp /etc to /tmp/etc MFS"

/sbin/mount_mfs -s 4096 -T qp120at dummy /etc
chkerr $? "MFS mount on /etc"
/bin/chmod 755 /etc

/bin/cp -Rp /tmp/etc/* /etc
chkerr $? "cp /tmp/etc to /etc MFS"

rm -rf /tmp/etc
/sbin/umount /tmp


# Allow for override files to replace files in /etc.  Use /conf/*/etc
# to find the override files.  First choice is default files that
# always override, then files that from the directory that matches the
# client's broadcast address, finally followed by overrides that match
# the client's IP address.
d122 1
a122 9
# This way we have some flexibility to handle clusters of machines
# on separate subnets.
#

for i in default ${bootp_ipbca} ${bootp_ipa} ; do
	if [ -d /conf/${i}/etc ]; then
		cp -Rp /conf/${i}/etc/* /etc
	fi
done
@


1.5.2.6
log
@MFC: /etc bootstrap simplifications, ability to make /tmp a seperate
     memory filesystem, minimize differences between -current and
     releng_4.
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.5.2.5 2001/04/20 23:21:11 bsd Exp $
a64 4
mount_md() {
	/sbin/mount_mfs -s $1 -T qp120at dummy $2
}

d96 6
a101 1
mount_md 4096 /etc 0
d105 6
a110 2
/bin/cp -Rp /conf/default/etc/* /etc
chkerr $? "cp /conf/default/etc to /etc MFS"
d122 1
a122 1
for i in ${bootp_ipbca} ${bootp_ipa} ; do
@


1.5.2.7
log
@Fix the scripts for diskless boot. Apart from various changes in the
comments to reflect reality and explain the boot process a bit better,
the main changes are the following:

rc.diskless1:
	Use -b 4096 -f 1024 as mount parameters, and increase the
	/etc MFS partition size to 8192 blocks.
	Initially populate /etc from /conf/base/etc

rc.diskless2:
	Use -b 4096 -f 1024 as mount parameters, move "mount -a"
	up a bit so various utilities located in /usr can be
	actually run when /usr is not on the same filesystem as /
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.5.2.6 2001/05/11 17:46:57 bsd Exp $
d31 10
a40 20
# 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
d66 1
a66 1
	/sbin/mount_mfs -s $1 -T qp120at -b 4096 -f 1024 dummy $2
d100 1
a100 1
mount_md 8192 /etc 0
d104 12
a115 6
# Populate /etc, and then override the base setup with increasingly
# specific files.
# 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.
d117 1
a117 1
for i in base default ${bootp_ipbca} ${bootp_ipa} ; do
d128 4
a131 1
# diskless mount environment.
@


1.5.2.8
log
@Make the fs use 8k/1k blocks as 4:1 ratios are reported to
give trouble sometimes. Probably 4096/512 would be ok too, but
since i do not have a chance now to test it thoroughly i prefer
to stay on the safe side (8k/1k is what was used before 4.5).

Suggested-by: Warner Losh
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.5.2.7 2002/02/12 17:25:11 luigi Exp $
d76 1
a76 1
	/sbin/mount_mfs -s $1 -T qp120at -b 8192 -f 1024 dummy $2
@


1.5.2.9
log
@Two [minor] performance fixes for diskless configurations:
when copying large trees into /etc and /dev, try to fetch the
content from a cpio archive if there is one available, so the
operation does not take multiple RTTs for each individual file.
clone_root has been updated to generate the cpio archives,
rc.diskless* to make use of them.

Not committed to -current yet because the relevant files are
already slightly different in the two branches, and I would like
to have a chance to test it there first before resyncing the two
versions.
@
text
@d25 1
a25 1
# $FreeBSD: src/etc/rc.diskless1,v 1.5.2.8 2002/02/12 18:36:23 luigi Exp $
a115 5
# 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.
#
d122 1
a122 5
	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
@


1.4
log
@Add/adjust some $FreeBSD$ tags.

Noted by:	Doug <Doug@@gorean.org>
@
text
@d1 1
a1 1
# $FreeBSD: src/etc/rc.diskless1,v 1.3 1999/09/13 15:44:18 sheldonh Exp $
d3 1
a3 1
# /etc/rc.diskless - general BOOTP startup
d5 13
a17 17
#	BOOTP has mounted / for us.  Assume a read-only mount.  We must then
#	- figure out where the NFS mount is coming from
#	- figure out our IP by querying the interface
#	- retarget /conf/ME softlink to proper configuration script directory
#
#	It is expected that /etc/fstab and /etc/rc.conf.local will be
#	set by the system operator on the server to be softlinks to
#	/conf/ME/fstab and /conf/ME/rc.conf.local.  The system operator may
#	choose to retarget other files as well.  The server itself boots
#	properly with its default /conf/ME softlink pointing to
#	/conf/server.host.name.
#
#	During a diskless boot, we retarget the /conf/ME softlink to point
#	to /conf/DISKLESS.CLIENT.IP.ADDRESS.  Thus, various system config
#	files that are softlinks through /conf/ME also get retargeted.
#
# SEE SAMPLE FILES IN /usr/share/examples/diskless.
d40 1
a40 16
set -v

# Figure out where the root mount is coming from, synthesize a mount
# for /usr and mount it.
#
# e.g. nfs_root might wind up as "A.B.C.D:/"
#
# NOTE! the /usr mount is only temporary so we can access commands necessary
# to retarget /conf/ME.  The actual /usr mount should be part of the
# retargeted /etc/fstab.  See instructions in /usr/share/examples/diskless.
#
set `/bin/df /`
nfs_root=$8
mount_nfs -o ro ${nfs_root}/usr /usr

chkerr $? "mount of /usr"
d44 27
a70 16

bootp_ifc=`route -n get default | fgrep interface | awk '{ print $2; }'`
bootp_ipa=`ifconfig ${bootp_ifc} | fgrep inet | head -1 | awk '{ print $2; }'`

echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa}"

umount /usr

# retarget /conf/ME
#
# MFS's background process takes a bit to startup.  Various config files
# on server should be softlinks through /conf/ME.  The server's own /conf/ME
# points to the server's version of the files.
#
# We retarget /conf/ME using a -o union mount.  This allows
# us to 'mkdir' over whatever was there previously.
d75 11
a85 5
mount_mfs -s 256 -T qp120at -o union dummy /conf
chkerr $? "MFS mount on /conf"

mkdir /conf/ME
cp -Rp /conf/$bootp_ipa/* /conf/ME
d87 1
a87 1
# retarget the kernel
d89 1
a89 2

sysctl -w kern.bootfile=/conf/ME/kernel
@


1.3
log
@Apply a consistent style to most of the etc scripts.  Particularly, use
case instead of test where appropriate, since case allows case is a sh
builtin and (as a side-effect) allows case-insensitivity.

Changes discussed on freebsd-hackers.

Submitted by:	Doug Barton <Doug@@gorean.org>
@
text
@d1 1
a1 2
#
# $FreeBSD$
@


1.2
log
@Style clean-up:

	* All variables are now embraced: ${foo}

	* All comparisons against some value now take the form:
	  [ "${foo}" ? "value" ]
	  where ? is a comparison operator

	* All empty string tests now take the form:
	  [ -z "${foo}" ]

	* All non-empty string tests now take the form:
	  [ -n "${foo}" ]

Submitted by:	jkh
@
text
@d2 2
d15 2
a16 2
#	properly with its default /conf/ME softlink pointing to 
#	/conf/server.host.name.  
d22 1
a22 1
# SEE SAMPLE FILES IN /usr/share/examples/diskless. 
d30 1
a30 1

d32 4
a35 1
	if [ $1 != 0 ]; then
d39 2
a40 1
	fi
d47 2
a48 2
#  Figure out where the root mount is coming from, synthesize a mount
#  for /usr and mount it.
d50 1
a50 1
#  e.g. nfs_root might wind up as "A.B.C.D:/"
d52 3
a54 3
#  NOTE! the /usr mount is only temporary so we can access commands necessary
#  to retarget /conf/ME.  The actual /usr mount should be part of the
#  retargeted /etc/fstab.  See instructions in /usr/share/examples/diskless.
d62 1
a62 1
#  Figure out our interface and IP.
d83 1
a83 1

d100 1
a100 1
# diskless mount environment.  This can be 
@


1.1
log
@    Revamp rc.diskless.  Split into rc.diskless1 and rc.diskless2.  provide
    more opportunities for overriding.  Clean up /etc/rc ( remove conf_dir,
    remove startup mount special cases, remove other special cases )
@
text
@d60 1
a60 1
bootp_ipa=`ifconfig $bootp_ifc | fgrep inet | head -1 | awk '{ print $2; }'`
d62 1
a62 1
echo "Interface $bootp_ifc IP-Address $bootp_ipa"
a99 1

@


1.1.2.1
log
@MFC: bring support for diskless in RELENG_3
@
text
@d39 1
a39 2
# XXX
# set -v
d52 1
a52 6

# XXX we should extract the host part from nfs_root, but we don't have
# any good tool for string parsing yet. The ../ is a dirty hack. We
# can add more than one. But this whole section to determine the boot
# ifc etc. needs some cleanup
mount_nfs -o ro ${nfs_root}/../usr /usr
a60 1
bootp_ipbca=`ifconfig $bootp_ifc | fgrep inet | head -1 | awk '{ print $6; }'`
d62 1
a62 1
echo "Interface $bootp_ifc IP-Address $bootp_ipa Broadcast $bootp_ipbca"
d66 8
a73 6
# Files in /etc are copied to /conf/etc which is writable. Then
# per-machine configs from /conf/ip.address/etc are copied onto this
# directory. First choice is using the client's IP, then the client's
# broadcast address, then a default configuration.
# This way we have some flexibility to handle clusters of machines
# on separate subnets.
d78 2
a79 13
mount_mfs -s 2048 -T qp120at dummy /conf/etc
cp -Rp /etc/* /conf/etc
chkerr $? "MFS mount on /conf/etc"

if [ -d /conf/$bootp_ipa ]
then
	cp -Rp /conf/$bootp_ipa/etc/* /conf/etc
elif [ -d /conf/$bootp_ipbca ]
then
	cp -Rp /conf/$bootp_ipbca/etc/* /conf/etc
else
	cp -Rp /conf/default/etc/* /conf/etc
fi
d81 4
d86 2
a87 3
# Make the new directory available as /etc
#
mount_null /conf/etc /etc
@

