clone_root revision 159175
175537Sluigi#!/bin/sh 275537Sluigi# 375537Sluigi# (C) 2001 Luigi Rizzo, Gabriele Cecchetti 475537Sluigi# <Standard BSD copyright> 575537Sluigi# Revised 2001.04.16 675537Sluigi# 775537Sluigi# $FreeBSD: head/share/examples/diskless/clone_root 159175 2006-06-02 15:01:11Z motoyuki $ 875537Sluigi# 975537Sluigi# clone root filesystem for diskless root stuff 1075537Sluigi# 1175537Sluigi# usage 1275537Sluigi# clone_root all to do a full copy (e.g. bin, sbin...) 1375537Sluigi# clone_root update to recreate /var (including devices) 1475537Sluigi# clone_root to copy /conf and password-related files 1575537Sluigi# 1675537Sluigi# This script assumes that you use a shared readonly root and /usr 1775537Sluigi# partition. The script creates a partial clone of the root partition, 1875537Sluigi# and puts it into ${DEST} (defaults to /diskless_root ) on the server, 1975537Sluigi# where it is read. 2075537Sluigi# 2175537Sluigi# To run a diskless install you need to do the following: 2275537Sluigi# 2375537Sluigi# create /conf/default/etc/fstab 2475537Sluigi# this will replace the standard /etc/fstab and should contain 2575537Sluigi# as a minimum the following lines 2675537Sluigi# ${SERVER}:${DEST} / nfs ro 0 0 2775537Sluigi# ${SERVER}:/usr /usr nfs ro 0 0 2875537Sluigi# proc /proc procfs rw 0 0 2975537Sluigi# 3075537Sluigi# create /conf/default/etc/rc.conf 3175537Sluigi# this will replace the standard rc.conf and should contain 3275537Sluigi# the startup options for the diskless client. Most likely 3375537Sluigi# you will not need to set hostname and ifconfig_* because these 3475537Sluigi# will be already set by the startup code. You will also 3575537Sluigi# probably need to set local_startup="" so that the server's 3675537Sluigi# local startup files will not be used. 3775537Sluigi# 3875537Sluigi# create a kernel config file in /sys/i386/conf/DISKLESS with 39159175Smotoyuki# options MD_ROOT 4075537Sluigi# options BOOTP 4175537Sluigi# options BOOTP_NFSROOT 4275537Sluigi# options BOOTP_COMPAT 4375537Sluigi# and do a full build of the kernel. 4475537Sluigi# If you use the firewall, remember to default to open or your kernel 4575537Sluigi# will not be able to send/receive the bootp packets. 4675537Sluigi# 4775537Sluigi# On the server: 4875537Sluigi# enable NFS server and set /etc/exports as 4975537Sluigi# ${DEST} -maproot=0 -alldirs <list of diskless clients> 5075537Sluigi# /usr -alldirs 5175537Sluigi# 5275537Sluigi# enable bootpd by uncommenting the bootps line in /etc/inetd.conf 5375537Sluigi# and putting at least the following entries in /etc/bootptab: 5475537Sluigi# .default:\ 5575537Sluigi# hn:ht=1:vm=rfc1048:\ 5675537Sluigi# :sm=255.255.255.0:\ 5775537Sluigi# :sa=${SERVER}:\ 5875537Sluigi# :gw=${GATEWAY}:\ 5975537Sluigi# :rp="${SERVER}:${DEST}": 6075537Sluigi# 6175537Sluigi# client1:ha=0123456789ab:tc=.default 6275537Sluigi# 6375537Sluigi# and make sure that client1 is listed in /etc/hosts 6475537Sluigi 6575537Sluigi# VARIABLES: 6675537Sluigi# some manual init is needed here. 6775537Sluigi# DEST the diskless_root dir (goes into /etc/bootptab and /etc/exports 6875537Sluigi# on the server) 6975537SluigiDEST=/diskless_root 7075537Sluigi 7175537Sluigi# you should not touch these vars: 7275537Sluigi# SYSDIRS system directories and mountpoints 7375537Sluigi# DIRS mountpoints (empty dirs) 7475537Sluigi# PWFILES files related to passwords 7575537Sluigi# TOCOPY files and dirs to copy from root partition 7675537Sluigi 7775537SluigiSYSDIRS="dev proc root usr var" 7875537SluigiDIRS="cdrom home mnt" 7975537SluigiPWFILES="master.passwd passwd spwd.db pwd.db" 8075537SluigiTOCOPY="bin boot compat etc modules sbin stand sys" 8175537Sluigi 8275537Sluigiinit_diskless_root() { 8375537Sluigi echo "Cleaning old diskless root ($DEST)" 8475537Sluigi cd / 8575537Sluigi rm -rf ${DEST} && echo "Old diskless root removed." 8675537Sluigi echo "Creating $DEST..." 8775537Sluigi mkdir -p $DEST && echo "New diskless root created." 8875537Sluigi echo "+++ Now copy original tree from / ..." 8975537Sluigi ex="" 90135639Sbrooks (cd / ; tar -clf - ${TOCOPY} ) | (cd $DEST; tar xvf - ) 9175537Sluigi #(cd / ; find -x dev | cpio -o -H newc ) | \ 9275537Sluigi # (cd $DEST; cpio -i -H newc -d ) 9375537Sluigi echo "+++ Fixing permissions on some objects" 9475537Sluigi chmod 555 $DEST/sbin/init 9575537Sluigi} 9675537Sluigi 9775537Sluigiupdate_conf_and_pw() { 9875537Sluigi echo "+++ Copying files in /conf and password files" 9975537Sluigi (cd ${DEST} ; rm -rf conf ) 10075537Sluigi (cd / ; tar clf - conf ) | (cd ${DEST}; tar xvf - ) 10175537Sluigi mkdir -p ${DEST}/conf/etc # used to mount things 10275537Sluigi (cd /etc ; tar cvf - ${PWFILES} ) | (cd ${DEST}/etc ; tar xf - ) 10375537Sluigi} 10475537Sluigi 10575537Sluigiupdate() { 10675537Sluigi echo "+++ update: create mountpoints and device entries, kernel" 10775537Sluigi for i in ${SYSDIRS} ${DIRS} 10875537Sluigi do 10975537Sluigi rm -r -f ${DEST}/$i 11075537Sluigi mkdir -p ${DEST}/$i && chown root:wheel ${DEST}/$i && echo -n "$i " 11175537Sluigi done 11275537Sluigi echo "." 11375537Sluigi ln -s /var/tmp ${DEST}/tmp 11475537Sluigi echo "+++ Copying kernel from /sys/compile/DISKLESS" 11575537Sluigi cp /sys/compile/DISKLESS/kernel $DEST/kernel 11675537Sluigi echo "." 11775537Sluigi} 11875537Sluigi 11975537Sluigi 12075537Sluigi# Main entry point 12175537Sluigicase $1 in 12275537Sluigi all) # clean and reinstall the whole diskless_root 12375537Sluigi init_diskless_root 12475537Sluigi update 12575537Sluigi update_conf_and_pw 12675537Sluigi ;; 12775537Sluigi 12875537Sluigi update) # clean and rebuild mountpoints and device entries 12975537Sluigi update 13075537Sluigi update_conf_and_pw 13175537Sluigi ;; 13275537Sluigi 13375537Sluigi *) # copy /conf and password files 13475537Sluigi update_conf_and_pw 13575537Sluigi ;; 13675537Sluigiesac 13775537Sluigiexit 0 13875537Sluigi### end of file ### 139