summaryrefslogtreecommitdiffstats
path: root/share/examples/diskless/clone_root
blob: 22bd70c997965040fa30d5f06d5d78d08d3a7ab0 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh
#
# (C) 2001 Luigi Rizzo, Gabriele Cecchetti
#	<Standard BSD copyright>
# Revised 2001.04.16
#
# $FreeBSD$
#
# clone root filesystem for diskless root stuff
#
# usage
#	clone_root all		to do a full copy (e.g. bin, sbin...)
#	clone_root update	to recreate /var (including devices)
#	clone_root		to copy /conf and password-related files
#
# This script assumes that you use a shared readonly root and /usr
# partition. The script creates a partial clone of the root partition,
# and puts it into ${DEST} (defaults to /diskless_root ) on the server,
# where it is read.
#
# To run a diskless install you need to do the following:
#
# create /conf/default/etc/fstab
#    this will replace the standard /etc/fstab and should contain
#    as a minimum the following lines
#    ${SERVER}:${DEST} /     nfs    ro 0 0
#    ${SERVER}:/usr    /usr  nfs    ro 0 0
#    proc              /proc procfs rw 0 0
#
# create /conf/default/etc/rc.conf
#    this will replace the standard rc.conf and should contain
#    the startup options for the diskless client. Most likely
#    you will not need to set hostname and ifconfig_* because these
#    will be already set by the startup code. You will also
#    probably need to set local_startup="" so that the server's
#    local startup files will not be used.
#
# create a kernel config file in /sys/i386/conf/DISKLESS with
#	options MD_ROOT
#	options BOOTP
#	options BOOTP_NFSROOT
#	options BOOTP_COMPAT
# and do a full build of the kernel.
# If you use the firewall, remember to default to open or your kernel
# will not be able to send/receive the bootp packets.
#
# On the server:
# enable NFS server and set /etc/exports as
#	${DEST}	-maproot=0 -alldirs <list of diskless clients>
#	/usr -alldirs
#
# enable bootpd by uncommenting the bootps line in /etc/inetd.conf
# and putting at least the following entries in /etc/bootptab:
#  .default:\
#	hn:ht=1:vm=rfc1048:\
#	:sm=255.255.255.0:\
#	:sa=${SERVER}:\
#	:gw=${GATEWAY}:\
#	:rp="${SERVER}:${DEST}":
#
#  client1:ha=0123456789ab:tc=.default
#
# and make sure that client1 is listed in /etc/hosts

# VARIABLES:
#	some manual init is needed here.
# DEST	the diskless_root dir (goes into /etc/bootptab and /etc/exports
#	on the server)
DEST=/diskless_root

# you should not touch these vars:
# SYSDIRS	system directories and mountpoints
# DIRS		mountpoints (empty dirs)
# PWFILES	files related to passwords
# TOCOPY	files and dirs to copy from root partition

SYSDIRS="dev proc root usr var"
DIRS="cdrom home mnt"
PWFILES="master.passwd passwd spwd.db pwd.db"
TOCOPY="bin boot compat etc modules sbin stand sys"

init_diskless_root() {
	echo "Cleaning old diskless root ($DEST)"
	cd /
	rm -rf ${DEST} && echo "Old diskless root removed."
	echo "Creating $DEST..."
	mkdir -p $DEST && echo "New diskless root created."
	echo "+++ Now copy original tree from / ..."
	ex=""
	(cd / ; tar -clf - ${TOCOPY} ) | (cd $DEST; tar xvf - )
	#(cd / ; find -x dev | cpio -o -H newc ) | \
	#	(cd $DEST; cpio -i -H newc -d )
	echo "+++ Fixing permissions on some objects"
	chmod 555 $DEST/sbin/init
}

update_conf_and_pw() {
	echo "+++ Copying files in /conf and password files"
	(cd ${DEST} ; rm -rf conf )
	(cd / ; tar clf - conf ) | (cd ${DEST}; tar xvf - )
	mkdir -p ${DEST}/conf/etc	# used to mount things
	(cd /etc ; tar cvf - ${PWFILES} ) | (cd ${DEST}/etc ; tar xf - )
}

update() {
	echo "+++ update: create mountpoints and device entries, kernel"
	for i in ${SYSDIRS} ${DIRS}
	do
	    rm -r -f ${DEST}/$i
	    mkdir -p ${DEST}/$i && chown root:wheel ${DEST}/$i && echo -n "$i "
	done
	echo "."
	ln -s /var/tmp ${DEST}/tmp
	echo "+++ Copying kernel from /sys/compile/DISKLESS"
	cp /sys/compile/DISKLESS/kernel $DEST/kernel
	echo "."
}


# Main entry point
case $1 in
	all)	# clean and reinstall the whole diskless_root
		init_diskless_root
		update
		update_conf_and_pw
		;;

	update)	# clean and rebuild mountpoints and device entries
		update
		update_conf_and_pw
		;;

	*)	# copy /conf and password files
		update_conf_and_pw
		;;
esac
exit 0
### end of file ###
OpenPOWER on IntegriCloud