rc.initdiskless (126868) | rc.initdiskless (127657) |
---|---|
1#!/bin/sh 2# 3# Copyright (c) 1999 Matt Dillon 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# | 1#!/bin/sh 2# 3# Copyright (c) 1999 Matt Dillon 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# |
27# $FreeBSD: head/etc/rc.initdiskless 126868 2004-03-12 04:40:16Z brooks $ | 27# $FreeBSD: head/etc/rc.initdiskless 127657 2004-03-31 07:24:15Z luigi $ |
28# 29# PROVIDE: initdiskless 30# KEYWORD: FreeBSD nojail 31 32 33# On entry to this script the entire system consists of a read-only root 34# mounted via NFS. We use the contents of /conf to create and populate 35# memory filesystems. The kernel has run BOOTP and configured an interface --- 112 unchanged lines hidden (view full) --- 148 bootp_ipbca=$2; shift 149 fi 150 shift 151 done 152 if [ "${bootp_ifc}" != "" ] ; then 153 break 154 fi 155 done | 28# 29# PROVIDE: initdiskless 30# KEYWORD: FreeBSD nojail 31 32 33# On entry to this script the entire system consists of a read-only root 34# mounted via NFS. We use the contents of /conf to create and populate 35# memory filesystems. The kernel has run BOOTP and configured an interface --- 112 unchanged lines hidden (view full) --- 148 bootp_ipbca=$2; shift 149 fi 150 shift 151 done 152 if [ "${bootp_ifc}" != "" ] ; then 153 break 154 fi 155 done |
156 # Insert the directories passed with the T134 bootp cookie 157 # in the list of paths used for templates. 158 i="`/sbin/sysctl -n kern.bootp_cookie`" 159 [ "${i}" != "" ] && bootp_ipbca="${bootp_ipbca} ${i}" 160 |
|
156 echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}" 157fi 158 159# Figure out our NFS root path 160# 161set `mount -t nfs` 162while [ $# -ge 1 ] ; do 163 if [ "$2" = "on" -a "$3" = "/" ]; then 164 nfsroot="$1" 165 break 166 fi 167 shift 168done 169 | 161 echo "Interface ${bootp_ifc} IP-Address ${bootp_ipa} Broadcast ${bootp_ipbca}" 162fi 163 164# Figure out our NFS root path 165# 166set `mount -t nfs` 167while [ $# -ge 1 ] ; do 168 if [ "$2" = "on" -a "$3" = "/" ]; then 169 nfsroot="$1" 170 break 171 fi 172 shift 173done 174 |
175# The list of directories with template files 176templates="base default ${bootp_ipbca} ${bootp_ipa}" 177 178# The list of filesystems to umount after the copy 179to_umount="" 180 |
|
170# If /conf/diskless_remount exists, remount all of /conf. This allows 171# multiple roots to share the same conf files. 172if [ -d /conf -a -f /conf/diskless_remount ]; then 173 nfspt=`/bin/cat /conf/diskless_remount` 174 if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then 175 nfspt="${nfsroot}${nfspt}" 176 fi 177 mount_nfs $nfspt /conf 178 chkerr $? "mount_nfs $nfspt /conf" | 181# If /conf/diskless_remount exists, remount all of /conf. This allows 182# multiple roots to share the same conf files. 183if [ -d /conf -a -f /conf/diskless_remount ]; then 184 nfspt=`/bin/cat /conf/diskless_remount` 185 if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then 186 nfspt="${nfsroot}${nfspt}" 187 fi 188 mount_nfs $nfspt /conf 189 chkerr $? "mount_nfs $nfspt /conf" |
190 to_umount="/conf" |
|
179fi 180 181# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca}, 182# and /conf/${bootp_ipa}. For each subdirectory found within these 183# directories: 184# 185# - calculate memory filesystem sizes. If the subdirectory (prior to 186# NFS remounting) contains the file 'md_size', the contents specified --- 6 unchanged lines hidden (view full) --- 193# might contain 'myserver:/etc'. NFS remounts allow you to avoid 194# having to dup your system directories in /conf. Your server must 195# be sure to export those filesystems -alldirs, however. 196# If the diskless_remount file contains a string beginning with a 197# '/' it is assumed that the local nfsroot should be prepended to 198# it before attemping to the remount. This allows the root to be 199# relocated without needing to change the remount files. 200# | 191fi 192 193# Resolve templates in /conf/base, /conf/default, /conf/${bootp_ipbca}, 194# and /conf/${bootp_ipa}. For each subdirectory found within these 195# directories: 196# 197# - calculate memory filesystem sizes. If the subdirectory (prior to 198# NFS remounting) contains the file 'md_size', the contents specified --- 6 unchanged lines hidden (view full) --- 205# might contain 'myserver:/etc'. NFS remounts allow you to avoid 206# having to dup your system directories in /conf. Your server must 207# be sure to export those filesystems -alldirs, however. 208# If the diskless_remount file contains a string beginning with a 209# '/' it is assumed that the local nfsroot should be prepended to 210# it before attemping to the remount. This allows the root to be 211# relocated without needing to change the remount files. 212# |
201for i in base default ${bootp_ipbca} ${bootp_ipa} ; do | 213for i in ${templates} ; do |
202 for j in /conf/$i/* ; do 203 # memory filesystem size specification 204 # 205 subdir=${j##*/} 206 if [ -d $j -a -f $j/md_size ]; then 207 eval md_size_$subdir=`cat $j/md_size` 208 fi 209 210 # remount 211 # 212 if [ -d $j -a -f $j/remount ]; then 213 nfspt=`/bin/cat $j/remount` 214 $nfspt $j 215 chkerr $? "$nfspt $j" | 214 for j in /conf/$i/* ; do 215 # memory filesystem size specification 216 # 217 subdir=${j##*/} 218 if [ -d $j -a -f $j/md_size ]; then 219 eval md_size_$subdir=`cat $j/md_size` 220 fi 221 222 # remount 223 # 224 if [ -d $j -a -f $j/remount ]; then 225 nfspt=`/bin/cat $j/remount` 226 $nfspt $j 227 chkerr $? "$nfspt $j" |
228 to_umount="${to_umount} $j" # XXX hope it is really a mount! |
|
216 fi 217 218 # NFS remount 219 # 220 if [ -d $j -a -f $j/diskless_remount ]; then 221 nfspt=`/bin/cat $j/diskless_remount` 222 if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then 223 nfspt="${nfsroot}${nfspt}" 224 fi 225 mount_nfs $nfspt $j 226 chkerr $? "mount_nfs $nfspt $j" | 229 fi 230 231 # NFS remount 232 # 233 if [ -d $j -a -f $j/diskless_remount ]; then 234 nfspt=`/bin/cat $j/diskless_remount` 235 if [ `expr "$nfspt" : '\(.\)'` = "/" ]; then 236 nfspt="${nfsroot}${nfspt}" 237 fi 238 mount_nfs $nfspt $j 239 chkerr $? "mount_nfs $nfspt $j" |
240 to_umount="${to_umount} $j" |
|
227 fi 228 done 229done 230 231# - Create all required MFS filesystems and populate them from 232# our templates. Support both a direct template and a dir.cpio.gz 233# archive. Support dir.remove files containing a list of relative 234# paths to remove. 235# | 241 fi 242 done 243done 244 245# - Create all required MFS filesystems and populate them from 246# our templates. Support both a direct template and a dir.cpio.gz 247# archive. Support dir.remove files containing a list of relative 248# paths to remove. 249# |
236# TODO: 237# + find a way to assign a 'group' identifier to a machine 238# so we can use group-specific configurations; | 250# The dir.cpio.gz form is there to make the copy process more efficient, 251# so if the cpio archive is present, it prevents the files from dir/ 252# from being copied. |
239 | 253 |
240for i in base default ${bootp_ipbca} ${bootp_ipa} ; do | 254for i in ${templates} ; do |
241 for j in /conf/$i/* ; do 242 subdir=${j##*/} | 255 for j in /conf/$i/* ; do 256 subdir=${j##*/} |
243 if [ -d $j ]; then | 257 if [ -d $j -a ! -f $j.cpio.gz ]; then |
244 create_md $subdir 245 cp -Rp $j/* /$subdir 246 fi 247 done 248 for j in /conf/$i/*.cpio.gz ; do 249 subdir=${j%*.cpio.gz} 250 subdir=${subdir##*/} 251 if [ -f $j ]; then --- 8 unchanged lines hidden (view full) --- 260 if [ -f $j ]; then 261 # doubly sure it is a memory disk before rm -rf'ing 262 create_md $subdir 263 (cd /$subdir; rm -rf `/bin/cat $j`) 264 fi 265 done 266done 267 | 258 create_md $subdir 259 cp -Rp $j/* /$subdir 260 fi 261 done 262 for j in /conf/$i/*.cpio.gz ; do 263 subdir=${j%*.cpio.gz} 264 subdir=${subdir##*/} 265 if [ -f $j ]; then --- 8 unchanged lines hidden (view full) --- 274 if [ -f $j ]; then 275 # doubly sure it is a memory disk before rm -rf'ing 276 create_md $subdir 277 (cd /$subdir; rm -rf `/bin/cat $j`) 278 fi 279 done 280done 281 |
282# umount partitions used to fill the memory filesystems 283[ -n "${to_umount}" ] && umount $to_umount |
|