10696600cSBjoern A. Zeeb#!/bin/sh 20696600cSBjoern A. Zeeb# 30696600cSBjoern A. Zeeb# Copyright (c) 1999 Matt Dillon 40696600cSBjoern A. Zeeb# All rights reserved. 50696600cSBjoern A. Zeeb# 60696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 70696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions 80696600cSBjoern A. Zeeb# are met: 90696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 100696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 110696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 120696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 130696600cSBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 140696600cSBjoern A. Zeeb# 150696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 160696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 170696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 180696600cSBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 190696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 200696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 210696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 220696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 230696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 240696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 250696600cSBjoern A. Zeeb# SUCH DAMAGE. 260696600cSBjoern A. Zeeb# 270696600cSBjoern A. Zeeb# $FreeBSD$ 280696600cSBjoern A. Zeeb 290696600cSBjoern A. Zeeb# On entry to this script the entire system consists of a read-only root 300696600cSBjoern A. Zeeb# mounted via NFS. The kernel has run BOOTP and configured an interface 310696600cSBjoern A. Zeeb# (otherwise it would not have been able to mount the NFS root!) 320696600cSBjoern A. Zeeb# 330696600cSBjoern A. Zeeb# We use the contents of /conf to create and populate memory filesystems 340696600cSBjoern A. Zeeb# that are mounted on top of this root to implement the writable 350696600cSBjoern A. Zeeb# (and host-specific) parts of the root filesystem, and other volatile 360696600cSBjoern A. Zeeb# filesystems. 370696600cSBjoern A. Zeeb# 380696600cSBjoern A. Zeeb# The hierarchy in /conf has the form /conf/T/M/ where M are directories 390696600cSBjoern A. Zeeb# for which memory filesystems will be created and filled, 400696600cSBjoern A. Zeeb# and T is one of the "template" directories below: 410696600cSBjoern A. Zeeb# 420696600cSBjoern A. Zeeb# base universal base, typically a replica of the original root; 430696600cSBjoern A. Zeeb# default secondary universal base, typically overriding some 440696600cSBjoern A. Zeeb# of the files in the original root; 450696600cSBjoern A. Zeeb# ${ipba} where ${ipba} is the assigned broadcast IP address 460696600cSBjoern A. Zeeb# bcast/${ipba} same as above 470696600cSBjoern A. Zeeb# ${class} where ${class} is a list of directories supplied by 480696600cSBjoern A. Zeeb# bootp/dhcp through the T134 option. 490696600cSBjoern A. Zeeb# ${ipba} and ${class} are typically used to configure features 500696600cSBjoern A. Zeeb# for group of diskless clients, or even individual features; 510696600cSBjoern A. Zeeb# ${ip} where ${ip} is the machine's assigned IP address, typically 520696600cSBjoern A. Zeeb# used to set host-specific features; 530696600cSBjoern A. Zeeb# ip/${ip} same as above 540696600cSBjoern A. Zeeb# 550696600cSBjoern A. Zeeb# Template directories are scanned in the order they are listed above, 560696600cSBjoern A. Zeeb# with each successive directory overriding (merged into) the previous one; 570696600cSBjoern A. Zeeb# non-existing directories are ignored. The subdirectory forms exist to 580696600cSBjoern A. Zeeb# help keep the top level /conf manageable in large installations. 590696600cSBjoern A. Zeeb# 600696600cSBjoern A. Zeeb# The existence of a directory /conf/T/M causes this script to create a 610696600cSBjoern A. Zeeb# memory filesystem mounted as /M on the client. 620696600cSBjoern A. Zeeb# 630696600cSBjoern A. Zeeb# Some files in /conf have special meaning, namely: 640696600cSBjoern A. Zeeb# 650696600cSBjoern A. Zeeb# Filename Action 660696600cSBjoern A. Zeeb# ---------------------------------------------------------------- 670696600cSBjoern A. Zeeb# /conf/T/M/remount 680696600cSBjoern A. Zeeb# The contents of the file is a mount command. E.g. if 690696600cSBjoern A. Zeeb# /conf/1.2.3.4/foo/remount contains "mount -o ro /dev/ad0s3", 700696600cSBjoern A. Zeeb# then /dev/ad0s3 will be mounted on /conf/1.2.3.4/foo/ 710696600cSBjoern A. Zeeb# 720696600cSBjoern A. Zeeb# /conf/T/M/remount_optional 730696600cSBjoern A. Zeeb# If this file exists, then failure to execute the mount 740696600cSBjoern A. Zeeb# command contained in /conf/T/M/remount is non-fatal. 750696600cSBjoern A. Zeeb# 760696600cSBjoern A. Zeeb# /conf/T/M/remount_subdir 770696600cSBjoern A. Zeeb# If this file exists, then the behaviour of /conf/T/M/remount 780696600cSBjoern A. Zeeb# changes as follows: 790696600cSBjoern A. Zeeb# 1. /conf/T/M/remount is invoked to mount the root of the 800696600cSBjoern A. Zeeb# filesystem where the configuration data exists on a 810696600cSBjoern A. Zeeb# temporary mountpoint. 820696600cSBjoern A. Zeeb# 2. /conf/T/M/remount_subdir is then invoked to mount a 830696600cSBjoern A. Zeeb# *subdirectory* of the filesystem mounted by 840696600cSBjoern A. Zeeb# /conf/T/M/remount on /conf/T/M/. 850696600cSBjoern A. Zeeb# 860696600cSBjoern A. Zeeb# /conf/T/M/diskless_remount 870696600cSBjoern A. Zeeb# The contents of the file points to an NFS filesystem, 880696600cSBjoern A. Zeeb# possibly followed by mount_nfs options. If the server name 890696600cSBjoern A. Zeeb# is omitted, the script will prepend the root path used when 900696600cSBjoern A. Zeeb# booting. E.g. if you booted from foo.com:/path/to/root, 910696600cSBjoern A. Zeeb# an entry for /conf/base/etc/diskless_remount could be any of 920696600cSBjoern A. Zeeb# foo.com:/path/to/root/etc 930696600cSBjoern A. Zeeb# /etc -o ro 940696600cSBjoern A. Zeeb# Because mount_nfs understands ".." in paths, it is 950696600cSBjoern A. Zeeb# possible to mount from locations above the NFS root with 960696600cSBjoern A. Zeeb# paths such as "/../../etc". 970696600cSBjoern A. Zeeb# 980696600cSBjoern A. Zeeb# /conf/T/M/md_size 990696600cSBjoern A. Zeeb# The contents of the file specifies the size of the memory 1000696600cSBjoern A. Zeeb# filesystem to be created, in 512 byte blocks. 1010696600cSBjoern A. Zeeb# The default size is 10240 blocks (5MB). E.g. if 1020696600cSBjoern A. Zeeb# /conf/base/etc/md_size contains "30000" then a 15MB MFS 1030696600cSBjoern A. Zeeb# will be created. In case of multiple entries for the same 1040696600cSBjoern A. Zeeb# directory M, the last one in the scanning order is used. 1050696600cSBjoern A. Zeeb# NOTE: If you only need to create a memory filesystem but not 1060696600cSBjoern A. Zeeb# initialize it from a template, it is preferable to specify 1070696600cSBjoern A. Zeeb# it in fstab e.g. as "md /tmp mfs -s=30m,rw 0 0" 1080696600cSBjoern A. Zeeb# 1090696600cSBjoern A. Zeeb# /conf/T/SUBDIR.cpio.gz 1100696600cSBjoern A. Zeeb# The file is cpio'd into /SUBDIR (and a memory filesystem is 1110696600cSBjoern A. Zeeb# created for /SUBDIR if necessary). The presence of this file 1120696600cSBjoern A. Zeeb# prevents the copy from /conf/T/SUBDIR/ 1130696600cSBjoern A. Zeeb# 114b4d24263SEugene Grosbein# /conf/T/M/extract 115b4d24263SEugene Grosbein# This is alternative to SUBDIR.cpio.gz and remount. 116b4d24263SEugene Grosbein# Similar to remount case, a memory filesystem is created 117b4d24263SEugene Grosbein# for /M and initialized from a template but no mounting 118707a657cSEugene Grosbein# performed. Instead, this file is run passing /M as single 119b4d24263SEugene Grosbein# argument. It is expected to extract template override to /M 120b4d24263SEugene Grosbein# using auxiliary storage found in some embedded systems 121b4d24263SEugene Grosbein# having NVRAM too small to hold mountable file system. 122b4d24263SEugene Grosbein# 1230696600cSBjoern A. Zeeb# /conf/T/SUBDIR.remove 1240696600cSBjoern A. Zeeb# The list of paths contained in the file are rm -rf'd 1250696600cSBjoern A. Zeeb# relative to /SUBDIR. 1260696600cSBjoern A. Zeeb# 1270696600cSBjoern A. Zeeb# /conf/diskless_remount 1280696600cSBjoern A. Zeeb# Similar to /conf/T/M/diskless_remount above, but allows 1290696600cSBjoern A. Zeeb# all of /conf to be remounted. This can be used to allow 1300696600cSBjoern A. Zeeb# multiple roots to share the same /conf. 1310696600cSBjoern A. Zeeb# 1320696600cSBjoern A. Zeeb# 1330696600cSBjoern A. Zeeb# You will almost universally want to create the following files under /conf 1340696600cSBjoern A. Zeeb# 1350696600cSBjoern A. Zeeb# File Content 1360696600cSBjoern A. Zeeb# ---------------------------- ---------------------------------- 1370696600cSBjoern A. Zeeb# /conf/base/etc/md_size size of /etc filesystem 1380696600cSBjoern A. Zeeb# /conf/base/etc/diskless_remount "/etc" 1390696600cSBjoern A. Zeeb# /conf/default/etc/rc.conf generic diskless config parameters 1400696600cSBjoern A. Zeeb# /conf/default/etc/fstab generic diskless fstab e.g. like this 1410696600cSBjoern A. Zeeb# 1420696600cSBjoern A. Zeeb# foo:/root_part / nfs ro 0 0 1430696600cSBjoern A. Zeeb# foo:/usr_part /usr nfs ro 0 0 1440696600cSBjoern A. Zeeb# foo:/home_part /home nfs rw 0 0 1450696600cSBjoern A. Zeeb# md /tmp mfs -s=30m,rw 0 0 1460696600cSBjoern A. Zeeb# md /var mfs -s=30m,rw 0 0 1470696600cSBjoern A. Zeeb# proc /proc procfs rw 0 0 1480696600cSBjoern A. Zeeb# 1490696600cSBjoern A. Zeeb# plus, possibly, overrides for password files etc. 1500696600cSBjoern A. Zeeb# 1510696600cSBjoern A. Zeeb# NOTE! /var, /tmp, and /dev will be typically created elsewhere, e.g. 1520696600cSBjoern A. Zeeb# as entries in the fstab as above. 1530696600cSBjoern A. Zeeb# Those filesystems should not be specified in /conf. 1540696600cSBjoern A. Zeeb# 1550696600cSBjoern A. Zeeb# (end of documentation, now get to the real code) 1560696600cSBjoern A. Zeeb 1570696600cSBjoern A. Zeebdlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 1580696600cSBjoern A. Zeeb 1590696600cSBjoern A. Zeeb# DEBUGGING 1600696600cSBjoern A. Zeeb# log something on stdout if verbose. 1610696600cSBjoern A. Zeebo_verbose=0 # set to 1 or 2 if you want more debugging 1620696600cSBjoern A. Zeeblog() { 1630696600cSBjoern A. Zeeb [ ${o_verbose} -gt 0 ] && echo "*** $* ***" 1640696600cSBjoern A. Zeeb [ ${o_verbose} -gt 1 ] && read -p "=== Press enter to continue" foo 1650696600cSBjoern A. Zeeb} 1660696600cSBjoern A. Zeeb 1670696600cSBjoern A. Zeeb# chkerr: 1680696600cSBjoern A. Zeeb# 1690696600cSBjoern A. Zeeb# Routine to check for error 1700696600cSBjoern A. Zeeb# 1710696600cSBjoern A. Zeeb# checks error code and drops into shell on failure. 1720696600cSBjoern A. Zeeb# if shell exits, terminates script as well as /etc/rc. 1730696600cSBjoern A. Zeeb# if remount_optional exists under the mountpoint, skip this check. 1740696600cSBjoern A. Zeeb# 1750696600cSBjoern A. Zeebchkerr() { 1760696600cSBjoern A. Zeeb lastitem () ( n=$(($# - 1)) ; shift $n ; echo $1 ) 1770696600cSBjoern A. Zeeb mountpoint="$(lastitem $2)" 1780696600cSBjoern A. Zeeb [ -r $mountpoint/remount_optional ] && ( echo "$2 failed: ignoring due to remount_optional" ; return ) 1790696600cSBjoern A. Zeeb case $1 in 1800696600cSBjoern A. Zeeb 0) 1810696600cSBjoern A. Zeeb ;; 1820696600cSBjoern A. Zeeb *) 1830696600cSBjoern A. Zeeb echo "$2 failed: dropping into /bin/sh" 1840696600cSBjoern A. Zeeb /bin/sh 1850696600cSBjoern A. Zeeb # RESUME 1860696600cSBjoern A. Zeeb ;; 1870696600cSBjoern A. Zeeb esac 1880696600cSBjoern A. Zeeb} 1890696600cSBjoern A. Zeeb 1900696600cSBjoern A. Zeeb# The list of filesystems to umount after the copy 1910696600cSBjoern A. Zeebto_umount="" 1920696600cSBjoern A. Zeeb 1930696600cSBjoern A. Zeebhandle_remount() { # $1 = mount point 1940696600cSBjoern A. Zeeb local nfspt mountopts b 1950696600cSBjoern A. Zeeb b=$1 1960696600cSBjoern A. Zeeb log handle_remount $1 1970696600cSBjoern A. Zeeb [ -d $b -a -f $b/diskless_remount ] || return 1980696600cSBjoern A. Zeeb read nfspt mountopts < $b/diskless_remount 1990696600cSBjoern A. Zeeb log "nfspt ${nfspt} mountopts ${mountopts}" 2000696600cSBjoern A. Zeeb # prepend the nfs root if not present 2010696600cSBjoern A. Zeeb [ `expr "$nfspt" : '\(.\)'` = "/" ] && nfspt="${nfsroot}${nfspt}" 2020696600cSBjoern A. Zeeb mount_nfs $mountopts $nfspt $b 2030696600cSBjoern A. Zeeb chkerr $? "mount_nfs $nfspt $b" 2040696600cSBjoern A. Zeeb to_umount="$b ${to_umount}" 2050696600cSBjoern A. Zeeb} 2060696600cSBjoern A. Zeeb 2070696600cSBjoern A. Zeeb# Create a generic memory disk. 2080696600cSBjoern A. Zeeb# The 'auto' parameter will attempt to use tmpfs(5), falls back to md(4). 2090696600cSBjoern A. Zeeb# $1 is size in 512-byte sectors, $2 is the mount point. 2100696600cSBjoern A. Zeebmount_md() { 211*26e8ed62SLev A. Serebryakov if [ ${o_verbose} -gt 0 ] ; then 212*26e8ed62SLev A. Serebryakov /sbin/mdmfs -XL -s $1 auto $2 213*26e8ed62SLev A. Serebryakov else 2140696600cSBjoern A. Zeeb /sbin/mdmfs -s $1 auto $2 215*26e8ed62SLev A. Serebryakov fi 2160696600cSBjoern A. Zeeb} 2170696600cSBjoern A. Zeeb 2180696600cSBjoern A. Zeeb# Create the memory filesystem if it has not already been created 2190696600cSBjoern A. Zeeb# 2200696600cSBjoern A. Zeebcreate_md() { 2210696600cSBjoern A. Zeeb [ "x`eval echo \\$md_created_$1`" = "x" ] || return # only once 2220696600cSBjoern A. Zeeb if [ "x`eval echo \\$md_size_$1`" = "x" ]; then 2230696600cSBjoern A. Zeeb md_size=10240 2240696600cSBjoern A. Zeeb else 2250696600cSBjoern A. Zeeb md_size=`eval echo \\$md_size_$1` 2260696600cSBjoern A. Zeeb fi 2270696600cSBjoern A. Zeeb log create_md $1 with size $md_size 2280696600cSBjoern A. Zeeb mount_md $md_size /$1 2290696600cSBjoern A. Zeeb /bin/chmod 755 /$1 2300696600cSBjoern A. Zeeb eval md_created_$1=created 2310696600cSBjoern A. Zeeb} 2320696600cSBjoern A. Zeeb 2330696600cSBjoern A. Zeeb# DEBUGGING 2340696600cSBjoern A. Zeeb# 2350696600cSBjoern A. Zeeb# set -v 2360696600cSBjoern A. Zeeb 2370696600cSBjoern A. Zeeb# Figure out our interface and IP. 2380696600cSBjoern A. Zeeb# 2390696600cSBjoern A. Zeebbootp_ifc="" 2400696600cSBjoern A. Zeebbootp_ipa="" 2410696600cSBjoern A. Zeebbootp_ipbca="" 2420696600cSBjoern A. Zeebclass="" 2430696600cSBjoern A. Zeebif [ ${dlv:=0} -ne 0 ] ; then 2440696600cSBjoern A. Zeeb iflist=`ifconfig -l` 2450696600cSBjoern A. Zeeb for i in ${iflist} ; do 2460696600cSBjoern A. Zeeb set -- `ifconfig ${i}` 2470696600cSBjoern A. Zeeb while [ $# -ge 1 ] ; do 2480696600cSBjoern A. Zeeb if [ "${bootp_ifc}" = "" -a "$1" = "inet" ] ; then 2490696600cSBjoern A. Zeeb bootp_ifc=${i} ; bootp_ipa=${2} ; shift 2500696600cSBjoern A. Zeeb fi 2510696600cSBjoern A. Zeeb if [ "${bootp_ipbca}" = "" -a "$1" = "broadcast" ] ; then 2520696600cSBjoern A. Zeeb bootp_ipbca=$2; shift 2530696600cSBjoern A. Zeeb fi 2540696600cSBjoern A. Zeeb shift 2550696600cSBjoern A. Zeeb done 2560696600cSBjoern A. Zeeb if [ "${bootp_ifc}" != "" ] ; then 2570696600cSBjoern A. Zeeb break 2580696600cSBjoern A. Zeeb fi 2590696600cSBjoern A. Zeeb done 2600696600cSBjoern A. Zeeb # Get the values passed with the T134 bootp cookie. 2610696600cSBjoern A. Zeeb class="`/sbin/sysctl -qn kern.bootp_cookie`" 2620696600cSBjoern A. Zeeb 2630696600cSBjoern A. Zeeb echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca} ${class}" 2640696600cSBjoern A. Zeebfi 2650696600cSBjoern A. Zeeb 2660696600cSBjoern A. Zeeblog Figure out our NFS root path 2670696600cSBjoern A. Zeeb# 2680696600cSBjoern A. Zeebset -- `mount -t nfs` 2690696600cSBjoern A. Zeebwhile [ $# -ge 1 ] ; do 2700696600cSBjoern A. Zeeb if [ "$2" = "on" -a "$3" = "/" ]; then 2710696600cSBjoern A. Zeeb nfsroot="$1" 2720696600cSBjoern A. Zeeb break 2730696600cSBjoern A. Zeeb fi 2740696600cSBjoern A. Zeeb shift 2750696600cSBjoern A. Zeebdone 2760696600cSBjoern A. Zeeb 2770696600cSBjoern A. Zeeb# The list of directories with template files 2780696600cSBjoern A. Zeebtemplates="base default" 2790696600cSBjoern A. Zeebif [ -n "${bootp_ipbca}" ]; then 2800696600cSBjoern A. Zeeb templates="${templates} ${bootp_ipbca} bcast/${bootp_ipbca}" 2810696600cSBjoern A. Zeebfi 2820696600cSBjoern A. Zeebif [ -n "${class}" ]; then 2830696600cSBjoern A. Zeeb templates="${templates} ${class}" 2840696600cSBjoern A. Zeebfi 2850696600cSBjoern A. Zeebif [ -n "${bootp_ipa}" ]; then 2860696600cSBjoern A. Zeeb templates="${templates} ${bootp_ipa} ip/${bootp_ipa}" 2870696600cSBjoern A. Zeebfi 2880696600cSBjoern A. Zeeb 2890696600cSBjoern A. Zeeb# If /conf/diskless_remount exists, remount all of /conf. 2900696600cSBjoern A. Zeebhandle_remount /conf 2910696600cSBjoern A. Zeeb 2920696600cSBjoern A. Zeeb# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca}, 2930696600cSBjoern A. Zeeb# and /conf/${bootp_ipa}. For each subdirectory found within these 2940696600cSBjoern A. Zeeb# directories: 2950696600cSBjoern A. Zeeb# 2960696600cSBjoern A. Zeeb# - calculate memory filesystem sizes. If the subdirectory (prior to 2970696600cSBjoern A. Zeeb# NFS remounting) contains the file 'md_size', the contents specified 2980696600cSBjoern A. Zeeb# in 512 byte sectors will be used to size the memory filesystem. Otherwise 2990696600cSBjoern A. Zeeb# 8192 sectors (4MB) is used. 3000696600cSBjoern A. Zeeb# 3010696600cSBjoern A. Zeeb# - handle NFS remounts. If the subdirectory contains the file 3020696600cSBjoern A. Zeeb# diskless_remount, the contents of the file is NFS mounted over 3030696600cSBjoern A. Zeeb# the directory. For example /conf/base/etc/diskless_remount 3040696600cSBjoern A. Zeeb# might contain 'myserver:/etc'. NFS remounts allow you to avoid 3050696600cSBjoern A. Zeeb# having to dup your system directories in /conf. Your server must 3060696600cSBjoern A. Zeeb# be sure to export those filesystems -alldirs, however. 3070696600cSBjoern A. Zeeb# If the diskless_remount file contains a string beginning with a 3080696600cSBjoern A. Zeeb# '/' it is assumed that the local nfsroot should be prepended to 3090696600cSBjoern A. Zeeb# it before attemping to the remount. This allows the root to be 3100696600cSBjoern A. Zeeb# relocated without needing to change the remount files. 3110696600cSBjoern A. Zeeb# 3120696600cSBjoern A. Zeeblog "templates are ${templates}" 3130696600cSBjoern A. Zeebfor i in ${templates} ; do 3140696600cSBjoern A. Zeeb for j in /conf/$i/* ; do 3150696600cSBjoern A. Zeeb [ -d $j ] || continue 3160696600cSBjoern A. Zeeb 3170696600cSBjoern A. Zeeb # memory filesystem size specification 3180696600cSBjoern A. Zeeb subdir=${j##*/} 3190696600cSBjoern A. Zeeb [ -f $j/md_size ] && eval md_size_$subdir=`cat $j/md_size` 3200696600cSBjoern A. Zeeb 3210696600cSBjoern A. Zeeb # remount. Beware, the command is in the file itself! 3220696600cSBjoern A. Zeeb if [ -f $j/remount ]; then 3230696600cSBjoern A. Zeeb if [ -f $j/remount_subdir ]; then 3240696600cSBjoern A. Zeeb k="/conf.tmp/$i/$subdir" 3250696600cSBjoern A. Zeeb [ -d $k ] || continue 3260696600cSBjoern A. Zeeb 3270696600cSBjoern A. Zeeb # Mount the filesystem root where the config data is 3280696600cSBjoern A. Zeeb # on the temporary mount point. 3290696600cSBjoern A. Zeeb nfspt=`/bin/cat $j/remount` 3300696600cSBjoern A. Zeeb $nfspt $k 3310696600cSBjoern A. Zeeb chkerr $? "$nfspt $k" 3320696600cSBjoern A. Zeeb 3330696600cSBjoern A. Zeeb # Now use a nullfs mount to get the data where we 3340696600cSBjoern A. Zeeb # really want to see it. 3350696600cSBjoern A. Zeeb remount_subdir=`/bin/cat $j/remount_subdir` 3360696600cSBjoern A. Zeeb remount_subdir_cmd="mount -t nullfs $k/$remount_subdir" 3370696600cSBjoern A. Zeeb 3380696600cSBjoern A. Zeeb $remount_subdir_cmd $j 3390696600cSBjoern A. Zeeb chkerr $? "$remount_subdir_cmd $j" 3400696600cSBjoern A. Zeeb 3410696600cSBjoern A. Zeeb # XXX check order -- we must force $k to be unmounted 3420696600cSBjoern A. Zeeb # after j, as j depends on k. 3430696600cSBjoern A. Zeeb to_umount="$j $k ${to_umount}" 3440696600cSBjoern A. Zeeb else 3450696600cSBjoern A. Zeeb nfspt=`/bin/cat $j/remount` 3460696600cSBjoern A. Zeeb $nfspt $j 3470696600cSBjoern A. Zeeb chkerr $? "$nfspt $j" 3480696600cSBjoern A. Zeeb to_umount="$j ${to_umount}" # XXX hope it is really a mount! 3490696600cSBjoern A. Zeeb fi 3500696600cSBjoern A. Zeeb fi 3510696600cSBjoern A. Zeeb 3520696600cSBjoern A. Zeeb # NFS remount 3530696600cSBjoern A. Zeeb handle_remount $j 3540696600cSBjoern A. Zeeb done 3550696600cSBjoern A. Zeebdone 3560696600cSBjoern A. Zeeb 3570696600cSBjoern A. Zeeb# - Create all required MFS filesystems and populate them from 3580696600cSBjoern A. Zeeb# our templates. Support both a direct template and a dir.cpio.gz 359b4d24263SEugene Grosbein# archive. Support for auxiliary NVRAM. Support dir.remove files containing 360b4d24263SEugene Grosbein# a list of relative paths to remove. 3610696600cSBjoern A. Zeeb# 3620696600cSBjoern A. Zeeb# The dir.cpio.gz form is there to make the copy process more efficient, 3630696600cSBjoern A. Zeeb# so if the cpio archive is present, it prevents the files from dir/ 3640696600cSBjoern A. Zeeb# from being copied. 3650696600cSBjoern A. Zeeb 3660696600cSBjoern A. Zeebfor i in ${templates} ; do 3670696600cSBjoern A. Zeeb for j in /conf/$i/* ; do 3680696600cSBjoern A. Zeeb subdir=${j##*/} 3690696600cSBjoern A. Zeeb if [ -d $j -a ! -f $j.cpio.gz ]; then 3700696600cSBjoern A. Zeeb create_md $subdir 3710696600cSBjoern A. Zeeb cp -Rp $j/ /$subdir 3720696600cSBjoern A. Zeeb fi 3730696600cSBjoern A. Zeeb done 3740696600cSBjoern A. Zeeb for j in /conf/$i/*.cpio.gz ; do 3750696600cSBjoern A. Zeeb subdir=${j%*.cpio.gz} 3760696600cSBjoern A. Zeeb subdir=${subdir##*/} 3770696600cSBjoern A. Zeeb if [ -f $j ]; then 3780696600cSBjoern A. Zeeb create_md $subdir 3790696600cSBjoern A. Zeeb echo "Loading /$subdir from cpio archive $j" 3800696600cSBjoern A. Zeeb (cd / ; /rescue/tar -xpf $j) 3810696600cSBjoern A. Zeeb fi 3820696600cSBjoern A. Zeeb done 383b4d24263SEugene Grosbein for j in /conf/$i/*/extract ; do 384b4d24263SEugene Grosbein if [ -x $j ]; then 385b4d24263SEugene Grosbein subdir=${j%*/extract} 386b4d24263SEugene Grosbein subdir=${subdir##*/} 387b4d24263SEugene Grosbein create_md $subdir 388b4d24263SEugene Grosbein echo "Loading /$subdir using auxiliary command $j" 389b4d24263SEugene Grosbein $j /$subdir 390b4d24263SEugene Grosbein fi 391b4d24263SEugene Grosbein done 3920696600cSBjoern A. Zeeb for j in /conf/$i/*.remove ; do 3930696600cSBjoern A. Zeeb subdir=${j%*.remove} 3940696600cSBjoern A. Zeeb subdir=${subdir##*/} 3950696600cSBjoern A. Zeeb if [ -f $j ]; then 3960696600cSBjoern A. Zeeb # doubly sure it is a memory disk before rm -rf'ing 3970696600cSBjoern A. Zeeb create_md $subdir 3980696600cSBjoern A. Zeeb (cd /$subdir; rm -rf `/bin/cat $j`) 3990696600cSBjoern A. Zeeb fi 4000696600cSBjoern A. Zeeb done 4010696600cSBjoern A. Zeebdone 4020696600cSBjoern A. Zeeb 4030696600cSBjoern A. Zeeb# umount partitions used to fill the memory filesystems 4040696600cSBjoern A. Zeeb[ -n "${to_umount}" ] && umount $to_umount 405