clone_root revision 75537
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 75537 2001-04-16 06:37:03Z luigi $ 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 3975537Sluigi# options MFS 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) 6975537Sluigi# DEVICES device entries to create in /dev 7075537SluigiDEST=/diskless_root 7175537SluigiDEVICES="all snd1 bktr0" 7275537Sluigi 7375537Sluigi# you should not touch these vars: 7475537Sluigi# SYSDIRS system directories and mountpoints 7575537Sluigi# DIRS mountpoints (empty dirs) 7675537Sluigi# PWFILES files related to passwords 7775537Sluigi# TOCOPY files and dirs to copy from root partition 7875537Sluigi 7975537SluigiSYSDIRS="dev proc root usr var" 8075537SluigiDIRS="cdrom home mnt" 8175537SluigiPWFILES="master.passwd passwd spwd.db pwd.db" 8275537SluigiTOCOPY="bin boot compat etc modules sbin stand sys" 8375537Sluigi 8475537Sluigiinit_diskless_root() { 8575537Sluigi echo "Cleaning old diskless root ($DEST)" 8675537Sluigi cd / 8775537Sluigi rm -rf ${DEST} && echo "Old diskless root removed." 8875537Sluigi echo "Creating $DEST..." 8975537Sluigi mkdir -p $DEST && echo "New diskless root created." 9075537Sluigi echo "+++ Now copy original tree from / ..." 9175537Sluigi ex="" 9275537Sluigi (cd / ; tar -clf - ${TOCOPY} ) | (cd $DEST; tar xvf - ) 9375537Sluigi #(cd / ; find -x dev | cpio -o -H newc ) | \ 9475537Sluigi # (cd $DEST; cpio -i -H newc -d ) 9575537Sluigi echo "+++ Fixing permissions on some objects" 9675537Sluigi chmod 555 $DEST/sbin/init 9775537Sluigi} 9875537Sluigi 9975537Sluigiupdate_conf_and_pw() { 10075537Sluigi echo "+++ Copying files in /conf and password files" 10175537Sluigi (cd ${DEST} ; rm -rf conf ) 10275537Sluigi (cd / ; tar clf - conf ) | (cd ${DEST}; tar xvf - ) 10375537Sluigi mkdir -p ${DEST}/conf/etc # used to mount things 10475537Sluigi (cd /etc ; tar cvf - ${PWFILES} ) | (cd ${DEST}/etc ; tar xf - ) 10575537Sluigi} 10675537Sluigi 10775537Sluigiupdate() { 10875537Sluigi echo "+++ update: create mountpoints and device entries, kernel" 10975537Sluigi for i in ${SYSDIRS} ${DIRS} 11075537Sluigi do 11175537Sluigi rm -r -f ${DEST}/$i 11275537Sluigi mkdir -p ${DEST}/$i && chown root:wheel ${DEST}/$i && echo -n "$i " 11375537Sluigi done 11475537Sluigi echo "." 11575537Sluigi ln -s /var/tmp ${DEST}/tmp 11675537Sluigi echo "+++ Now use MAKEDEV to create devices ${DEVICES}" 11775537Sluigi (cd $DEST/dev ; cp /dev/MAKEDEV . ) 11875537Sluigi (cd $DEST/dev ; /dev/MAKEDEV ${DEVICES} ) 11975537Sluigi (cd $DEST/dev ; ln -s /dev/sysmouse mouse ) 12075537Sluigi echo "+++ Copying kernel from /sys/compile/DISKLESS" 12175537Sluigi cp /sys/compile/DISKLESS/kernel $DEST/kernel 12275537Sluigi echo "." 12375537Sluigi} 12475537Sluigi 12575537Sluigi 12675537Sluigi# Main entry point 12775537Sluigicase $1 in 12875537Sluigi all) # clean and reinstall the whole diskless_root 12975537Sluigi init_diskless_root 13075537Sluigi update 13175537Sluigi update_conf_and_pw 13275537Sluigi ;; 13375537Sluigi 13475537Sluigi update) # clean and rebuild mountpoints and device entries 13575537Sluigi update 13675537Sluigi update_conf_and_pw 13775537Sluigi ;; 13875537Sluigi 13975537Sluigi *) # copy /conf and password files 14075537Sluigi update_conf_and_pw 14175537Sluigi ;; 14275537Sluigiesac 14375537Sluigiexit 0 14475537Sluigi### end of file ### 145