1047073a1SLuigi Rizzo#!/bin/sh 2047073a1SLuigi Rizzo# 3047073a1SLuigi Rizzo# (C) 2001 Luigi Rizzo, Gabriele Cecchetti 4047073a1SLuigi Rizzo# <Standard BSD copyright> 5047073a1SLuigi Rizzo# Revised 2001.04.16 6047073a1SLuigi Rizzo# 7047073a1SLuigi Rizzo# $FreeBSD$ 8047073a1SLuigi Rizzo# 9047073a1SLuigi Rizzo# clone root filesystem for diskless root stuff 10047073a1SLuigi Rizzo# 11047073a1SLuigi Rizzo# usage 12047073a1SLuigi Rizzo# clone_root all to do a full copy (e.g. bin, sbin...) 13047073a1SLuigi Rizzo# clone_root update to recreate /var (including devices) 14047073a1SLuigi Rizzo# clone_root to copy /conf and password-related files 15047073a1SLuigi Rizzo# 16047073a1SLuigi Rizzo# This script assumes that you use a shared readonly root and /usr 17047073a1SLuigi Rizzo# partition. The script creates a partial clone of the root partition, 18047073a1SLuigi Rizzo# and puts it into ${DEST} (defaults to /diskless_root ) on the server, 19047073a1SLuigi Rizzo# where it is read. 20047073a1SLuigi Rizzo# 21047073a1SLuigi Rizzo# To run a diskless install you need to do the following: 22047073a1SLuigi Rizzo# 23047073a1SLuigi Rizzo# create /conf/default/etc/fstab 24047073a1SLuigi Rizzo# this will replace the standard /etc/fstab and should contain 25047073a1SLuigi Rizzo# as a minimum the following lines 26047073a1SLuigi Rizzo# ${SERVER}:${DEST} / nfs ro 0 0 27047073a1SLuigi Rizzo# ${SERVER}:/usr /usr nfs ro 0 0 28047073a1SLuigi Rizzo# proc /proc procfs rw 0 0 29047073a1SLuigi Rizzo# 30047073a1SLuigi Rizzo# create /conf/default/etc/rc.conf 31047073a1SLuigi Rizzo# this will replace the standard rc.conf and should contain 32047073a1SLuigi Rizzo# the startup options for the diskless client. Most likely 33047073a1SLuigi Rizzo# you will not need to set hostname and ifconfig_* because these 34047073a1SLuigi Rizzo# will be already set by the startup code. You will also 35047073a1SLuigi Rizzo# probably need to set local_startup="" so that the server's 36047073a1SLuigi Rizzo# local startup files will not be used. 37047073a1SLuigi Rizzo# 38047073a1SLuigi Rizzo# create a kernel config file in /sys/i386/conf/DISKLESS with 39*0fdc646aSMotoyuki Konno# options MD_ROOT 40047073a1SLuigi Rizzo# options BOOTP 41047073a1SLuigi Rizzo# options BOOTP_NFSROOT 42047073a1SLuigi Rizzo# options BOOTP_COMPAT 43047073a1SLuigi Rizzo# and do a full build of the kernel. 44047073a1SLuigi Rizzo# If you use the firewall, remember to default to open or your kernel 45047073a1SLuigi Rizzo# will not be able to send/receive the bootp packets. 46047073a1SLuigi Rizzo# 47047073a1SLuigi Rizzo# On the server: 48047073a1SLuigi Rizzo# enable NFS server and set /etc/exports as 49047073a1SLuigi Rizzo# ${DEST} -maproot=0 -alldirs <list of diskless clients> 50047073a1SLuigi Rizzo# /usr -alldirs 51047073a1SLuigi Rizzo# 52047073a1SLuigi Rizzo# enable bootpd by uncommenting the bootps line in /etc/inetd.conf 53047073a1SLuigi Rizzo# and putting at least the following entries in /etc/bootptab: 54047073a1SLuigi Rizzo# .default:\ 55047073a1SLuigi Rizzo# hn:ht=1:vm=rfc1048:\ 56047073a1SLuigi Rizzo# :sm=255.255.255.0:\ 57047073a1SLuigi Rizzo# :sa=${SERVER}:\ 58047073a1SLuigi Rizzo# :gw=${GATEWAY}:\ 59047073a1SLuigi Rizzo# :rp="${SERVER}:${DEST}": 60047073a1SLuigi Rizzo# 61047073a1SLuigi Rizzo# client1:ha=0123456789ab:tc=.default 62047073a1SLuigi Rizzo# 63047073a1SLuigi Rizzo# and make sure that client1 is listed in /etc/hosts 64047073a1SLuigi Rizzo 65047073a1SLuigi Rizzo# VARIABLES: 66047073a1SLuigi Rizzo# some manual init is needed here. 67047073a1SLuigi Rizzo# DEST the diskless_root dir (goes into /etc/bootptab and /etc/exports 68047073a1SLuigi Rizzo# on the server) 69047073a1SLuigi RizzoDEST=/diskless_root 70047073a1SLuigi Rizzo 71047073a1SLuigi Rizzo# you should not touch these vars: 72047073a1SLuigi Rizzo# SYSDIRS system directories and mountpoints 73047073a1SLuigi Rizzo# DIRS mountpoints (empty dirs) 74047073a1SLuigi Rizzo# PWFILES files related to passwords 75047073a1SLuigi Rizzo# TOCOPY files and dirs to copy from root partition 76047073a1SLuigi Rizzo 77047073a1SLuigi RizzoSYSDIRS="dev proc root usr var" 78047073a1SLuigi RizzoDIRS="cdrom home mnt" 79047073a1SLuigi RizzoPWFILES="master.passwd passwd spwd.db pwd.db" 80047073a1SLuigi RizzoTOCOPY="bin boot compat etc modules sbin stand sys" 81047073a1SLuigi Rizzo 82047073a1SLuigi Rizzoinit_diskless_root() { 83047073a1SLuigi Rizzo echo "Cleaning old diskless root ($DEST)" 84047073a1SLuigi Rizzo cd / 85047073a1SLuigi Rizzo rm -rf ${DEST} && echo "Old diskless root removed." 86047073a1SLuigi Rizzo echo "Creating $DEST..." 87047073a1SLuigi Rizzo mkdir -p $DEST && echo "New diskless root created." 88047073a1SLuigi Rizzo echo "+++ Now copy original tree from / ..." 89047073a1SLuigi Rizzo ex="" 90f186a295SBrooks Davis (cd / ; tar -clf - ${TOCOPY} ) | (cd $DEST; tar xvf - ) 91047073a1SLuigi Rizzo #(cd / ; find -x dev | cpio -o -H newc ) | \ 92047073a1SLuigi Rizzo # (cd $DEST; cpio -i -H newc -d ) 93047073a1SLuigi Rizzo echo "+++ Fixing permissions on some objects" 94047073a1SLuigi Rizzo chmod 555 $DEST/sbin/init 95047073a1SLuigi Rizzo} 96047073a1SLuigi Rizzo 97047073a1SLuigi Rizzoupdate_conf_and_pw() { 98047073a1SLuigi Rizzo echo "+++ Copying files in /conf and password files" 99047073a1SLuigi Rizzo (cd ${DEST} ; rm -rf conf ) 100047073a1SLuigi Rizzo (cd / ; tar clf - conf ) | (cd ${DEST}; tar xvf - ) 101047073a1SLuigi Rizzo mkdir -p ${DEST}/conf/etc # used to mount things 102047073a1SLuigi Rizzo (cd /etc ; tar cvf - ${PWFILES} ) | (cd ${DEST}/etc ; tar xf - ) 103047073a1SLuigi Rizzo} 104047073a1SLuigi Rizzo 105047073a1SLuigi Rizzoupdate() { 106047073a1SLuigi Rizzo echo "+++ update: create mountpoints and device entries, kernel" 107047073a1SLuigi Rizzo for i in ${SYSDIRS} ${DIRS} 108047073a1SLuigi Rizzo do 109047073a1SLuigi Rizzo rm -r -f ${DEST}/$i 110047073a1SLuigi Rizzo mkdir -p ${DEST}/$i && chown root:wheel ${DEST}/$i && echo -n "$i " 111047073a1SLuigi Rizzo done 112047073a1SLuigi Rizzo echo "." 113047073a1SLuigi Rizzo ln -s /var/tmp ${DEST}/tmp 114047073a1SLuigi Rizzo echo "+++ Copying kernel from /sys/compile/DISKLESS" 115047073a1SLuigi Rizzo cp /sys/compile/DISKLESS/kernel $DEST/kernel 116047073a1SLuigi Rizzo echo "." 117047073a1SLuigi Rizzo} 118047073a1SLuigi Rizzo 119047073a1SLuigi Rizzo 120047073a1SLuigi Rizzo# Main entry point 121047073a1SLuigi Rizzocase $1 in 122047073a1SLuigi Rizzo all) # clean and reinstall the whole diskless_root 123047073a1SLuigi Rizzo init_diskless_root 124047073a1SLuigi Rizzo update 125047073a1SLuigi Rizzo update_conf_and_pw 126047073a1SLuigi Rizzo ;; 127047073a1SLuigi Rizzo 128047073a1SLuigi Rizzo update) # clean and rebuild mountpoints and device entries 129047073a1SLuigi Rizzo update 130047073a1SLuigi Rizzo update_conf_and_pw 131047073a1SLuigi Rizzo ;; 132047073a1SLuigi Rizzo 133047073a1SLuigi Rizzo *) # copy /conf and password files 134047073a1SLuigi Rizzo update_conf_and_pw 135047073a1SLuigi Rizzo ;; 136047073a1SLuigi Rizzoesac 137047073a1SLuigi Rizzoexit 0 138047073a1SLuigi Rizzo### end of file ### 139