Home | History | Annotate | Download | only in scripts
      1     0   stevel #!/bin/ksh -p
      2     0   stevel #
      3     0   stevel # CDDL HEADER START
      4     0   stevel #
      5     0   stevel # The contents of this file are subject to the terms of the
      6  2334    setje # Common Development and Distribution License (the "License").
      7  2334    setje # You may not use this file except in compliance with the License.
      8     0   stevel #
      9     0   stevel # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10     0   stevel # or http://www.opensolaris.org/os/licensing.
     11     0   stevel # See the License for the specific language governing permissions
     12     0   stevel # and limitations under the License.
     13     0   stevel #
     14     0   stevel # When distributing Covered Code, include this CDDL HEADER in each
     15     0   stevel # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16     0   stevel # If applicable, add the following below this CDDL HEADER, with the
     17     0   stevel # fields enclosed by brackets "[]" replaced with your own identifying
     18     0   stevel # information: Portions Copyright [yyyy] [name of copyright owner]
     19     0   stevel #
     20     0   stevel # CDDL HEADER END
     21     0   stevel #
     22     0   stevel 
     23  8735   Enrico # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     24     0   stevel # Use is subject to license terms.
     25   174       jg 
     26     0   stevel format=ufs
     27     0   stevel ALT_ROOT=
     28  6319       jg EXTRACT_ARGS=
     29  3446      mrj compress=yes
     30  3446      mrj SPLIT=unknown
     31  3446      mrj ERROR=0
     32  4213   rscott dirsize32=0
     33  4213   rscott dirsize64=0
     34     0   stevel 
     35  6319       jg usage() {
     36  6319       jg 	echo "This utility is a component of the bootadm(1M) implementation"
     37  6319       jg 	echo "and it is not recommended for stand-alone use."
     38  6319       jg 	echo "Please use bootadm(1M) instead."
     39  6319       jg 	echo ""
     40  6319       jg 	echo "Usage: ${0##*/}: [-R \<root\>] [-p \<platform\>] [--nocompress]"
     41  6319       jg 	echo "where \<platform\> is one of i86pc, sun4u or sun4v"
     42  6319       jg 	exit
     43  6319       jg }
     44  6319       jg 
     45  6319       jg # default platform is what we're running on
     46  6319       jg PLATFORM=`uname -m`
     47     0   stevel 
     48  5648    setje #
     49  5648    setje # set path, but inherit /tmp/bfubin if owned by
     50  5648    setje # same uid executing this process, which must be root.
     51  5648    setje #
     52  5648    setje if [ "`echo $PATH | cut -f 1 -d :`" = /tmp/bfubin ] && \
     53  5648    setje     [ -O /tmp/bfubin ] ; then
     54  5734    setje 	export PATH=/tmp/bfubin
     55  5734    setje 	export GZIP_CMD=/tmp/bfubin/gzip
     56  5648    setje else
     57  5648    setje 	export PATH=/usr/sbin:/usr/bin:/sbin
     58  5734    setje 	export GZIP_CMD=/usr/bin/gzip
     59  5648    setje fi
     60  5648    setje 
     61  5648    setje EXTRACT_FILELIST="/boot/solaris/bin/extract_boot_filelist"
     62     0   stevel 
     63     0   stevel #
     64     0   stevel # Parse options
     65     0   stevel #
     66  3446      mrj while [ "$1" != "" ]
     67     0   stevel do
     68  3446      mrj         case $1 in
     69  3446      mrj         -R)	shift
     70  3446      mrj 		ALT_ROOT="$1"
     71     0   stevel 		if [ "$ALT_ROOT" != "/" ]; then
     72  5734    setje 			echo "Creating boot_archive for $ALT_ROOT"
     73  6319       jg 			EXTRACT_ARGS="${EXTRACT_ARGS} -R ${ALT_ROOT}"
     74  5648    setje 			EXTRACT_FILELIST="${ALT_ROOT}${EXTRACT_FILELIST}"
     75     0   stevel 		fi
     76     0   stevel 		;;
     77  3467   rscott 	-n|--nocompress) compress=no
     78  3467   rscott 		;;
     79  6319       jg 	-p)	shift
     80  6319       jg 		PLATFORM="$1"
     81  6319       jg 		EXTRACT_ARGS="${EXTRACT_ARGS} -p ${PLATFORM}"
     82  6319       jg 		;;
     83  6319       jg         *)      usage
     84  3467   rscott 		;;
     85     0   stevel         esac
     86  3446      mrj 	shift
     87     0   stevel done
     88     0   stevel 
     89     0   stevel if [ -x /usr/bin/mkisofs -o -x /tmp/bfubin/mkisofs ] ; then
     90     0   stevel 	format=isofs
     91   621   vikram fi
     92   621   vikram 
     93   621   vikram #
     94   621   vikram # mkisofs on s8 doesn't support functionality used by GRUB boot.
     95   621   vikram # Use ufs format for boot archive instead.
     96   621   vikram #
     97   621   vikram release=`uname -r`
     98   621   vikram if [ "$release" = "5.8" ]; then
     99  3446      mrj 	format=ufs
    100     0   stevel fi
    101     0   stevel 
    102     0   stevel shift `expr $OPTIND - 1`
    103     0   stevel 
    104     0   stevel if [ $# -eq 1 ]; then
    105  2334    setje 	ALT_ROOT="$1"
    106  5734    setje 	echo "Creating boot_archive for $ALT_ROOT"
    107     0   stevel fi
    108     0   stevel 
    109  6319       jg case $PLATFORM in
    110  6319       jg i386)	PLATFORM=i86pc
    111  6319       jg 	ISA=i386
    112  6319       jg 	ARCH64=amd64
    113  6319       jg 	;;
    114  6319       jg i86pc)	ISA=i386
    115  6319       jg 	ARCH64=amd64
    116  6319       jg 	;;
    117  6319       jg sun4u)	ISA=sparc
    118  6319       jg 	ARCH64=sparcv9
    119  6319       jg 	;;
    120  6319       jg sun4v)	ISA=sparc
    121  6319       jg 	ARCH64=sparcv9
    122  6319       jg 	;;
    123  6319       jg *)	usage
    124  6319       jg 	;;
    125  6319       jg esac
    126  6319       jg 
    127  6319       jg BOOT_ARCHIVE=platform/$PLATFORM/boot_archive
    128  6319       jg BOOT_ARCHIVE_64=platform/$PLATFORM/$ARCH64/boot_archive
    129  6319       jg 
    130  6319       jg if [ $PLATFORM = i86pc ] ; then
    131  6638       jg 	if [ ! -x "$ALT_ROOT"/boot/solaris/bin/symdef ]; then
    132  6638       jg 		# no dboot implies combined archives for example
    133  6638       jg 		# live-upgrade from s9 to s10u6 is multiboot-only
    134  5648    setje 		echo "Creating single archive at $ALT_ROOT/$BOOT_ARCHIVE"
    135  5648    setje 		SPLIT=no
    136  5648    setje 		compress=no
    137  6638       jg 	else
    138  5648    setje 		SPLIT=yes
    139  5648    setje 	fi
    140  5648    setje else			# must be sparc
    141  5648    setje 	SPLIT=no	# there's only 64-bit (sparcv9), so don't split
    142  5648    setje 	compress=no	
    143  3446      mrj fi
    144  3446      mrj 
    145  5734    setje [ -x $GZIP_CMD ] || compress=no
    146  3446      mrj 
    147  2334    setje function cleanup
    148  2334    setje {
    149  3446      mrj 	umount -f "$rdmnt32" 2>/dev/null
    150  3446      mrj 	umount -f "$rdmnt64" 2>/dev/null
    151  3446      mrj 	lofiadm -d "$rdfile32" 2>/dev/null
    152  3446      mrj 	lofiadm -d "$rdfile64" 2>/dev/null
    153  4213   rscott 	[ -n "$rddir" ] && rm -fr "$rddir" 2> /dev/null
    154  4213   rscott 	[ -n "$new_rddir" ] && rm -fr "$new_rddir" 2>/dev/null
    155     0   stevel }
    156     0   stevel 
    157  2334    setje function getsize
    158  2334    setje {
    159  4213   rscott 	# Estimate image size and add 10% overhead for ufs stuff.
    160  2511  jongkis 	# Note, we can't use du here in case we're on a filesystem, e.g. zfs,
    161  2511  jongkis 	# in which the disk usage is less than the sum of the file sizes.
    162  2511  jongkis 	# The nawk code 
    163  2511  jongkis 	#
    164  4213   rscott 	#	{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
    165  2511  jongkis 	#
    166  2511  jongkis 	# below rounds up the size of a file/directory, in bytes, to the
    167  2511  jongkis 	# next multiple of 1024.  This mimics the behavior of ufs especially
    168  2511  jongkis 	# with directories.  This results in a total size that's slightly
    169  2511  jongkis 	# bigger than if du was called on a ufs directory.
    170  5648    setje 	size32=$(cat "$list32" | xargs -I {} ls -lLd "{}" 2> /dev/null |
    171  5648    setje 		nawk '{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
    172  4213   rscott 		END {print int(t * 1.10 / 1024)}')
    173  4213   rscott 	(( size32 += dirsize32 ))
    174  5648    setje 	size64=$(cat "$list64" | xargs -I {} ls -lLd "{}" 2> /dev/null |
    175  5648    setje 		nawk '{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
    176  4213   rscott 		END {print int(t * 1.10 / 1024)}')
    177  4213   rscott 	(( size64 += dirsize64 ))
    178  4213   rscott 	(( total_size = size32 + size64 ))
    179  5648    setje 
    180  5648    setje 	if [ $compress = yes ] ; then
    181  5648    setje 		total_size=`echo $total_size | nawk '{print int($1 / 2)}'`
    182  5648    setje 	fi
    183     0   stevel }
    184     0   stevel 
    185  3446      mrj #
    186  4213   rscott # Copies all desired files to a target directory.  One argument should be
    187  4213   rscott # passed: the file containing the list of files to copy.  This function also
    188  4213   rscott # depends on several variables that must be set before calling:
    189  3555   rscott #
    190  3555   rscott # $ALT_ROOT - the target directory
    191  3555   rscott # $compress - whether or not the files in the archives should be compressed
    192  3555   rscott # $rdmnt - the target directory
    193  3555   rscott #
    194  4213   rscott function copy_files
    195  3555   rscott {
    196  4213   rscott 	list="$1"
    197  3555   rscott 
    198  3555   rscott 	#
    199  3555   rscott 	# If compress is set, the files are gzip'd and put in the correct
    200  3555   rscott 	# location in the loop.  Nothing is printed, so the pipe and cpio
    201  3555   rscott 	# at the end is a nop.
    202  3555   rscott 	#
    203  3555   rscott 	# If compress is not set, the file names are printed, which causes
    204  3555   rscott 	# the cpio at the end to do the copy.
    205  3555   rscott 	#
    206  4213   rscott 	while read path
    207  3555   rscott 	do
    208  4213   rscott 		if [ $compress = yes ]; then
    209  4213   rscott 			dir="${path%/*}"
    210  6006   dminer 			[ -d "$rdmnt/$dir" ] || mkdir -p "$rdmnt/$dir"
    211  5734    setje 			$GZIP_CMD -c "$path" > "$rdmnt/$path"
    212  3555   rscott 		else
    213  4213   rscott 			print "$path"
    214  3555   rscott 		fi
    215  4213   rscott 	done <"$list" | cpio -pdum "$rdmnt" 2>/dev/null
    216  5648    setje 
    217  6319       jg 	if [ $ISA = sparc ] ; then
    218  5648    setje 		# copy links
    219  5648    setje 		find $filelist -type l -print 2>/dev/null |\
    220  5648    setje 		    cpio -pdum "$rdmnt" 2>/dev/null
    221  5648    setje 		if [ $compress = yes ] ; then
    222  5648    setje 			# always copy unix uncompressed
    223  5648    setje 			find $filelist -name unix -type f -print 2>/dev/null |\
    224  5648    setje 			    cpio -pdum "$rdmnt" 2>/dev/null
    225  5648    setje 		fi
    226  5648    setje 	fi
    227  5648    setje 
    228  3555   rscott }
    229  3555   rscott 
    230  3555   rscott #
    231  3446      mrj # The first argument can be:
    232  3446      mrj #
    233  3446      mrj # "both" - create an archive with both 32-bit and 64-bit binaries
    234  3446      mrj # "32-bit" - create an archive with only 32-bit binaries
    235  3446      mrj # "64-bit" - create an archive with only 64-bit binaries
    236  3446      mrj #
    237     0   stevel function create_ufs
    238     0   stevel {
    239  3446      mrj 	which=$1
    240  3446      mrj 	archive=$2
    241  3446      mrj 	lofidev=$3
    242  3446      mrj 
    243     0   stevel 	# should we exclude amd64 binaries?
    244  3446      mrj 	if [ "$which" = "32-bit" ]; then
    245  3446      mrj 		rdfile="$rdfile32"
    246  3446      mrj 		rdmnt="$rdmnt32"
    247  4213   rscott 		list="$list32"
    248  3446      mrj 	elif [ "$which" = "64-bit" ]; then
    249  3446      mrj 		rdfile="$rdfile64"
    250  3446      mrj 		rdmnt="$rdmnt64"
    251  4213   rscott 		list="$list64"
    252  3446      mrj 	else
    253  3446      mrj 		rdfile="$rdfile32"
    254  3446      mrj 		rdmnt="$rdmnt32"
    255  4213   rscott 		list="$list32"
    256  3446      mrj 	fi
    257     0   stevel 
    258  2334    setje 	newfs $lofidev < /dev/null 2> /dev/null
    259  2334    setje 	mkdir "$rdmnt"
    260     0   stevel 	mount -F mntfs mnttab /etc/mnttab > /dev/null 2>&1
    261  6942    setje 	mount -F ufs -o nologging $lofidev "$rdmnt"
    262  3446      mrj 	files=
    263     0   stevel 
    264     0   stevel 	# do the actual copy
    265  4213   rscott 	copy_files "$list"
    266  8735   Enrico 	umount -f "$rdmnt"
    267  2334    setje 	rmdir "$rdmnt"
    268  2334    setje 
    269  6319       jg 	if [ $ISA = sparc ] ; then
    270  5648    setje 		rlofidev=`echo "$lofidev" | sed -e "s/dev\/lofi/dev\/rlofi/"`
    271  6319       jg 		bb="$ALT_ROOT/platform/$PLATFORM/lib/fs/ufs/bootblk"
    272  6319       jg 		# installboot is not available on all platforms
    273  6319       jg 		dd if=$bb of=$rlofidev bs=1b oseek=1 count=15 conv=sync 2>&1
    274  5648    setje 	fi
    275  5648    setje 
    276  3446      mrj 	#
    277  2334    setje 	# Check if gzip exists in /usr/bin, so we only try to run gzip
    278  2334    setje 	# on systems that have gzip. Then run gzip out of the patch to
    279  2334    setje 	# pick it up from bfubin or something like that if needed.
    280  2334    setje 	#
    281  3446      mrj 	# If compress is set, the individual files in the archive are
    282  3446      mrj 	# compressed, and the final compression will accomplish very
    283  3446      mrj 	# little.  To save time, we skip the gzip in this case.
    284  3446      mrj 	#
    285  6319       jg 	if [ $ISA = i386 ] && [ $compress = no ] && \
    286  5734    setje 	    [ -x $GZIP_CMD ] ; then
    287  3446      mrj 		gzip -c "$rdfile" > "${archive}-new"
    288  2334    setje 	else
    289  3446      mrj 		cat "$rdfile" > "${archive}-new"
    290  8735   Enrico 	fi
    291  8735   Enrico 	
    292  8735   Enrico 	if [ $? -ne 0 ] ; then
    293  8735   Enrico 		rm -f "${archive}-new"
    294  2334    setje 	fi
    295     0   stevel }
    296     0   stevel 
    297  3446      mrj #
    298  3446      mrj # The first argument can be:
    299  3446      mrj #
    300  3446      mrj # "both" - create an archive with both 32-bit and 64-bit binaries
    301  3446      mrj # "32-bit" - create an archive with only 32-bit binaries
    302  3446      mrj # "64-bit" - create an archive with only 64-bit binaries
    303  3446      mrj #
    304     0   stevel function create_isofs
    305     0   stevel {
    306  3446      mrj 	which=$1
    307  3446      mrj 	archive=$2
    308  3446      mrj 
    309     0   stevel 	# should we exclude amd64 binaries?
    310  3446      mrj 	if [ "$which" = "32-bit" ]; then
    311  3446      mrj 		rdmnt="$rdmnt32"
    312  3446      mrj 		errlog="$errlog32"
    313  4213   rscott 		list="$list32"
    314  3446      mrj 	elif [ "$which" = "64-bit" ]; then
    315  3446      mrj 		rdmnt="$rdmnt64"
    316  3446      mrj 		errlog="$errlog64"
    317  4213   rscott 		list="$list64"
    318  3446      mrj 	else
    319  3446      mrj 		rdmnt="$rdmnt32"
    320  3446      mrj 		errlog="$errlog32"
    321  4213   rscott 		list="$list32"
    322  3446      mrj 	fi
    323     0   stevel 
    324     0   stevel 	# create image directory seed with graft points
    325  2334    setje 	mkdir "$rdmnt"
    326     0   stevel 	files=
    327  3446      mrj 	isocmd="mkisofs -quiet -graft-points -dlrDJN -relaxed-filenames"
    328  3446      mrj 
    329  6319       jg 	if [ $ISA = sparc ] ; then
    330  6319       jg 		bb="$ALT_ROOT/platform/$PLATFORM/lib/fs/hsfs/bootblk"
    331  5648    setje 		isocmd="$isocmd -G \"$bb\""
    332  5648    setje 	fi
    333  5648    setje 
    334  4213   rscott 	copy_files "$list"
    335  2334    setje 	isocmd="$isocmd \"$rdmnt\""
    336  2334    setje 	rm -f "$errlog"
    337  2334    setje 
    338  3446      mrj 	#
    339  2334    setje 	# Check if gzip exists in /usr/bin, so we only try to run gzip
    340  2334    setje 	# on systems that have gzip. Then run gzip out of the patch to
    341  2334    setje 	# pick it up from bfubin or something like that if needed.
    342  2334    setje 	#
    343  3446      mrj 	# If compress is set, the individual files in the archive are
    344  3446      mrj 	# compressed, and the final compression will accomplish very
    345  3446      mrj 	# little.  To save time, we skip the gzip in this case.
    346  3446      mrj 	#
    347  8735   Enrico 	mkiso_ret=0
    348  8735   Enrico 
    349  6319       jg 	if [ $ISA = i386 ] &&[ $compress = no ] && [ -x $GZIP_CMD ]
    350  5648    setje 	then
    351  2334    setje 		ksh -c "$isocmd" 2> "$errlog" | \
    352  3446      mrj 		    gzip > "${archive}-new"
    353  2334    setje 	else
    354  3446      mrj 		ksh -c "$isocmd" 2> "$errlog" > "${archive}-new"
    355  8735   Enrico 	fi
    356  8735   Enrico 
    357  8735   Enrico 	if [ $? -ne 0 ]; then
    358  8735   Enrico 		cat "$errlog"
    359  8735   Enrico 		rm -f "${archive}-new" 2> /dev/null
    360  8735   Enrico 		rm -f "$errlog" 2> /dev/null
    361  8735   Enrico 		return
    362  5648    setje 	fi
    363  5648    setje 
    364  5734    setje 	dd_ret=0
    365  6319       jg 	if [ $ISA = sparc ] ; then
    366  6319       jg 		bb="$ALT_ROOT/platform/$PLATFORM/lib/fs/hsfs/bootblk"
    367  5734    setje 		dd if="$bb" of="${archive}-new" bs=1b oseek=1 count=15 \
    368  5734    setje 		    conv=notrunc conv=sync >> "$errlog" 2>&1
    369  5734    setje 		dd_ret=$?
    370  2334    setje 	fi
    371  2334    setje 
    372  5734    setje 	if [ -s "$errlog" ] || [ $dd_ret -ne 0 ] ; then
    373  2334    setje 		grep Error: "$errlog" >/dev/null 2>&1
    374  5734    setje 		if [ $? -eq 0 ] || [ $dd_ret -ne 0 ] ; then
    375  5734    setje 			cat "$errlog"
    376  3446      mrj 			rm -f "${archive}-new"
    377   174       jg 		fi
    378   174       jg 	fi
    379  2334    setje 	rm -f "$errlog"
    380  3446      mrj }
    381  3446      mrj 
    382  3446      mrj function create_archive
    383  3446      mrj {
    384  3446      mrj 	which=$1
    385  3446      mrj 	archive=$2
    386  3446      mrj 	lofidev=$3
    387  3446      mrj 
    388  5648    setje 	echo "updating $archive"
    389  3446      mrj 
    390  3446      mrj 	if [ "$format" = "ufs" ]; then
    391  3446      mrj 		create_ufs "$which" "$archive" "$lofidev"
    392  3446      mrj 	else
    393  3446      mrj 		create_isofs "$which" "$archive"
    394  3446      mrj 	fi
    395  3446      mrj 
    396  3446      mrj 	# sanity check the archive before moving it into place
    397  3446      mrj 	#
    398  8735   Enrico 	ARCHIVE_SIZE=`ls -l "${archive}-new" 2> /dev/null | nawk '{ print $5 }'`
    399  6319       jg 	if [ $compress = yes ] || [ $ISA = sparc ] ; then
    400  3446      mrj 		#
    401  3446      mrj 		# 'file' will report "English text" for uncompressed
    402  3446      mrj 		# boot_archives.  Checking for that doesn't seem stable,
    403  3446      mrj 		# so we just check that the file exists.
    404  3446      mrj 		#
    405  3446      mrj 		ls "${archive}-new" >/dev/null 2>&1
    406  3446      mrj 	else
    407  3446      mrj 		#
    408  3446      mrj 		# the file type check also establishes that the
    409  3446      mrj 		# file exists at all
    410  3446      mrj 		#
    411  3614    setje 		LC_MESSAGES=C file "${archive}-new" | grep gzip > /dev/null
    412  3446      mrj 	fi
    413  3446      mrj 
    414  8735   Enrico 	if [ $? = 1 ] && [ -x $GZIP_CMD ] || [ "$ARCHIVE_SIZE" -lt 10000 ]
    415  3446      mrj 	then
    416  3446      mrj 		#
    417  3446      mrj 		# Two of these functions may be run in parallel.  We
    418  3446      mrj 		# need to allow the other to clean up, so we can't
    419  3446      mrj 		# exit immediately.  Instead, we set a flag.
    420  3446      mrj 		#
    421  3446      mrj 		echo "update of $archive failed"
    422  3446      mrj 		ERROR=1
    423  3446      mrj 	else
    424  3446      mrj 		lockfs -f "/$ALT_ROOT" 2>/dev/null
    425  3446      mrj 		mv "${archive}-new" "$archive"
    426  3446      mrj 		lockfs -f "/$ALT_ROOT" 2>/dev/null
    427  3446      mrj 	fi
    428  3446      mrj 
    429     0   stevel }
    430     0   stevel 
    431  4213   rscott function fatal_error
    432  4213   rscott {
    433  4213   rscott 	print -u2 $*
    434  4213   rscott 	exit 1
    435  4213   rscott }
    436  4213   rscott 
    437     0   stevel #
    438     0   stevel # get filelist
    439     0   stevel #
    440  3555   rscott if [ ! -f "$ALT_ROOT/boot/solaris/filelist.ramdisk" ] &&
    441  3555   rscott     [ ! -f "$ALT_ROOT/etc/boot/solaris/filelist.ramdisk" ]
    442  2851  jongkis then
    443  2851  jongkis 	print -u2 "Can't find filelist.ramdisk"
    444  2851  jongkis 	exit 1
    445     0   stevel fi
    446  6319       jg filelist=$($EXTRACT_FILELIST $EXTRACT_ARGS \
    447  6319       jg 	/boot/solaris/filelist.ramdisk \
    448  6319       jg 	/etc/boot/solaris/filelist.ramdisk \
    449  6319       jg 		2>/dev/null | sort -u)
    450     0   stevel 
    451  4213   rscott #
    452  4213   rscott # We use /tmp/ for scratch space now.  This may be changed later if there
    453  4213   rscott # is insufficient space in /tmp/.
    454  4213   rscott #
    455  4213   rscott rddir="/tmp/create_ramdisk.$$.tmp"
    456  4213   rscott new_rddir=
    457  4213   rscott rm -rf "$rddir"
    458  4213   rscott mkdir "$rddir" || fatal_error "Could not create temporary directory $rddir"
    459  4213   rscott 
    460  4213   rscott # Clean up upon exit.
    461  4213   rscott trap 'cleanup' EXIT
    462  4213   rscott 
    463  4213   rscott list32="$rddir/filelist.32"
    464  4213   rscott list64="$rddir/filelist.64"
    465  5648    setje 
    466  5648    setje touch $list32 $list64
    467  4213   rscott 
    468  4213   rscott #
    469  4213   rscott # This loop creates the 32-bit and 64-bit lists of files.  The 32-bit list
    470  4213   rscott # is written to stdout, which is redirected at the end of the loop.  The
    471  4213   rscott # 64-bit list is appended with each write.
    472  4213   rscott #
    473  4213   rscott cd "/$ALT_ROOT"
    474  4213   rscott find $filelist -print 2>/dev/null | while read path
    475  4213   rscott do
    476  4213   rscott 	if [ $SPLIT = no ]; then
    477  4213   rscott 		print "$path"
    478  4213   rscott 	elif [ -d "$path" ]; then
    479  4213   rscott 		if [ $format = ufs ]; then
    480  4213   rscott 			size=`ls -lLd "$path" | nawk '
    481  4213   rscott 			    {print ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}'`
    482  4213   rscott 			if [ `basename "$path"` != "amd64" ]; then
    483  4213   rscott 				(( dirsize32 += size ))
    484  4213   rscott 			fi
    485  4213   rscott 			(( dirsize64 += size ))
    486  4213   rscott 		fi
    487  4213   rscott 	else
    488  6006   dminer 		case `LC_MESSAGES=C /usr/bin/file -m /dev/null "$path" 2>/dev/null` in
    489  6006   dminer 		*ELF\ 64-bit*)
    490  4213   rscott 			print "$path" >> "$list64"
    491  6006   dminer 			;;
    492  6006   dminer 		*ELF\ 32-bit*)
    493  4213   rscott 			print "$path"
    494  6006   dminer 			;;
    495  6006   dminer 		*)
    496  4213   rscott 			# put in both lists
    497  4213   rscott 			print "$path"
    498  4213   rscott 			print "$path" >> "$list64"
    499  6006   dminer 		esac
    500  4213   rscott 	fi
    501  4213   rscott done >"$list32"
    502  2334    setje 
    503  2334    setje if [ $format = ufs ] ; then
    504  2334    setje 	# calculate image size
    505  2334    setje 	getsize
    506  3446      mrj 
    507  2334    setje 	# check to see if there is sufficient space in tmpfs 
    508  2334    setje 	#
    509  2334    setje 	tmp_free=`df -b /tmp | tail -1 | awk '{ printf ($2) }'`
    510  7659    Jerry 	(( tmp_free = tmp_free / 3 ))
    511  7659    Jerry 	if [ $SPLIT = yes ]; then
    512  7659    Jerry 		(( tmp_free = tmp_free / 2 ))
    513  7659    Jerry 	fi
    514  2334    setje 
    515  4213   rscott 	if [ $total_size -gt $tmp_free  ] ; then
    516  2334    setje 		# assumes we have enough scratch space on $ALT_ROOT
    517  7659    Jerry 		new_rddir="/$ALT_ROOT/var/tmp/create_ramdisk.$$.tmp"
    518  4213   rscott 		rm -rf "$new_rddir"
    519  4213   rscott 		mkdir "$new_rddir" || fatal_error \
    520  4213   rscott 		    "Could not create temporary directory $new_rddir"
    521  4213   rscott 
    522  4213   rscott 		# Save the file lists
    523  4213   rscott 		mv "$list32" "$new_rddir"/
    524  4213   rscott 		mv "$list64" "$new_rddir"/
    525  4213   rscott 		list32="/$new_rddir/filelist.32"
    526  4213   rscott 		list64="/$new_rddir/filelist.64"
    527  4213   rscott 
    528  4213   rscott 		# Remove the old $rddir and set the new value of rddir
    529  4213   rscott 		rm -rf "$rddir"
    530  4213   rscott 		rddir="$new_rddir"
    531  4213   rscott 		new_rddir=
    532  2334    setje 	fi
    533  2334    setje fi
    534  2334    setje 
    535  3446      mrj rdfile32="$rddir/rd.file.32"
    536  3446      mrj rdfile64="$rddir/rd.file.64"
    537  3446      mrj rdmnt32="$rddir/rd.mount.32"
    538  3446      mrj rdmnt64="$rddir/rd.mount.64"
    539  3446      mrj errlog32="$rddir/rd.errlog.32"
    540  3446      mrj errlog64="$rddir/rd.errlog.64"
    541  3446      mrj lofidev32=""
    542  3446      mrj lofidev64=""
    543  2334    setje 
    544  3446      mrj if [ $SPLIT = yes ]; then
    545  3446      mrj 	#
    546  3446      mrj 	# We can't run lofiadm commands in parallel, so we have to do
    547  3446      mrj 	# them here.
    548  3446      mrj 	#
    549  3446      mrj 	if [ "$format" = "ufs" ]; then
    550  4213   rscott 		mkfile ${size32}k "$rdfile32"
    551  3446      mrj 		lofidev32=`lofiadm -a "$rdfile32"`
    552  4213   rscott 		mkfile ${size64}k "$rdfile64"
    553  3446      mrj 		lofidev64=`lofiadm -a "$rdfile64"`
    554  3446      mrj 	fi
    555  3446      mrj 	create_archive "32-bit" "$ALT_ROOT/$BOOT_ARCHIVE" $lofidev32 &
    556  3446      mrj 	create_archive "64-bit" "$ALT_ROOT/$BOOT_ARCHIVE_64" $lofidev64
    557  3446      mrj 	wait
    558  3446      mrj 	if [ "$format" = "ufs" ]; then
    559  3446      mrj 		lofiadm -d "$rdfile32"
    560  3446      mrj 		lofiadm -d "$rdfile64"
    561  3446      mrj 	fi
    562     0   stevel else
    563  3446      mrj 	if [ "$format" = "ufs" ]; then
    564  3446      mrj 		mkfile ${total_size}k "$rdfile32"
    565  3446      mrj 		lofidev32=`lofiadm -a "$rdfile32"`
    566  3446      mrj 	fi
    567  3446      mrj 	create_archive "both" "$ALT_ROOT/$BOOT_ARCHIVE" $lofidev32
    568  3446      mrj 	[ "$format" = "ufs" ] && lofiadm -d "$rdfile32"
    569     0   stevel fi
    570  3446      mrj if [ $ERROR = 1 ]; then
    571  3446      mrj 	cleanup
    572   174       jg 	exit 1
    573   174       jg fi
    574   174       jg 
    575     0   stevel #
    576     0   stevel # For the diskless case, hardlink archive to /boot to make it
    577     0   stevel # visible via tftp. /boot is lofs mounted under /tftpboot/<hostname>.
    578  3446      mrj # NOTE: this script must work on both client and server.
    579     0   stevel #
    580  2334    setje grep "[	 ]/[	 ]*nfs[	 ]" "$ALT_ROOT/etc/vfstab" > /dev/null
    581     0   stevel if [ $? = 0 ]; then
    582  3446      mrj 	rm -f "$ALT_ROOT/boot/boot_archive" "$ALT_ROOT/boot/amd64/boot_archive"
    583  2334    setje 	ln "$ALT_ROOT/$BOOT_ARCHIVE" "$ALT_ROOT/boot/boot_archive"
    584  6319       jg 	if [ $SPLIT = yes ]; then
    585  6319       jg 		ln "$ALT_ROOT/$BOOT_ARCHIVE_64" \
    586  6319       jg 		    "$ALT_ROOT/boot/amd64/boot_archive"
    587  6319       jg 	fi
    588     0   stevel fi
    589  4213   rscott [ -n "$rddir" ] && rm -rf "$rddir"
    590