clone_root revision 75537
1130803Smarcel#!/bin/sh 2130803Smarcel# 3130803Smarcel# (C) 2001 Luigi Rizzo, Gabriele Cecchetti 4130803Smarcel# <Standard BSD copyright> 598944Sobrien# Revised 2001.04.16 698944Sobrien# 798944Sobrien# $FreeBSD: head/share/examples/diskless/clone_root 75537 2001-04-16 06:37:03Z luigi $ 898944Sobrien# 998944Sobrien# clone root filesystem for diskless root stuff 1098944Sobrien# 1198944Sobrien# usage 1298944Sobrien# clone_root all to do a full copy (e.g. bin, sbin...) 1398944Sobrien# clone_root update to recreate /var (including devices) 1498944Sobrien# clone_root to copy /conf and password-related files 1598944Sobrien# 1698944Sobrien# This script assumes that you use a shared readonly root and /usr 1798944Sobrien# partition. The script creates a partial clone of the root partition, 1898944Sobrien# and puts it into ${DEST} (defaults to /diskless_root ) on the server, 1998944Sobrien# where it is read. 2098944Sobrien# 2198944Sobrien# To run a diskless install you need to do the following: 2298944Sobrien# 2398944Sobrien# create /conf/default/etc/fstab 2498944Sobrien# this will replace the standard /etc/fstab and should contain 25130803Smarcel# as a minimum the following lines 26130803Smarcel# ${SERVER}:${DEST} / nfs ro 0 0 27130803Smarcel# ${SERVER}:/usr /usr nfs ro 0 0 28130803Smarcel# proc /proc procfs rw 0 0 29130803Smarcel# 3098944Sobrien# create /conf/default/etc/rc.conf 31130803Smarcel# this will replace the standard rc.conf and should contain 32130803Smarcel# the startup options for the diskless client. Most likely 33130803Smarcel# you will not need to set hostname and ifconfig_* because these 34130803Smarcel# will be already set by the startup code. You will also 35130803Smarcel# probably need to set local_startup="" so that the server's 36130803Smarcel# local startup files will not be used. 37130803Smarcel# 38130803Smarcel# create a kernel config file in /sys/i386/conf/DISKLESS with 39130803Smarcel# options MFS 40130803Smarcel# options BOOTP 4198944Sobrien# options BOOTP_NFSROOT 42130803Smarcel# options BOOTP_COMPAT 43130803Smarcel# and do a full build of the kernel. 44130803Smarcel# If you use the firewall, remember to default to open or your kernel 45130803Smarcel# will not be able to send/receive the bootp packets. 46130803Smarcel# 47130803Smarcel# On the server: 48130803Smarcel# enable NFS server and set /etc/exports as 49130803Smarcel# ${DEST} -maproot=0 -alldirs <list of diskless clients> 50130803Smarcel# /usr -alldirs 51130803Smarcel# 52130803Smarcel# enable bootpd by uncommenting the bootps line in /etc/inetd.conf 53130803Smarcel# and putting at least the following entries in /etc/bootptab: 54130803Smarcel# .default:\ 55130803Smarcel# hn:ht=1:vm=rfc1048:\ 56130803Smarcel# :sm=255.255.255.0:\ 57130803Smarcel# :sa=${SERVER}:\ 58130803Smarcel# :gw=${GATEWAY}:\ 59130803Smarcel# :rp="${SERVER}:${DEST}": 60130803Smarcel# 61130803Smarcel# client1:ha=0123456789ab:tc=.default 62130803Smarcel# 63130803Smarcel# and make sure that client1 is listed in /etc/hosts 64130803Smarcel 65130803Smarcel# VARIABLES: 66130803Smarcel# some manual init is needed here. 67130803Smarcel# DEST the diskless_root dir (goes into /etc/bootptab and /etc/exports 68130803Smarcel# on the server) 69130803Smarcel# DEVICES device entries to create in /dev 70130803SmarcelDEST=/diskless_root 7198944SobrienDEVICES="all snd1 bktr0" 72130803Smarcel 73130803Smarcel# you should not touch these vars: 74130803Smarcel# SYSDIRS system directories and mountpoints 75130803Smarcel# DIRS mountpoints (empty dirs) 76130803Smarcel# PWFILES files related to passwords 77130803Smarcel# TOCOPY files and dirs to copy from root partition 78130803Smarcel 79130803SmarcelSYSDIRS="dev proc root usr var" 80130803SmarcelDIRS="cdrom home mnt" 81130803SmarcelPWFILES="master.passwd passwd spwd.db pwd.db" 82130803SmarcelTOCOPY="bin boot compat etc modules sbin stand sys" 83130803Smarcel 84130803Smarcelinit_diskless_root() { 85130803Smarcel echo "Cleaning old diskless root ($DEST)" 86130803Smarcel cd / 87130803Smarcel rm -rf ${DEST} && echo "Old diskless root removed." 88130803Smarcel echo "Creating $DEST..." 89130803Smarcel mkdir -p $DEST && echo "New diskless root created." 90130803Smarcel echo "+++ Now copy original tree from / ..." 91130803Smarcel ex="" 92130803Smarcel (cd / ; tar -clf - ${TOCOPY} ) | (cd $DEST; tar xvf - ) 93130803Smarcel #(cd / ; find -x dev | cpio -o -H newc ) | \ 94130803Smarcel # (cd $DEST; cpio -i -H newc -d ) 95130803Smarcel echo "+++ Fixing permissions on some objects" 96130803Smarcel chmod 555 $DEST/sbin/init 97130803Smarcel} 98130803Smarcel 99130803Smarcelupdate_conf_and_pw() { 100130803Smarcel echo "+++ Copying files in /conf and password files" 101130803Smarcel (cd ${DEST} ; rm -rf conf ) 102130803Smarcel (cd / ; tar clf - conf ) | (cd ${DEST}; tar xvf - ) 103130803Smarcel mkdir -p ${DEST}/conf/etc # used to mount things 104130803Smarcel (cd /etc ; tar cvf - ${PWFILES} ) | (cd ${DEST}/etc ; tar xf - ) 105130803Smarcel} 106130803Smarcel 107130803Smarcelupdate() { 108130803Smarcel echo "+++ update: create mountpoints and device entries, kernel" 109130803Smarcel for i in ${SYSDIRS} ${DIRS} 110130803Smarcel do 111130803Smarcel rm -r -f ${DEST}/$i 112130803Smarcel mkdir -p ${DEST}/$i && chown root:wheel ${DEST}/$i && echo -n "$i " 113130803Smarcel done 114130803Smarcel echo "." 115130803Smarcel ln -s /var/tmp ${DEST}/tmp 116130803Smarcel echo "+++ Now use MAKEDEV to create devices ${DEVICES}" 117130803Smarcel (cd $DEST/dev ; cp /dev/MAKEDEV . ) 118130803Smarcel (cd $DEST/dev ; /dev/MAKEDEV ${DEVICES} ) 119130803Smarcel (cd $DEST/dev ; ln -s /dev/sysmouse mouse ) 120130803Smarcel echo "+++ Copying kernel from /sys/compile/DISKLESS" 121130803Smarcel cp /sys/compile/DISKLESS/kernel $DEST/kernel 122130803Smarcel echo "." 123130803Smarcel} 124130803Smarcel 125130803Smarcel 126130803Smarcel# Main entry point 127130803Smarcelcase $1 in 128130803Smarcel all) # clean and reinstall the whole diskless_root 129130803Smarcel init_diskless_root 130130803Smarcel update 131130803Smarcel update_conf_and_pw 132130803Smarcel ;; 133130803Smarcel 134130803Smarcel update) # clean and rebuild mountpoints and device entries 135130803Smarcel update 136130803Smarcel update_conf_and_pw 137130803Smarcel ;; 138130803Smarcel 139130803Smarcel *) # copy /conf and password files 140130803Smarcel update_conf_and_pw 141130803Smarcel ;; 142130803Smarcelesac 143130803Smarcelexit 0 144130803Smarcel### end of file ### 145130803Smarcel