1*0696600cSBjoern A. Zeeb#!/bin/sh 2*0696600cSBjoern A. Zeeb# 3*0696600cSBjoern A. Zeeb# Copyright (c) 1999 Matt Dillon 4*0696600cSBjoern A. Zeeb# All rights reserved. 5*0696600cSBjoern A. Zeeb# 6*0696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 7*0696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions 8*0696600cSBjoern A. Zeeb# are met: 9*0696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 10*0696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 11*0696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 12*0696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 13*0696600cSBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 14*0696600cSBjoern A. Zeeb# 15*0696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*0696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*0696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*0696600cSBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*0696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*0696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*0696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*0696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*0696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*0696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*0696600cSBjoern A. Zeeb# SUCH DAMAGE. 26*0696600cSBjoern A. Zeeb# 27*0696600cSBjoern A. Zeeb# $FreeBSD$ 28*0696600cSBjoern A. Zeeb 29*0696600cSBjoern A. Zeeb# On entry to this script the entire system consists of a read-only root 30*0696600cSBjoern A. Zeeb# mounted via NFS. The kernel has run BOOTP and configured an interface 31*0696600cSBjoern A. Zeeb# (otherwise it would not have been able to mount the NFS root!) 32*0696600cSBjoern A. Zeeb# 33*0696600cSBjoern A. Zeeb# We use the contents of /conf to create and populate memory filesystems 34*0696600cSBjoern A. Zeeb# that are mounted on top of this root to implement the writable 35*0696600cSBjoern A. Zeeb# (and host-specific) parts of the root filesystem, and other volatile 36*0696600cSBjoern A. Zeeb# filesystems. 37*0696600cSBjoern A. Zeeb# 38*0696600cSBjoern A. Zeeb# The hierarchy in /conf has the form /conf/T/M/ where M are directories 39*0696600cSBjoern A. Zeeb# for which memory filesystems will be created and filled, 40*0696600cSBjoern A. Zeeb# and T is one of the "template" directories below: 41*0696600cSBjoern A. Zeeb# 42*0696600cSBjoern A. Zeeb# base universal base, typically a replica of the original root; 43*0696600cSBjoern A. Zeeb# default secondary universal base, typically overriding some 44*0696600cSBjoern A. Zeeb# of the files in the original root; 45*0696600cSBjoern A. Zeeb# ${ipba} where ${ipba} is the assigned broadcast IP address 46*0696600cSBjoern A. Zeeb# bcast/${ipba} same as above 47*0696600cSBjoern A. Zeeb# ${class} where ${class} is a list of directories supplied by 48*0696600cSBjoern A. Zeeb# bootp/dhcp through the T134 option. 49*0696600cSBjoern A. Zeeb# ${ipba} and ${class} are typically used to configure features 50*0696600cSBjoern A. Zeeb# for group of diskless clients, or even individual features; 51*0696600cSBjoern A. Zeeb# ${ip} where ${ip} is the machine's assigned IP address, typically 52*0696600cSBjoern A. Zeeb# used to set host-specific features; 53*0696600cSBjoern A. Zeeb# ip/${ip} same as above 54*0696600cSBjoern A. Zeeb# 55*0696600cSBjoern A. Zeeb# Template directories are scanned in the order they are listed above, 56*0696600cSBjoern A. Zeeb# with each successive directory overriding (merged into) the previous one; 57*0696600cSBjoern A. Zeeb# non-existing directories are ignored. The subdirectory forms exist to 58*0696600cSBjoern A. Zeeb# help keep the top level /conf manageable in large installations. 59*0696600cSBjoern A. Zeeb# 60*0696600cSBjoern A. Zeeb# The existence of a directory /conf/T/M causes this script to create a 61*0696600cSBjoern A. Zeeb# memory filesystem mounted as /M on the client. 62*0696600cSBjoern A. Zeeb# 63*0696600cSBjoern A. Zeeb# Some files in /conf have special meaning, namely: 64*0696600cSBjoern A. Zeeb# 65*0696600cSBjoern A. Zeeb# Filename Action 66*0696600cSBjoern A. Zeeb# ---------------------------------------------------------------- 67*0696600cSBjoern A. Zeeb# /conf/T/M/remount 68*0696600cSBjoern A. Zeeb# The contents of the file is a mount command. E.g. if 69*0696600cSBjoern A. Zeeb# /conf/1.2.3.4/foo/remount contains "mount -o ro /dev/ad0s3", 70*0696600cSBjoern A. Zeeb# then /dev/ad0s3 will be mounted on /conf/1.2.3.4/foo/ 71*0696600cSBjoern A. Zeeb# 72*0696600cSBjoern A. Zeeb# /conf/T/M/remount_optional 73*0696600cSBjoern A. Zeeb# If this file exists, then failure to execute the mount 74*0696600cSBjoern A. Zeeb# command contained in /conf/T/M/remount is non-fatal. 75*0696600cSBjoern A. Zeeb# 76*0696600cSBjoern A. Zeeb# /conf/T/M/remount_subdir 77*0696600cSBjoern A. Zeeb# If this file exists, then the behaviour of /conf/T/M/remount 78*0696600cSBjoern A. Zeeb# changes as follows: 79*0696600cSBjoern A. Zeeb# 1. /conf/T/M/remount is invoked to mount the root of the 80*0696600cSBjoern A. Zeeb# filesystem where the configuration data exists on a 81*0696600cSBjoern A. Zeeb# temporary mountpoint. 82*0696600cSBjoern A. Zeeb# 2. /conf/T/M/remount_subdir is then invoked to mount a 83*0696600cSBjoern A. Zeeb# *subdirectory* of the filesystem mounted by 84*0696600cSBjoern A. Zeeb# /conf/T/M/remount on /conf/T/M/. 85*0696600cSBjoern A. Zeeb# 86*0696600cSBjoern A. Zeeb# /conf/T/M/diskless_remount 87*0696600cSBjoern A. Zeeb# The contents of the file points to an NFS filesystem, 88*0696600cSBjoern A. Zeeb# possibly followed by mount_nfs options. If the server name 89*0696600cSBjoern A. Zeeb# is omitted, the script will prepend the root path used when 90*0696600cSBjoern A. Zeeb# booting. E.g. if you booted from foo.com:/path/to/root, 91*0696600cSBjoern A. Zeeb# an entry for /conf/base/etc/diskless_remount could be any of 92*0696600cSBjoern A. Zeeb# foo.com:/path/to/root/etc 93*0696600cSBjoern A. Zeeb# /etc -o ro 94*0696600cSBjoern A. Zeeb# Because mount_nfs understands ".." in paths, it is 95*0696600cSBjoern A. Zeeb# possible to mount from locations above the NFS root with 96*0696600cSBjoern A. Zeeb# paths such as "/../../etc". 97*0696600cSBjoern A. Zeeb# 98*0696600cSBjoern A. Zeeb# /conf/T/M/md_size 99*0696600cSBjoern A. Zeeb# The contents of the file specifies the size of the memory 100*0696600cSBjoern A. Zeeb# filesystem to be created, in 512 byte blocks. 101*0696600cSBjoern A. Zeeb# The default size is 10240 blocks (5MB). E.g. if 102*0696600cSBjoern A. Zeeb# /conf/base/etc/md_size contains "30000" then a 15MB MFS 103*0696600cSBjoern A. Zeeb# will be created. In case of multiple entries for the same 104*0696600cSBjoern A. Zeeb# directory M, the last one in the scanning order is used. 105*0696600cSBjoern A. Zeeb# NOTE: If you only need to create a memory filesystem but not 106*0696600cSBjoern A. Zeeb# initialize it from a template, it is preferable to specify 107*0696600cSBjoern A. Zeeb# it in fstab e.g. as "md /tmp mfs -s=30m,rw 0 0" 108*0696600cSBjoern A. Zeeb# 109*0696600cSBjoern A. Zeeb# /conf/T/SUBDIR.cpio.gz 110*0696600cSBjoern A. Zeeb# The file is cpio'd into /SUBDIR (and a memory filesystem is 111*0696600cSBjoern A. Zeeb# created for /SUBDIR if necessary). The presence of this file 112*0696600cSBjoern A. Zeeb# prevents the copy from /conf/T/SUBDIR/ 113*0696600cSBjoern A. Zeeb# 114*0696600cSBjoern A. Zeeb# /conf/T/SUBDIR.remove 115*0696600cSBjoern A. Zeeb# The list of paths contained in the file are rm -rf'd 116*0696600cSBjoern A. Zeeb# relative to /SUBDIR. 117*0696600cSBjoern A. Zeeb# 118*0696600cSBjoern A. Zeeb# /conf/diskless_remount 119*0696600cSBjoern A. Zeeb# Similar to /conf/T/M/diskless_remount above, but allows 120*0696600cSBjoern A. Zeeb# all of /conf to be remounted. This can be used to allow 121*0696600cSBjoern A. Zeeb# multiple roots to share the same /conf. 122*0696600cSBjoern A. Zeeb# 123*0696600cSBjoern A. Zeeb# 124*0696600cSBjoern A. Zeeb# You will almost universally want to create the following files under /conf 125*0696600cSBjoern A. Zeeb# 126*0696600cSBjoern A. Zeeb# File Content 127*0696600cSBjoern A. Zeeb# ---------------------------- ---------------------------------- 128*0696600cSBjoern A. Zeeb# /conf/base/etc/md_size size of /etc filesystem 129*0696600cSBjoern A. Zeeb# /conf/base/etc/diskless_remount "/etc" 130*0696600cSBjoern A. Zeeb# /conf/default/etc/rc.conf generic diskless config parameters 131*0696600cSBjoern A. Zeeb# /conf/default/etc/fstab generic diskless fstab e.g. like this 132*0696600cSBjoern A. Zeeb# 133*0696600cSBjoern A. Zeeb# foo:/root_part / nfs ro 0 0 134*0696600cSBjoern A. Zeeb# foo:/usr_part /usr nfs ro 0 0 135*0696600cSBjoern A. Zeeb# foo:/home_part /home nfs rw 0 0 136*0696600cSBjoern A. Zeeb# md /tmp mfs -s=30m,rw 0 0 137*0696600cSBjoern A. Zeeb# md /var mfs -s=30m,rw 0 0 138*0696600cSBjoern A. Zeeb# proc /proc procfs rw 0 0 139*0696600cSBjoern A. Zeeb# 140*0696600cSBjoern A. Zeeb# plus, possibly, overrides for password files etc. 141*0696600cSBjoern A. Zeeb# 142*0696600cSBjoern A. Zeeb# NOTE! /var, /tmp, and /dev will be typically created elsewhere, e.g. 143*0696600cSBjoern A. Zeeb# as entries in the fstab as above. 144*0696600cSBjoern A. Zeeb# Those filesystems should not be specified in /conf. 145*0696600cSBjoern A. Zeeb# 146*0696600cSBjoern A. Zeeb# (end of documentation, now get to the real code) 147*0696600cSBjoern A. Zeeb 148*0696600cSBjoern A. Zeebdlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 149*0696600cSBjoern A. Zeeb 150*0696600cSBjoern A. Zeeb# DEBUGGING 151*0696600cSBjoern A. Zeeb# log something on stdout if verbose. 152*0696600cSBjoern A. Zeebo_verbose=0 # set to 1 or 2 if you want more debugging 153*0696600cSBjoern A. Zeeblog() { 154*0696600cSBjoern A. Zeeb [ ${o_verbose} -gt 0 ] && echo "*** $* ***" 155*0696600cSBjoern A. Zeeb [ ${o_verbose} -gt 1 ] && read -p "=== Press enter to continue" foo 156*0696600cSBjoern A. Zeeb} 157*0696600cSBjoern A. Zeeb 158*0696600cSBjoern A. Zeeb# chkerr: 159*0696600cSBjoern A. Zeeb# 160*0696600cSBjoern A. Zeeb# Routine to check for error 161*0696600cSBjoern A. Zeeb# 162*0696600cSBjoern A. Zeeb# checks error code and drops into shell on failure. 163*0696600cSBjoern A. Zeeb# if shell exits, terminates script as well as /etc/rc. 164*0696600cSBjoern A. Zeeb# if remount_optional exists under the mountpoint, skip this check. 165*0696600cSBjoern A. Zeeb# 166*0696600cSBjoern A. Zeebchkerr() { 167*0696600cSBjoern A. Zeeb lastitem () ( n=$(($# - 1)) ; shift $n ; echo $1 ) 168*0696600cSBjoern A. Zeeb mountpoint="$(lastitem $2)" 169*0696600cSBjoern A. Zeeb [ -r $mountpoint/remount_optional ] && ( echo "$2 failed: ignoring due to remount_optional" ; return ) 170*0696600cSBjoern A. Zeeb case $1 in 171*0696600cSBjoern A. Zeeb 0) 172*0696600cSBjoern A. Zeeb ;; 173*0696600cSBjoern A. Zeeb *) 174*0696600cSBjoern A. Zeeb echo "$2 failed: dropping into /bin/sh" 175*0696600cSBjoern A. Zeeb /bin/sh 176*0696600cSBjoern A. Zeeb # RESUME 177*0696600cSBjoern A. Zeeb ;; 178*0696600cSBjoern A. Zeeb esac 179*0696600cSBjoern A. Zeeb} 180*0696600cSBjoern A. Zeeb 181*0696600cSBjoern A. Zeeb# The list of filesystems to umount after the copy 182*0696600cSBjoern A. Zeebto_umount="" 183*0696600cSBjoern A. Zeeb 184*0696600cSBjoern A. Zeebhandle_remount() { # $1 = mount point 185*0696600cSBjoern A. Zeeb local nfspt mountopts b 186*0696600cSBjoern A. Zeeb b=$1 187*0696600cSBjoern A. Zeeb log handle_remount $1 188*0696600cSBjoern A. Zeeb [ -d $b -a -f $b/diskless_remount ] || return 189*0696600cSBjoern A. Zeeb read nfspt mountopts < $b/diskless_remount 190*0696600cSBjoern A. Zeeb log "nfspt ${nfspt} mountopts ${mountopts}" 191*0696600cSBjoern A. Zeeb # prepend the nfs root if not present 192*0696600cSBjoern A. Zeeb [ `expr "$nfspt" : '\(.\)'` = "/" ] && nfspt="${nfsroot}${nfspt}" 193*0696600cSBjoern A. Zeeb mount_nfs $mountopts $nfspt $b 194*0696600cSBjoern A. Zeeb chkerr $? "mount_nfs $nfspt $b" 195*0696600cSBjoern A. Zeeb to_umount="$b ${to_umount}" 196*0696600cSBjoern A. Zeeb} 197*0696600cSBjoern A. Zeeb 198*0696600cSBjoern A. Zeeb# Create a generic memory disk. 199*0696600cSBjoern A. Zeeb# The 'auto' parameter will attempt to use tmpfs(5), falls back to md(4). 200*0696600cSBjoern A. Zeeb# $1 is size in 512-byte sectors, $2 is the mount point. 201*0696600cSBjoern A. Zeebmount_md() { 202*0696600cSBjoern A. Zeeb /sbin/mdmfs -s $1 auto $2 203*0696600cSBjoern A. Zeeb} 204*0696600cSBjoern A. Zeeb 205*0696600cSBjoern A. Zeeb# Create the memory filesystem if it has not already been created 206*0696600cSBjoern A. Zeeb# 207*0696600cSBjoern A. Zeebcreate_md() { 208*0696600cSBjoern A. Zeeb [ "x`eval echo \\$md_created_$1`" = "x" ] || return # only once 209*0696600cSBjoern A. Zeeb if [ "x`eval echo \\$md_size_$1`" = "x" ]; then 210*0696600cSBjoern A. Zeeb md_size=10240 211*0696600cSBjoern A. Zeeb else 212*0696600cSBjoern A. Zeeb md_size=`eval echo \\$md_size_$1` 213*0696600cSBjoern A. Zeeb fi 214*0696600cSBjoern A. Zeeb log create_md $1 with size $md_size 215*0696600cSBjoern A. Zeeb mount_md $md_size /$1 216*0696600cSBjoern A. Zeeb /bin/chmod 755 /$1 217*0696600cSBjoern A. Zeeb eval md_created_$1=created 218*0696600cSBjoern A. Zeeb} 219*0696600cSBjoern A. Zeeb 220*0696600cSBjoern A. Zeeb# DEBUGGING 221*0696600cSBjoern A. Zeeb# 222*0696600cSBjoern A. Zeeb# set -v 223*0696600cSBjoern A. Zeeb 224*0696600cSBjoern A. Zeeb# Figure out our interface and IP. 225*0696600cSBjoern A. Zeeb# 226*0696600cSBjoern A. Zeebbootp_ifc="" 227*0696600cSBjoern A. Zeebbootp_ipa="" 228*0696600cSBjoern A. Zeebbootp_ipbca="" 229*0696600cSBjoern A. Zeebclass="" 230*0696600cSBjoern A. Zeebif [ ${dlv:=0} -ne 0 ] ; then 231*0696600cSBjoern A. Zeeb iflist=`ifconfig -l` 232*0696600cSBjoern A. Zeeb for i in ${iflist} ; do 233*0696600cSBjoern A. Zeeb set -- `ifconfig ${i}` 234*0696600cSBjoern A. Zeeb while [ $# -ge 1 ] ; do 235*0696600cSBjoern A. Zeeb if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then 236*0696600cSBjoern A. Zeeb bootp_ifc=${i} ; bootp_ipa=${2} ; shift 237*0696600cSBjoern A. Zeeb fi 238*0696600cSBjoern A. Zeeb if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then 239*0696600cSBjoern A. Zeeb bootp_ipbca=$2; shift 240*0696600cSBjoern A. Zeeb fi 241*0696600cSBjoern A. Zeeb shift 242*0696600cSBjoern A. Zeeb done 243*0696600cSBjoern A. Zeeb if [ "${bootp_ifc}" != "" ] ; then 244*0696600cSBjoern A. Zeeb break 245*0696600cSBjoern A. Zeeb fi 246*0696600cSBjoern A. Zeeb done 247*0696600cSBjoern A. Zeeb # Get the values passed with the T134 bootp cookie. 248*0696600cSBjoern A. Zeeb class="`/sbin/sysctl -qn kern.bootp_cookie`" 249*0696600cSBjoern A. Zeeb 250*0696600cSBjoern A. Zeeb echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca} ${class}" 251*0696600cSBjoern A. Zeebfi 252*0696600cSBjoern A. Zeeb 253*0696600cSBjoern A. Zeeblog Figure out our NFS root path 254*0696600cSBjoern A. Zeeb# 255*0696600cSBjoern A. Zeebset -- `mount -t nfs` 256*0696600cSBjoern A. Zeebwhile [ $# -ge 1 ] ; do 257*0696600cSBjoern A. Zeeb if [ "$2" = "on" -a "$3" = "/" ]; then 258*0696600cSBjoern A. Zeeb nfsroot="$1" 259*0696600cSBjoern A. Zeeb break 260*0696600cSBjoern A. Zeeb fi 261*0696600cSBjoern A. Zeeb shift 262*0696600cSBjoern A. Zeebdone 263*0696600cSBjoern A. Zeeb 264*0696600cSBjoern A. Zeeb# The list of directories with template files 265*0696600cSBjoern A. Zeebtemplates="base default" 266*0696600cSBjoern A. Zeebif [ -n "${bootp_ipbca}" ]; then 267*0696600cSBjoern A. Zeeb templates="${templates} ${bootp_ipbca} bcast/${bootp_ipbca}" 268*0696600cSBjoern A. Zeebfi 269*0696600cSBjoern A. Zeebif [ -n "${class}" ]; then 270*0696600cSBjoern A. Zeeb templates="${templates} ${class}" 271*0696600cSBjoern A. Zeebfi 272*0696600cSBjoern A. Zeebif [ -n "${bootp_ipa}" ]; then 273*0696600cSBjoern A. Zeeb templates="${templates} ${bootp_ipa} ip/${bootp_ipa}" 274*0696600cSBjoern A. Zeebfi 275*0696600cSBjoern A. Zeeb 276*0696600cSBjoern A. Zeeb# If /conf/diskless_remount exists, remount all of /conf. 277*0696600cSBjoern A. Zeebhandle_remount /conf 278*0696600cSBjoern A. Zeeb 279*0696600cSBjoern A. Zeeb# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca}, 280*0696600cSBjoern A. Zeeb# and /conf/${bootp_ipa}. For each subdirectory found within these 281*0696600cSBjoern A. Zeeb# directories: 282*0696600cSBjoern A. Zeeb# 283*0696600cSBjoern A. Zeeb# - calculate memory filesystem sizes. If the subdirectory (prior to 284*0696600cSBjoern A. Zeeb# NFS remounting) contains the file 'md_size', the contents specified 285*0696600cSBjoern A. Zeeb# in 512 byte sectors will be used to size the memory filesystem. Otherwise 286*0696600cSBjoern A. Zeeb# 8192 sectors (4MB) is used. 287*0696600cSBjoern A. Zeeb# 288*0696600cSBjoern A. Zeeb# - handle NFS remounts. If the subdirectory contains the file 289*0696600cSBjoern A. Zeeb# diskless_remount, the contents of the file is NFS mounted over 290*0696600cSBjoern A. Zeeb# the directory. For example /conf/base/etc/diskless_remount 291*0696600cSBjoern A. Zeeb# might contain 'myserver:/etc'. NFS remounts allow you to avoid 292*0696600cSBjoern A. Zeeb# having to dup your system directories in /conf. Your server must 293*0696600cSBjoern A. Zeeb# be sure to export those filesystems -alldirs, however. 294*0696600cSBjoern A. Zeeb# If the diskless_remount file contains a string beginning with a 295*0696600cSBjoern A. Zeeb# '/' it is assumed that the local nfsroot should be prepended to 296*0696600cSBjoern A. Zeeb# it before attemping to the remount. This allows the root to be 297*0696600cSBjoern A. Zeeb# relocated without needing to change the remount files. 298*0696600cSBjoern A. Zeeb# 299*0696600cSBjoern A. Zeeblog "templates are ${templates}" 300*0696600cSBjoern A. Zeebfor i in ${templates} ; do 301*0696600cSBjoern A. Zeeb for j in /conf/$i/* ; do 302*0696600cSBjoern A. Zeeb [ -d $j ] || continue 303*0696600cSBjoern A. Zeeb 304*0696600cSBjoern A. Zeeb # memory filesystem size specification 305*0696600cSBjoern A. Zeeb subdir=${j##*/} 306*0696600cSBjoern A. Zeeb [ -f $j/md_size ] && eval md_size_$subdir=`cat $j/md_size` 307*0696600cSBjoern A. Zeeb 308*0696600cSBjoern A. Zeeb # remount. Beware, the command is in the file itself! 309*0696600cSBjoern A. Zeeb if [ -f $j/remount ]; then 310*0696600cSBjoern A. Zeeb if [ -f $j/remount_subdir ]; then 311*0696600cSBjoern A. Zeeb k="/conf.tmp/$i/$subdir" 312*0696600cSBjoern A. Zeeb [ -d $k ] || continue 313*0696600cSBjoern A. Zeeb 314*0696600cSBjoern A. Zeeb # Mount the filesystem root where the config data is 315*0696600cSBjoern A. Zeeb # on the temporary mount point. 316*0696600cSBjoern A. Zeeb nfspt=`/bin/cat $j/remount` 317*0696600cSBjoern A. Zeeb $nfspt $k 318*0696600cSBjoern A. Zeeb chkerr $? "$nfspt $k" 319*0696600cSBjoern A. Zeeb 320*0696600cSBjoern A. Zeeb # Now use a nullfs mount to get the data where we 321*0696600cSBjoern A. Zeeb # really want to see it. 322*0696600cSBjoern A. Zeeb remount_subdir=`/bin/cat $j/remount_subdir` 323*0696600cSBjoern A. Zeeb remount_subdir_cmd="mount -t nullfs $k/$remount_subdir" 324*0696600cSBjoern A. Zeeb 325*0696600cSBjoern A. Zeeb $remount_subdir_cmd $j 326*0696600cSBjoern A. Zeeb chkerr $? "$remount_subdir_cmd $j" 327*0696600cSBjoern A. Zeeb 328*0696600cSBjoern A. Zeeb # XXX check order -- we must force $k to be unmounted 329*0696600cSBjoern A. Zeeb # after j, as j depends on k. 330*0696600cSBjoern A. Zeeb to_umount="$j $k ${to_umount}" 331*0696600cSBjoern A. Zeeb else 332*0696600cSBjoern A. Zeeb nfspt=`/bin/cat $j/remount` 333*0696600cSBjoern A. Zeeb $nfspt $j 334*0696600cSBjoern A. Zeeb chkerr $? "$nfspt $j" 335*0696600cSBjoern A. Zeeb to_umount="$j ${to_umount}" # XXX hope it is really a mount! 336*0696600cSBjoern A. Zeeb fi 337*0696600cSBjoern A. Zeeb fi 338*0696600cSBjoern A. Zeeb 339*0696600cSBjoern A. Zeeb # NFS remount 340*0696600cSBjoern A. Zeeb handle_remount $j 341*0696600cSBjoern A. Zeeb done 342*0696600cSBjoern A. Zeebdone 343*0696600cSBjoern A. Zeeb 344*0696600cSBjoern A. Zeeb# - Create all required MFS filesystems and populate them from 345*0696600cSBjoern A. Zeeb# our templates. Support both a direct template and a dir.cpio.gz 346*0696600cSBjoern A. Zeeb# archive. Support dir.remove files containing a list of relative 347*0696600cSBjoern A. Zeeb# paths to remove. 348*0696600cSBjoern A. Zeeb# 349*0696600cSBjoern A. Zeeb# The dir.cpio.gz form is there to make the copy process more efficient, 350*0696600cSBjoern A. Zeeb# so if the cpio archive is present, it prevents the files from dir/ 351*0696600cSBjoern A. Zeeb# from being copied. 352*0696600cSBjoern A. Zeeb 353*0696600cSBjoern A. Zeebfor i in ${templates} ; do 354*0696600cSBjoern A. Zeeb for j in /conf/$i/* ; do 355*0696600cSBjoern A. Zeeb subdir=${j##*/} 356*0696600cSBjoern A. Zeeb if [ -d $j -a ! -f $j.cpio.gz ]; then 357*0696600cSBjoern A. Zeeb create_md $subdir 358*0696600cSBjoern A. Zeeb cp -Rp $j/ /$subdir 359*0696600cSBjoern A. Zeeb fi 360*0696600cSBjoern A. Zeeb done 361*0696600cSBjoern A. Zeeb for j in /conf/$i/*.cpio.gz ; do 362*0696600cSBjoern A. Zeeb subdir=${j%*.cpio.gz} 363*0696600cSBjoern A. Zeeb subdir=${subdir##*/} 364*0696600cSBjoern A. Zeeb if [ -f $j ]; then 365*0696600cSBjoern A. Zeeb create_md $subdir 366*0696600cSBjoern A. Zeeb echo "Loading /$subdir from cpio archive $j" 367*0696600cSBjoern A. Zeeb (cd / ; /rescue/tar -xpf $j) 368*0696600cSBjoern A. Zeeb fi 369*0696600cSBjoern A. Zeeb done 370*0696600cSBjoern A. Zeeb for j in /conf/$i/*.remove ; do 371*0696600cSBjoern A. Zeeb subdir=${j%*.remove} 372*0696600cSBjoern A. Zeeb subdir=${subdir##*/} 373*0696600cSBjoern A. Zeeb if [ -f $j ]; then 374*0696600cSBjoern A. Zeeb # doubly sure it is a memory disk before rm -rf'ing 375*0696600cSBjoern A. Zeeb create_md $subdir 376*0696600cSBjoern A. Zeeb (cd /$subdir; rm -rf `/bin/cat $j`) 377*0696600cSBjoern A. Zeeb fi 378*0696600cSBjoern A. Zeeb done 379*0696600cSBjoern A. Zeebdone 380*0696600cSBjoern A. Zeeb 381*0696600cSBjoern A. Zeeb# umount partitions used to fill the memory filesystems 382*0696600cSBjoern A. Zeeb[ -n "${to_umount}" ] && umount $to_umount 383