summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/initdiskless
blob: 4679a28b888f1e92e5d15cdd3096059662aa7a73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# $FreeBSD$
#
# /etc/rc.diskless - general BOOTP startup
#
#	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.

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

# DEBUGGING
#
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"

# Figure out our interface and IP.
#

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.
#
# WARNING! null mounts cannot handle mmap, and since many programs
# use mmap (such as 'cp'), we have to copy.
#
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

# retarget the kernel
#

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

# 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"
OpenPOWER on IntegriCloud