rc.initdiskless revision 51237
1# $FreeBSD: head/etc/rc.initdiskless 51237 1999-09-13 17:09:08Z peter $
2#
3# /etc/rc.diskless - general BOOTP startup
4#
5#	BOOTP has mounted / for us.  Assume a read-only mount.  We must then
6#	- figure out where the NFS mount is coming from
7#	- figure out our IP by querying the interface
8#	- retarget /conf/ME softlink to proper configuration script directory
9#
10#	It is expected that /etc/fstab and /etc/rc.conf.local will be
11#	set by the system operator on the server to be softlinks to
12#	/conf/ME/fstab and /conf/ME/rc.conf.local.  The system operator may
13#	choose to retarget other files as well.  The server itself boots
14#	properly with its default /conf/ME softlink pointing to
15#	/conf/server.host.name.
16#
17#	During a diskless boot, we retarget the /conf/ME softlink to point
18#	to /conf/DISKLESS.CLIENT.IP.ADDRESS.  Thus, various system config
19#	files that are softlinks through /conf/ME also get retargeted.
20#
21# SEE SAMPLE FILES IN /usr/share/examples/diskless.
22
23# chkerr:
24#
25# Routine to check for error
26#
27#	checks error code and drops into shell on failure.
28#	if shell exits, terminates script as well as /etc/rc.
29#
30chkerr() {
31	case $1 in
32	0)
33		;;
34	*)
35		echo "$2 failed: dropping into /bin/sh"
36		/bin/sh
37		# RESUME
38		;;
39	esac
40}
41
42# DEBUGGING
43#
44set -v
45
46# Figure out where the root mount is coming from, synthesize a mount
47# for /usr and mount it.
48#
49# e.g. nfs_root might wind up as "A.B.C.D:/"
50#
51# NOTE! the /usr mount is only temporary so we can access commands necessary
52# to retarget /conf/ME.  The actual /usr mount should be part of the
53# retargeted /etc/fstab.  See instructions in /usr/share/examples/diskless.
54#
55set `/bin/df /`
56nfs_root=$8
57mount_nfs -o ro ${nfs_root}/usr /usr
58
59chkerr $? "mount of /usr"
60
61# Figure out our interface and IP.
62#
63
64bootp_ifc=`route -n get default | fgrep interface | awk '{ print $2; }'`
65bootp_ipa=`ifconfig ${bootp_ifc} | fgrep inet | head -1 | awk '{ print $2; }'`
66
67echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa}"
68
69umount /usr
70
71# retarget /conf/ME
72#
73# MFS's background process takes a bit to startup.  Various config files
74# on server should be softlinks through /conf/ME.  The server's own /conf/ME
75# points to the server's version of the files.
76#
77# We retarget /conf/ME using a -o union mount.  This allows
78# us to 'mkdir' over whatever was there previously.
79#
80# WARNING! null mounts cannot handle mmap, and since many programs
81# use mmap (such as 'cp'), we have to copy.
82#
83mount_mfs -s 256 -T qp120at -o union dummy /conf
84chkerr $? "MFS mount on /conf"
85
86mkdir /conf/ME
87cp -Rp /conf/$bootp_ipa/* /conf/ME
88
89# retarget the kernel
90#
91
92sysctl -w kern.bootfile=/conf/ME/kernel
93
94# Tell /etc/rc to run the specified script after
95# it does its mounts but before it does anything
96# else.
97#
98# This script is responsible for setting up the
99# diskless mount environment.  This can be
100# overriden by /conf/ME/rc.conf.local if, for
101# example, you do not want to run the standard
102# system /etc/rc.diskless2
103
104diskless_mount="/etc/rc.diskless2"
105