clone_root revision 75537
190792Sgshapiro#!/bin/sh 2261370Sgshapiro# 390792Sgshapiro# (C) 2001 Luigi Rizzo, Gabriele Cecchetti 490792Sgshapiro# <Standard BSD copyright> 590792Sgshapiro# Revised 2001.04.16 690792Sgshapiro# 790792Sgshapiro# $FreeBSD: head/share/examples/diskless/clone_root 75537 2001-04-16 06:37:03Z luigi $ 890792Sgshapiro# 990792Sgshapiro# clone root filesystem for diskless root stuff 1090792Sgshapiro# 1190792Sgshapiro# usage 1290792Sgshapiro# clone_root all to do a full copy (e.g. bin, sbin...) 1390792Sgshapiro# clone_root update to recreate /var (including devices) 1490792Sgshapiro# clone_root to copy /conf and password-related files 1590792Sgshapiro# 16266711Sgshapiro# This script assumes that you use a shared readonly root and /usr 1790792Sgshapiro# partition. The script creates a partial clone of the root partition, 1890792Sgshapiro# and puts it into ${DEST} (defaults to /diskless_root ) on the server, 1990792Sgshapiro# where it is read. 2090792Sgshapiro# 2190792Sgshapiro# To run a diskless install you need to do the following: 22157001Sgshapiro# 2390792Sgshapiro# create /conf/default/etc/fstab 2490792Sgshapiro# this will replace the standard /etc/fstab and should contain 2590792Sgshapiro# as a minimum the following lines 2690792Sgshapiro# ${SERVER}:${DEST} / nfs ro 0 0 2790792Sgshapiro# ${SERVER}:/usr /usr nfs ro 0 0 2890792Sgshapiro# proc /proc procfs rw 0 0 2990792Sgshapiro# 3090792Sgshapiro# create /conf/default/etc/rc.conf 3190792Sgshapiro# this will replace the standard rc.conf and should contain 3290792Sgshapiro# the startup options for the diskless client. Most likely 3390792Sgshapiro# you will not need to set hostname and ifconfig_* because these 3490792Sgshapiro# will be already set by the startup code. You will also 3590792Sgshapiro# probably need to set local_startup="" so that the server's 3690792Sgshapiro# local startup files will not be used. 3790792Sgshapiro# 3890792Sgshapiro# create a kernel config file in /sys/i386/conf/DISKLESS with 3990792Sgshapiro# options MFS 4090792Sgshapiro# options BOOTP 4190792Sgshapiro# options BOOTP_NFSROOT 4290792Sgshapiro# options BOOTP_COMPAT 4390792Sgshapiro# and do a full build of the kernel. 4490792Sgshapiro# If you use the firewall, remember to default to open or your kernel 4590792Sgshapiro# will not be able to send/receive the bootp packets. 4690792Sgshapiro# 4790792Sgshapiro# On the server: 4890792Sgshapiro# enable NFS server and set /etc/exports as 4990792Sgshapiro# ${DEST} -maproot=0 -alldirs <list of diskless clients> 5090792Sgshapiro# /usr -alldirs 5190792Sgshapiro# 5290792Sgshapiro# enable bootpd by uncommenting the bootps line in /etc/inetd.conf 5390792Sgshapiro# and putting at least the following entries in /etc/bootptab: 5490792Sgshapiro# .default:\ 5590792Sgshapiro# hn:ht=1:vm=rfc1048:\ 5690792Sgshapiro# :sm=255.255.255.0:\ 5790792Sgshapiro# :sa=${SERVER}:\ 5890792Sgshapiro# :gw=${GATEWAY}:\ 5990792Sgshapiro# :rp="${SERVER}:${DEST}": 6090792Sgshapiro# 6190792Sgshapiro# client1:ha=0123456789ab:tc=.default 6290792Sgshapiro# 6390792Sgshapiro# and make sure that client1 is listed in /etc/hosts 6490792Sgshapiro 6590792Sgshapiro# VARIABLES: 6690792Sgshapiro# some manual init is needed here. 6790792Sgshapiro# DEST the diskless_root dir (goes into /etc/bootptab and /etc/exports 68110560Sgshapiro# on the server) 69110560Sgshapiro# DEVICES device entries to create in /dev 70110560SgshapiroDEST=/diskless_root 71110560SgshapiroDEVICES="all snd1 bktr0" 72110560Sgshapiro 7390792Sgshapiro# you should not touch these vars: 7490792Sgshapiro# SYSDIRS system directories and mountpoints 7590792Sgshapiro# DIRS mountpoints (empty dirs) 7690792Sgshapiro# PWFILES files related to passwords 7790792Sgshapiro# TOCOPY files and dirs to copy from root partition 7890792Sgshapiro 79157001SgshapiroSYSDIRS="dev proc root usr var" 80157001SgshapiroDIRS="cdrom home mnt" 81157001SgshapiroPWFILES="master.passwd passwd spwd.db pwd.db" 82157001SgshapiroTOCOPY="bin boot compat etc modules sbin stand sys" 83157001Sgshapiro 8490792Sgshapiroinit_diskless_root() { 8590792Sgshapiro echo "Cleaning old diskless root ($DEST)" 8690792Sgshapiro cd / 8790792Sgshapiro rm -rf ${DEST} && echo "Old diskless root removed." 8890792Sgshapiro echo "Creating $DEST..." 8990792Sgshapiro mkdir -p $DEST && echo "New diskless root created." 9090792Sgshapiro echo "+++ Now copy original tree from / ..." 9190792Sgshapiro ex="" 9290792Sgshapiro (cd / ; tar -clf - ${TOCOPY} ) | (cd $DEST; tar xvf - ) 9390792Sgshapiro #(cd / ; find -x dev | cpio -o -H newc ) | \ 9490792Sgshapiro # (cd $DEST; cpio -i -H newc -d ) 9590792Sgshapiro echo "+++ Fixing permissions on some objects" 9690792Sgshapiro chmod 555 $DEST/sbin/init 9790792Sgshapiro} 9890792Sgshapiro 9990792Sgshapiroupdate_conf_and_pw() { 100157001Sgshapiro echo "+++ Copying files in /conf and password files" 10190792Sgshapiro (cd ${DEST} ; rm -rf conf ) 10290792Sgshapiro (cd / ; tar clf - conf ) | (cd ${DEST}; tar xvf - ) 10390792Sgshapiro mkdir -p ${DEST}/conf/etc # used to mount things 10490792Sgshapiro (cd /etc ; tar cvf - ${PWFILES} ) | (cd ${DEST}/etc ; tar xf - ) 10590792Sgshapiro} 10690792Sgshapiro 10790792Sgshapiroupdate() { 10890792Sgshapiro echo "+++ update: create mountpoints and device entries, kernel" 10990792Sgshapiro for i in ${SYSDIRS} ${DIRS} 11090792Sgshapiro do 11190792Sgshapiro rm -r -f ${DEST}/$i 11290792Sgshapiro mkdir -p ${DEST}/$i && chown root:wheel ${DEST}/$i && echo -n "$i " 11390792Sgshapiro done 11490792Sgshapiro echo "." 11590792Sgshapiro ln -s /var/tmp ${DEST}/tmp 11690792Sgshapiro echo "+++ Now use MAKEDEV to create devices ${DEVICES}" 11790792Sgshapiro (cd $DEST/dev ; cp /dev/MAKEDEV . ) 11890792Sgshapiro (cd $DEST/dev ; /dev/MAKEDEV ${DEVICES} ) 11990792Sgshapiro (cd $DEST/dev ; ln -s /dev/sysmouse mouse ) 12090792Sgshapiro echo "+++ Copying kernel from /sys/compile/DISKLESS" 12190792Sgshapiro cp /sys/compile/DISKLESS/kernel $DEST/kernel 12290792Sgshapiro echo "." 12390792Sgshapiro} 12490792Sgshapiro 12590792Sgshapiro 12690792Sgshapiro# Main entry point 12790792Sgshapirocase $1 in 12890792Sgshapiro all) # clean and reinstall the whole diskless_root 12990792Sgshapiro init_diskless_root 13090792Sgshapiro update 13190792Sgshapiro update_conf_and_pw 13290792Sgshapiro ;; 13390792Sgshapiro 13490792Sgshapiro update) # clean and rebuild mountpoints and device entries 13590792Sgshapiro update 13690792Sgshapiro update_conf_and_pw 13790792Sgshapiro ;; 13890792Sgshapiro 13990792Sgshapiro *) # copy /conf and password files 14090792Sgshapiro update_conf_and_pw 14190792Sgshapiro ;; 14290792Sgshapiroesac 14390792Sgshapiroexit 0 14490792Sgshapiro### end of file ### 14590792Sgshapiro