rc.initdiskless revision 43803
143803Sdillon#
243803Sdillon# /etc/rc.diskless - general BOOTP startup
343803Sdillon#
443803Sdillon#	BOOTP has mounted / for us.  Assume a read-only mount.  We must then
543803Sdillon#	- figure out where the NFS mount is coming from
643803Sdillon#	- figure out our IP by querying the interface
743803Sdillon#	- retarget /conf/ME softlink to proper configuration script directory
843803Sdillon#
943803Sdillon#	It is expected that /etc/fstab and /etc/rc.conf.local will be
1043803Sdillon#	set by the system operator on the server to be softlinks to
1143803Sdillon#	/conf/ME/fstab and /conf/ME/rc.conf.local.  The system operator may
1243803Sdillon#	choose to retarget other files as well.  The server itself boots
1343803Sdillon#	properly with its default /conf/ME softlink pointing to 
1443803Sdillon#	/conf/server.host.name.  
1543803Sdillon#
1643803Sdillon#	During a diskless boot, we retarget the /conf/ME softlink to point
1743803Sdillon#	to /conf/DISKLESS.CLIENT.IP.ADDRESS.  Thus, various system config
1843803Sdillon#	files that are softlinks through /conf/ME also get retargeted.
1943803Sdillon#
2043803Sdillon# SEE SAMPLE FILES IN /usr/share/examples/diskless. 
2143803Sdillon
2243803Sdillon# chkerr:
2343803Sdillon#
2443803Sdillon# Routine to check for error
2543803Sdillon#
2643803Sdillon#	checks error code and drops into shell on failure.
2743803Sdillon#	if shell exits, terminates script as well as /etc/rc.
2843803Sdillon
2943803Sdillonchkerr() {
3043803Sdillon	if [ $1 != 0 ]; then
3143803Sdillon		echo "$2 failed: dropping into /bin/sh"
3243803Sdillon		/bin/sh
3343803Sdillon		# RESUME
3443803Sdillon	fi
3543803Sdillon}
3643803Sdillon
3743803Sdillon# DEBUGGING
3843803Sdillon#
3943803Sdillonset -v
4043803Sdillon
4143803Sdillon#  Figure out where the root mount is coming from, synthesize a mount
4243803Sdillon#  for /usr and mount it.
4343803Sdillon#
4443803Sdillon#  e.g. nfs_root might wind up as "A.B.C.D:/"
4543803Sdillon#
4643803Sdillon#  NOTE! the /usr mount is only temporary so we can access commands necessary
4743803Sdillon#  to retarget /conf/ME.  The actual /usr mount should be part of the
4843803Sdillon#  retargeted /etc/fstab.  See instructions in /usr/share/examples/diskless.
4943803Sdillon#
5043803Sdillonset `/bin/df /`
5143803Sdillonnfs_root=$8
5243803Sdillonmount_nfs -o ro ${nfs_root}/usr /usr
5343803Sdillon
5443803Sdillonchkerr $? "mount of /usr"
5543803Sdillon
5643803Sdillon#  Figure out our interface and IP.
5743803Sdillon#
5843803Sdillon
5943803Sdillonbootp_ifc=`route -n get default | fgrep interface | awk '{ print $2; }'`
6043803Sdillonbootp_ipa=`ifconfig $bootp_ifc | fgrep inet | head -1 | awk '{ print $2; }'`
6143803Sdillon
6243803Sdillonecho "Interface $bootp_ifc IP-Address $bootp_ipa"
6343803Sdillon
6443803Sdillonumount /usr
6543803Sdillon
6643803Sdillon# retarget /conf/ME
6743803Sdillon#
6843803Sdillon# MFS's background process takes a bit to startup.  Various config files
6943803Sdillon# on server should be softlinks through /conf/ME.  The server's own /conf/ME
7043803Sdillon# points to the server's version of the files.
7143803Sdillon#
7243803Sdillon# We retarget /conf/ME using a -o union mount.  This allows
7343803Sdillon# us to 'mkdir' over whatever was there previously.
7443803Sdillon#
7543803Sdillon# WARNING! null mounts cannot handle mmap, and since many programs
7643803Sdillon# use mmap (such as 'cp'), we have to copy.
7743803Sdillon
7843803Sdillonmount_mfs -s 256 -T qp120at -o union dummy /conf
7943803Sdillonchkerr $? "MFS mount on /conf"
8043803Sdillon
8143803Sdillonmkdir /conf/ME
8243803Sdilloncp -Rp /conf/$bootp_ipa/* /conf/ME
8343803Sdillon
8443803Sdillon# retarget the kernel
8543803Sdillon#
8643803Sdillon
8743803Sdillonsysctl -w kern.bootfile=/conf/ME/kernel
8843803Sdillon
8943803Sdillon# Tell /etc/rc to run the specified script after
9043803Sdillon# it does its mounts but before it does anything
9143803Sdillon# else.
9243803Sdillon#
9343803Sdillon# This script is responsible for setting up the
9443803Sdillon# diskless mount environment.  This can be 
9543803Sdillon# overriden by /conf/ME/rc.conf.local if, for
9643803Sdillon# example, you do not want to run the standard
9743803Sdillon# system /etc/rc.diskless2
9843803Sdillon
9943803Sdillondiskless_mount="/etc/rc.diskless2"
10043803Sdillon
101