rc.initdiskless revision 51231
150477Speter#
232411Sjb# $FreeBSD: head/etc/rc.initdiskless 51231 1999-09-13 15:44:20Z sheldonh $
332411Sjb#
432411Sjb# /etc/rc.diskless - general BOOTP startup
532411Sjb#
632411Sjb#	BOOTP has mounted / for us.  Assume a read-only mount.  We must then
732411Sjb#	- figure out where the NFS mount is coming from
832411Sjb#	- figure out our IP by querying the interface
932411Sjb#	- retarget /conf/ME softlink to proper configuration script directory
1032411Sjb#
1132411Sjb#	It is expected that /etc/fstab and /etc/rc.conf.local will be
1232411Sjb#	set by the system operator on the server to be softlinks to
1332411Sjb#	/conf/ME/fstab and /conf/ME/rc.conf.local.  The system operator may
1432411Sjb#	choose to retarget other files as well.  The server itself boots
1532411Sjb#	properly with its default /conf/ME softlink pointing to
1632411Sjb#	/conf/server.host.name.
1732411Sjb#
1832411Sjb#	During a diskless boot, we retarget the /conf/ME softlink to point
1932411Sjb#	to /conf/DISKLESS.CLIENT.IP.ADDRESS.  Thus, various system config
2032411Sjb#	files that are softlinks through /conf/ME also get retargeted.
2132411Sjb#
2232411Sjb# SEE SAMPLE FILES IN /usr/share/examples/diskless.
2332411Sjb
2432411Sjb# chkerr:
2532411Sjb#
2632411Sjb# Routine to check for error
2732411Sjb#
2832411Sjb#	checks error code and drops into shell on failure.
2932411Sjb#	if shell exits, terminates script as well as /etc/rc.
3032411Sjb#
3132411Sjbchkerr() {
3232411Sjb	case $1 in
3332411Sjb	0)
3432411Sjb		;;
3551792Smarcel	*)
3632641Sjb		echo "$2 failed: dropping into /bin/sh"
3732641Sjb		/bin/sh
3832641Sjb		# RESUME
3932641Sjb		;;
4032641Sjb	esac
4132641Sjb}
4232641Sjb
4332641Sjb# DEBUGGING
4432641Sjb#
4532641Sjbset -v
4632641Sjb
47# Figure out where the root mount is coming from, synthesize a mount
48# for /usr and mount it.
49#
50# e.g. nfs_root might wind up as "A.B.C.D:/"
51#
52# NOTE! the /usr mount is only temporary so we can access commands necessary
53# to retarget /conf/ME.  The actual /usr mount should be part of the
54# retargeted /etc/fstab.  See instructions in /usr/share/examples/diskless.
55#
56set `/bin/df /`
57nfs_root=$8
58mount_nfs -o ro ${nfs_root}/usr /usr
59
60chkerr $? "mount of /usr"
61
62# Figure out our interface and IP.
63#
64
65bootp_ifc=`route -n get default | fgrep interface | awk '{ print $2; }'`
66bootp_ipa=`ifconfig ${bootp_ifc} | fgrep inet | head -1 | awk '{ print $2; }'`
67
68echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa}"
69
70umount /usr
71
72# retarget /conf/ME
73#
74# MFS's background process takes a bit to startup.  Various config files
75# on server should be softlinks through /conf/ME.  The server's own /conf/ME
76# points to the server's version of the files.
77#
78# We retarget /conf/ME using a -o union mount.  This allows
79# us to 'mkdir' over whatever was there previously.
80#
81# WARNING! null mounts cannot handle mmap, and since many programs
82# use mmap (such as 'cp'), we have to copy.
83#
84mount_mfs -s 256 -T qp120at -o union dummy /conf
85chkerr $? "MFS mount on /conf"
86
87mkdir /conf/ME
88cp -Rp /conf/$bootp_ipa/* /conf/ME
89
90# retarget the kernel
91#
92
93sysctl -w kern.bootfile=/conf/ME/kernel
94
95# Tell /etc/rc to run the specified script after
96# it does its mounts but before it does anything
97# else.
98#
99# This script is responsible for setting up the
100# diskless mount environment.  This can be
101# overriden by /conf/ME/rc.conf.local if, for
102# example, you do not want to run the standard
103# system /etc/rc.diskless2
104
105diskless_mount="/etc/rc.diskless2"
106