xref: /titanic_52/usr/src/cmd/boot/scripts/create_ramdisk.ksh (revision e1221cd0e8a9005384491e12b63e952499dbe333)
17c478bd9Sstevel@tonic-gate#!/bin/ksh -p
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
658091fd8Ssetje# Common Development and Distribution License (the "License").
758091fd8Ssetje# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate
23eeb2c267SToomas Soome# Copyright 2016 Toomas Soome <tsoome@me.com>
2448847494SEnrico Perla - Sun Microsystems# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
26eeb2c267SToomas Soome#
277c478bd9Sstevel@tonic-gate
28390cfdceSGeorge Wilson#
29390cfdceSGeorge Wilson# Copyright (c) 2014 by Delphix. All rights reserved.
30390cfdceSGeorge Wilson#
31390cfdceSGeorge Wilson
327c478bd9Sstevel@tonic-gateALT_ROOT=
33d876c67dSjgEXTRACT_ARGS=
34ae115bc7Smrjcompress=yes
35ae115bc7SmrjSPLIT=unknown
36ae115bc7SmrjERROR=0
376bb08588Srscottdirsize32=0
386bb08588Srscottdirsize64=0
397c478bd9Sstevel@tonic-gate
40d876c67dSjgusage() {
41d876c67dSjg	echo "This utility is a component of the bootadm(1M) implementation"
42d876c67dSjg	echo "and it is not recommended for stand-alone use."
43d876c67dSjg	echo "Please use bootadm(1M) instead."
44d876c67dSjg	echo ""
45d876c67dSjg	echo "Usage: ${0##*/}: [-R \<root\>] [-p \<platform\>] [--nocompress]"
46d876c67dSjg	echo "where \<platform\> is one of i86pc, sun4u or sun4v"
47d876c67dSjg	exit
48d876c67dSjg}
49d876c67dSjg
50d876c67dSjg# default platform is what we're running on
51d876c67dSjgPLATFORM=`uname -m`
527c478bd9Sstevel@tonic-gate
53986fd29aSsetjeexport PATH=/usr/sbin:/usr/bin:/sbin
5479538500Ssetjeexport GZIP_CMD=/usr/bin/gzip
55986fd29aSsetje
56986fd29aSsetjeEXTRACT_FILELIST="/boot/solaris/bin/extract_boot_filelist"
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate#
597c478bd9Sstevel@tonic-gate# Parse options
607c478bd9Sstevel@tonic-gate#
61ae115bc7Smrjwhile [ "$1" != "" ]
627c478bd9Sstevel@tonic-gatedo
63ae115bc7Smrj        case $1 in
64ae115bc7Smrj        -R)	shift
65ae115bc7Smrj		ALT_ROOT="$1"
667c478bd9Sstevel@tonic-gate		if [ "$ALT_ROOT" != "/" ]; then
6779538500Ssetje			echo "Creating boot_archive for $ALT_ROOT"
68d876c67dSjg			EXTRACT_ARGS="${EXTRACT_ARGS} -R ${ALT_ROOT}"
69986fd29aSsetje			EXTRACT_FILELIST="${ALT_ROOT}${EXTRACT_FILELIST}"
707c478bd9Sstevel@tonic-gate		fi
717c478bd9Sstevel@tonic-gate		;;
720d69385cSrscott	-n|--nocompress) compress=no
730d69385cSrscott		;;
74d876c67dSjg	-p)	shift
75d876c67dSjg		PLATFORM="$1"
76d876c67dSjg		EXTRACT_ARGS="${EXTRACT_ARGS} -p ${PLATFORM}"
77d876c67dSjg		;;
78d876c67dSjg        *)      usage
790d69385cSrscott		;;
807c478bd9Sstevel@tonic-gate        esac
81ae115bc7Smrj	shift
827c478bd9Sstevel@tonic-gatedone
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gateif [ $# -eq 1 ]; then
8758091fd8Ssetje	ALT_ROOT="$1"
8879538500Ssetje	echo "Creating boot_archive for $ALT_ROOT"
897c478bd9Sstevel@tonic-gatefi
907c478bd9Sstevel@tonic-gate
91d876c67dSjgcase $PLATFORM in
92d876c67dSjgi386)	PLATFORM=i86pc
93d876c67dSjg	ISA=i386
94d876c67dSjg	ARCH64=amd64
95d876c67dSjg	;;
96d876c67dSjgi86pc)	ISA=i386
97d876c67dSjg	ARCH64=amd64
98d876c67dSjg	;;
99d876c67dSjgsun4u)	ISA=sparc
100d876c67dSjg	ARCH64=sparcv9
101d876c67dSjg	;;
102d876c67dSjgsun4v)	ISA=sparc
103d876c67dSjg	ARCH64=sparcv9
104d876c67dSjg	;;
105d876c67dSjg*)	usage
106d876c67dSjg	;;
107d876c67dSjgesac
108d876c67dSjg
109d876c67dSjgBOOT_ARCHIVE=platform/$PLATFORM/boot_archive
110d876c67dSjgBOOT_ARCHIVE_64=platform/$PLATFORM/$ARCH64/boot_archive
111d876c67dSjg
112d876c67dSjgif [ $PLATFORM = i86pc ] ; then
113d71f719dSjg	SPLIT=yes
114986fd29aSsetjeelse			# must be sparc
115986fd29aSsetje	SPLIT=no	# there's only 64-bit (sparcv9), so don't split
116986fd29aSsetje	compress=no
117986fd29aSsetjefi
118ae115bc7Smrj
11979538500Ssetje[ -x $GZIP_CMD ] || compress=no
120ae115bc7Smrj
12158091fd8Ssetjefunction cleanup
12258091fd8Ssetje{
123ae115bc7Smrj	umount -f "$rdmnt32" 2>/dev/null
124ae115bc7Smrj	umount -f "$rdmnt64" 2>/dev/null
125ae115bc7Smrj	lofiadm -d "$rdfile32" 2>/dev/null
126ae115bc7Smrj	lofiadm -d "$rdfile64" 2>/dev/null
1276bb08588Srscott	[ -n "$rddir" ] && rm -fr "$rddir" 2> /dev/null
1286bb08588Srscott	[ -n "$new_rddir" ] && rm -fr "$new_rddir" 2>/dev/null
1297c478bd9Sstevel@tonic-gate}
1307c478bd9Sstevel@tonic-gate
13158091fd8Ssetjefunction getsize
13258091fd8Ssetje{
1336bb08588Srscott	# Estimate image size and add 10% overhead for ufs stuff.
1344681df02Sjongkis	# Note, we can't use du here in case we're on a filesystem, e.g. zfs,
1354681df02Sjongkis	# in which the disk usage is less than the sum of the file sizes.
1364681df02Sjongkis	# The nawk code
1374681df02Sjongkis	#
1386bb08588Srscott	#	{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
1394681df02Sjongkis	#
1404681df02Sjongkis	# below rounds up the size of a file/directory, in bytes, to the
1414681df02Sjongkis	# next multiple of 1024.  This mimics the behavior of ufs especially
1424681df02Sjongkis	# with directories.  This results in a total size that's slightly
1434681df02Sjongkis	# bigger than if du was called on a ufs directory.
144986fd29aSsetje	size32=$(cat "$list32" | xargs -I {} ls -lLd "{}" 2> /dev/null |
145986fd29aSsetje		nawk '{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
1464681df02Sjongkis		END {print int(t * 1.10 / 1024)}')
1476bb08588Srscott	(( size32 += dirsize32 ))
148986fd29aSsetje	size64=$(cat "$list64" | xargs -I {} ls -lLd "{}" 2> /dev/null |
149986fd29aSsetje		nawk '{t += ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}
1506bb08588Srscott		END {print int(t * 1.10 / 1024)}')
1516bb08588Srscott	(( size64 += dirsize64 ))
1526bb08588Srscott	(( total_size = size32 + size64 ))
153986fd29aSsetje
154986fd29aSsetje	if [ $compress = yes ] ; then
155986fd29aSsetje		total_size=`echo $total_size | nawk '{print int($1 / 2)}'`
156986fd29aSsetje	fi
1577c478bd9Sstevel@tonic-gate}
1587c478bd9Sstevel@tonic-gate
159ae115bc7Smrj#
1606bb08588Srscott# Copies all desired files to a target directory.  One argument should be
1616bb08588Srscott# passed: the file containing the list of files to copy.  This function also
1626bb08588Srscott# depends on several variables that must be set before calling:
163fe33b55dSrscott#
164fe33b55dSrscott# $ALT_ROOT - the target directory
165fe33b55dSrscott# $compress - whether or not the files in the archives should be compressed
166fe33b55dSrscott# $rdmnt - the target directory
167fe33b55dSrscott#
1686bb08588Srscottfunction copy_files
169fe33b55dSrscott{
1706bb08588Srscott	list="$1"
171fe33b55dSrscott
172fe33b55dSrscott	#
173fe33b55dSrscott	# If compress is set, the files are gzip'd and put in the correct
174fe33b55dSrscott	# location in the loop.  Nothing is printed, so the pipe and cpio
175fe33b55dSrscott	# at the end is a nop.
176fe33b55dSrscott	#
177fe33b55dSrscott	# If compress is not set, the file names are printed, which causes
178fe33b55dSrscott	# the cpio at the end to do the copy.
179fe33b55dSrscott	#
1806bb08588Srscott	while read path
181fe33b55dSrscott	do
182fe33b55dSrscott		if [ $compress = yes ]; then
183fe33b55dSrscott			dir="${path%/*}"
184a916d99cSdminer			[ -d "$rdmnt/$dir" ] || mkdir -p "$rdmnt/$dir"
18579538500Ssetje			$GZIP_CMD -c "$path" > "$rdmnt/$path"
186fe33b55dSrscott		else
187fe33b55dSrscott			print "$path"
188fe33b55dSrscott		fi
1896bb08588Srscott	done <"$list" | cpio -pdum "$rdmnt" 2>/dev/null
190986fd29aSsetje
191d876c67dSjg	if [ $ISA = sparc ] ; then
192986fd29aSsetje		# copy links
193986fd29aSsetje		find $filelist -type l -print 2>/dev/null |\
194986fd29aSsetje		    cpio -pdum "$rdmnt" 2>/dev/null
195986fd29aSsetje		if [ $compress = yes ] ; then
196986fd29aSsetje			# always copy unix uncompressed
197986fd29aSsetje			find $filelist -name unix -type f -print 2>/dev/null |\
198986fd29aSsetje			    cpio -pdum "$rdmnt" 2>/dev/null
199986fd29aSsetje		fi
200986fd29aSsetje	fi
201986fd29aSsetje
202fe33b55dSrscott}
203fe33b55dSrscott
204fe33b55dSrscott#
205ae115bc7Smrj# The first argument can be:
206ae115bc7Smrj#
207ae115bc7Smrj# "both" - create an archive with both 32-bit and 64-bit binaries
208ae115bc7Smrj# "32-bit" - create an archive with only 32-bit binaries
209ae115bc7Smrj# "64-bit" - create an archive with only 64-bit binaries
210ae115bc7Smrj#
2117c478bd9Sstevel@tonic-gatefunction create_ufs
2127c478bd9Sstevel@tonic-gate{
213ae115bc7Smrj	which=$1
214ae115bc7Smrj	archive=$2
215ae115bc7Smrj	lofidev=$3
2167c478bd9Sstevel@tonic-gate
217ae115bc7Smrj	# should we exclude amd64 binaries?
218ae115bc7Smrj	if [ "$which" = "32-bit" ]; then
219ae115bc7Smrj		rdfile="$rdfile32"
220ae115bc7Smrj		rdmnt="$rdmnt32"
2216bb08588Srscott		list="$list32"
222ae115bc7Smrj	elif [ "$which" = "64-bit" ]; then
223ae115bc7Smrj		rdfile="$rdfile64"
224ae115bc7Smrj		rdmnt="$rdmnt64"
2256bb08588Srscott		list="$list64"
226ae115bc7Smrj	else
227ae115bc7Smrj		rdfile="$rdfile32"
228ae115bc7Smrj		rdmnt="$rdmnt32"
2296bb08588Srscott		list="$list32"
230ae115bc7Smrj	fi
231ae115bc7Smrj
232390cfdceSGeorge Wilson	NOINUSE_CHECK=1 newfs $lofidev < /dev/null 2> /dev/null
23358091fd8Ssetje	mkdir "$rdmnt"
2347c478bd9Sstevel@tonic-gate	mount -F mntfs mnttab /etc/mnttab > /dev/null 2>&1
2357ce430bdSsetje	mount -F ufs -o nologging $lofidev "$rdmnt"
236ae115bc7Smrj	files=
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate	# do the actual copy
2396bb08588Srscott	copy_files "$list"
24048847494SEnrico Perla - Sun Microsystems	umount -f "$rdmnt"
24158091fd8Ssetje	rmdir "$rdmnt"
24258091fd8Ssetje
243d876c67dSjg	if [ $ISA = sparc ] ; then
244986fd29aSsetje		rlofidev=`echo "$lofidev" | sed -e "s/dev\/lofi/dev\/rlofi/"`
245d876c67dSjg		bb="$ALT_ROOT/platform/$PLATFORM/lib/fs/ufs/bootblk"
246d876c67dSjg		# installboot is not available on all platforms
247d876c67dSjg		dd if=$bb of=$rlofidev bs=1b oseek=1 count=15 conv=sync 2>&1
248986fd29aSsetje	fi
249986fd29aSsetje
250ae115bc7Smrj	#
25158091fd8Ssetje	# Check if gzip exists in /usr/bin, so we only try to run gzip
25258091fd8Ssetje	# on systems that have gzip. Then run gzip out of the patch to
25358091fd8Ssetje	# pick it up from bfubin or something like that if needed.
25458091fd8Ssetje	#
255ae115bc7Smrj	# If compress is set, the individual files in the archive are
256ae115bc7Smrj	# compressed, and the final compression will accomplish very
257ae115bc7Smrj	# little.  To save time, we skip the gzip in this case.
258ae115bc7Smrj	#
259d876c67dSjg	if [ $ISA = i386 ] && [ $compress = no ] && \
26079538500Ssetje	    [ -x $GZIP_CMD ] ; then
261ae115bc7Smrj		gzip -c "$rdfile" > "${archive}-new"
26258091fd8Ssetje	else
263ae115bc7Smrj		cat "$rdfile" > "${archive}-new"
26458091fd8Ssetje	fi
26548847494SEnrico Perla - Sun Microsystems
26648847494SEnrico Perla - Sun Microsystems	if [ $? -ne 0 ] ; then
26748847494SEnrico Perla - Sun Microsystems		rm -f "${archive}-new"
26848847494SEnrico Perla - Sun Microsystems	fi
2697c478bd9Sstevel@tonic-gate}
2707c478bd9Sstevel@tonic-gate
271ae115bc7Smrjfunction create_archive
272ae115bc7Smrj{
273ae115bc7Smrj	which=$1
274ae115bc7Smrj	archive=$2
275ae115bc7Smrj	lofidev=$3
276ae115bc7Smrj
277986fd29aSsetje	echo "updating $archive"
278ae115bc7Smrj
279ae115bc7Smrj	create_ufs "$which" "$archive" "$lofidev"
280ae115bc7Smrj
281ae115bc7Smrj	# sanity check the archive before moving it into place
282ae115bc7Smrj	#
28348847494SEnrico Perla - Sun Microsystems	ARCHIVE_SIZE=`ls -l "${archive}-new" 2> /dev/null | nawk '{ print $5 }'`
284d876c67dSjg	if [ $compress = yes ] || [ $ISA = sparc ] ; then
285ae115bc7Smrj		#
286ae115bc7Smrj		# 'file' will report "English text" for uncompressed
287ae115bc7Smrj		# boot_archives.  Checking for that doesn't seem stable,
288ae115bc7Smrj		# so we just check that the file exists.
289ae115bc7Smrj		#
290ae115bc7Smrj		ls "${archive}-new" >/dev/null 2>&1
291ae115bc7Smrj	else
292ae115bc7Smrj		#
293ae115bc7Smrj		# the file type check also establishes that the
294ae115bc7Smrj		# file exists at all
295ae115bc7Smrj		#
296ece420edSsetje		LC_MESSAGES=C file "${archive}-new" | grep gzip > /dev/null
297ae115bc7Smrj	fi
298ae115bc7Smrj
29948847494SEnrico Perla - Sun Microsystems	if [ $? = 1 ] && [ -x $GZIP_CMD ] || [ "$ARCHIVE_SIZE" -lt 10000 ]
300ae115bc7Smrj	then
301ae115bc7Smrj		#
302ae115bc7Smrj		# Two of these functions may be run in parallel.  We
303ae115bc7Smrj		# need to allow the other to clean up, so we can't
304ae115bc7Smrj		# exit immediately.  Instead, we set a flag.
305ae115bc7Smrj		#
306ae115bc7Smrj		echo "update of $archive failed"
307ae115bc7Smrj		ERROR=1
308ae115bc7Smrj	else
309ae115bc7Smrj		lockfs -f "/$ALT_ROOT" 2>/dev/null
310ae115bc7Smrj		mv "${archive}-new" "$archive"
311eeb2c267SToomas Soome		rm -f "$archive.hash"
312eeb2c267SToomas Soome		digest -a sha1 "$archive" > "$archive.hash"
313ae115bc7Smrj		lockfs -f "/$ALT_ROOT" 2>/dev/null
314ae115bc7Smrj	fi
315ae115bc7Smrj
316ae115bc7Smrj}
317ae115bc7Smrj
3186bb08588Srscottfunction fatal_error
3196bb08588Srscott{
3206bb08588Srscott	print -u2 $*
3216bb08588Srscott	exit 1
3226bb08588Srscott}
3236bb08588Srscott
3247c478bd9Sstevel@tonic-gate#
3257c478bd9Sstevel@tonic-gate# get filelist
3267c478bd9Sstevel@tonic-gate#
327fe33b55dSrscottif [ ! -f "$ALT_ROOT/boot/solaris/filelist.ramdisk" ] &&
328fe33b55dSrscott    [ ! -f "$ALT_ROOT/etc/boot/solaris/filelist.ramdisk" ]
329e482cb0aSjongkisthen
330e482cb0aSjongkis	print -u2 "Can't find filelist.ramdisk"
331e482cb0aSjongkis	exit 1
3327c478bd9Sstevel@tonic-gatefi
333d876c67dSjgfilelist=$($EXTRACT_FILELIST $EXTRACT_ARGS \
334d876c67dSjg	/boot/solaris/filelist.ramdisk \
335d876c67dSjg	/etc/boot/solaris/filelist.ramdisk \
336d876c67dSjg		2>/dev/null | sort -u)
3377c478bd9Sstevel@tonic-gate
3386bb08588Srscott#
3396bb08588Srscott# We use /tmp/ for scratch space now.  This may be changed later if there
3406bb08588Srscott# is insufficient space in /tmp/.
3416bb08588Srscott#
3426bb08588Srscottrddir="/tmp/create_ramdisk.$$.tmp"
3436bb08588Srscottnew_rddir=
3446bb08588Srscottrm -rf "$rddir"
3456bb08588Srscottmkdir "$rddir" || fatal_error "Could not create temporary directory $rddir"
3466bb08588Srscott
3476bb08588Srscott# Clean up upon exit.
3486bb08588Srscotttrap 'cleanup' EXIT
3496bb08588Srscott
3506bb08588Srscottlist32="$rddir/filelist.32"
3516bb08588Srscottlist64="$rddir/filelist.64"
3526bb08588Srscott
353986fd29aSsetjetouch $list32 $list64
354986fd29aSsetje
3556bb08588Srscott#
3566bb08588Srscott# This loop creates the 32-bit and 64-bit lists of files.  The 32-bit list
3576bb08588Srscott# is written to stdout, which is redirected at the end of the loop.  The
3586bb08588Srscott# 64-bit list is appended with each write.
3596bb08588Srscott#
3606bb08588Srscottcd "/$ALT_ROOT"
3616bb08588Srscottfind $filelist -print 2>/dev/null | while read path
3626bb08588Srscottdo
3636bb08588Srscott	if [ $SPLIT = no ]; then
3646bb08588Srscott		print "$path"
3656bb08588Srscott	elif [ -d "$path" ]; then
3666bb08588Srscott		size=`ls -lLd "$path" | nawk '
3676bb08588Srscott		    {print ($5 % 1024) ? (int($5 / 1024) + 1) * 1024 : $5}'`
3686bb08588Srscott		if [ `basename "$path"` != "amd64" ]; then
3696bb08588Srscott			(( dirsize32 += size ))
3706bb08588Srscott		fi
3716bb08588Srscott		(( dirsize64 += size ))
3726bb08588Srscott	else
373a916d99cSdminer		case `LC_MESSAGES=C /usr/bin/file -m /dev/null "$path" 2>/dev/null` in
374a916d99cSdminer		*ELF\ 64-bit*)
3756bb08588Srscott			print "$path" >> "$list64"
376a916d99cSdminer			;;
377a916d99cSdminer		*ELF\ 32-bit*)
3786bb08588Srscott			print "$path"
379a916d99cSdminer			;;
380a916d99cSdminer		*)
3816bb08588Srscott			# put in both lists
3826bb08588Srscott			print "$path"
3836bb08588Srscott			print "$path" >> "$list64"
384a916d99cSdminer		esac
3856bb08588Srscott	fi
3866bb08588Srscottdone >"$list32"
38758091fd8Ssetje
38858091fd8Ssetje# calculate image size
38958091fd8Ssetjegetsize
39058091fd8Ssetje
39158091fd8Ssetje# check to see if there is sufficient space in tmpfs
39258091fd8Ssetje#
39358091fd8Ssetjetmp_free=`df -b /tmp | tail -1 | awk '{ printf ($2) }'`
3947740ff5fSJerry Gilliam(( tmp_free = tmp_free / 3 ))
3957740ff5fSJerry Gilliamif [ $SPLIT = yes ]; then
39658091fd8Ssetje	(( tmp_free = tmp_free / 2 ))
3977740ff5fSJerry Gilliamfi
39858091fd8Ssetje
3996bb08588Srscottif [ $total_size -gt $tmp_free  ] ; then
40058091fd8Ssetje	# assumes we have enough scratch space on $ALT_ROOT
4017740ff5fSJerry Gilliam	new_rddir="/$ALT_ROOT/var/tmp/create_ramdisk.$$.tmp"
4026bb08588Srscott	rm -rf "$new_rddir"
4036bb08588Srscott	mkdir "$new_rddir" || fatal_error \
4046bb08588Srscott	    "Could not create temporary directory $new_rddir"
4056bb08588Srscott
4066bb08588Srscott	# Save the file lists
4076bb08588Srscott	mv "$list32" "$new_rddir"/
4086bb08588Srscott	mv "$list64" "$new_rddir"/
4096bb08588Srscott	list32="/$new_rddir/filelist.32"
4106bb08588Srscott	list64="/$new_rddir/filelist.64"
4116bb08588Srscott
4126bb08588Srscott	# Remove the old $rddir and set the new value of rddir
4136bb08588Srscott	rm -rf "$rddir"
4146bb08588Srscott	rddir="$new_rddir"
4156bb08588Srscott	new_rddir=
41658091fd8Ssetjefi
41758091fd8Ssetje
418ae115bc7Smrjrdfile32="$rddir/rd.file.32"
419ae115bc7Smrjrdfile64="$rddir/rd.file.64"
420ae115bc7Smrjrdmnt32="$rddir/rd.mount.32"
421ae115bc7Smrjrdmnt64="$rddir/rd.mount.64"
422ae115bc7Smrjerrlog32="$rddir/rd.errlog.32"
423ae115bc7Smrjerrlog64="$rddir/rd.errlog.64"
424ae115bc7Smrjlofidev32=""
425ae115bc7Smrjlofidev64=""
42658091fd8Ssetje
427ae115bc7Smrjif [ $SPLIT = yes ]; then
42858091fd8Ssetje	#
429ae115bc7Smrj	# We can't run lofiadm commands in parallel, so we have to do
430ae115bc7Smrj	# them here.
431ae115bc7Smrj	#
4326bb08588Srscott	mkfile ${size32}k "$rdfile32"
433ae115bc7Smrj	lofidev32=`lofiadm -a "$rdfile32"`
4346bb08588Srscott	mkfile ${size64}k "$rdfile64"
435ae115bc7Smrj	lofidev64=`lofiadm -a "$rdfile64"`
436ae115bc7Smrj	create_archive "32-bit" "$ALT_ROOT/$BOOT_ARCHIVE" $lofidev32 &
437ae115bc7Smrj	create_archive "64-bit" "$ALT_ROOT/$BOOT_ARCHIVE_64" $lofidev64
438ae115bc7Smrj	wait
439ae115bc7Smrj	lofiadm -d "$rdfile32"
440ae115bc7Smrj	lofiadm -d "$rdfile64"
441ae115bc7Smrjelse
442ae115bc7Smrj	mkfile ${total_size}k "$rdfile32"
443ae115bc7Smrj	lofidev32=`lofiadm -a "$rdfile32"`
444ae115bc7Smrj	create_archive "both" "$ALT_ROOT/$BOOT_ARCHIVE" $lofidev32
445*e1221cd0SToomas Soome	lofiadm -d "$rdfile32"
446ae115bc7Smrjfi
447ae115bc7Smrjif [ $ERROR = 1 ]; then
448ae115bc7Smrj	cleanup
449847671deSjg	exit 1
450847671deSjgfi
451847671deSjg
4527c478bd9Sstevel@tonic-gate#
4537c478bd9Sstevel@tonic-gate# For the diskless case, hardlink archive to /boot to make it
4547c478bd9Sstevel@tonic-gate# visible via tftp. /boot is lofs mounted under /tftpboot/<hostname>.
455ae115bc7Smrj# NOTE: this script must work on both client and server.
4567c478bd9Sstevel@tonic-gate#
45758091fd8Ssetjegrep "[	 ]/[	 ]*nfs[	 ]" "$ALT_ROOT/etc/vfstab" > /dev/null
4587c478bd9Sstevel@tonic-gateif [ $? = 0 ]; then
459ae115bc7Smrj	rm -f "$ALT_ROOT/boot/boot_archive" "$ALT_ROOT/boot/amd64/boot_archive"
46058091fd8Ssetje	ln "$ALT_ROOT/$BOOT_ARCHIVE" "$ALT_ROOT/boot/boot_archive"
461d876c67dSjg	if [ $SPLIT = yes ]; then
462d876c67dSjg		ln "$ALT_ROOT/$BOOT_ARCHIVE_64" \
463d876c67dSjg		    "$ALT_ROOT/boot/amd64/boot_archive"
464d876c67dSjg	fi
4657c478bd9Sstevel@tonic-gatefi
4666bb08588Srscott[ -n "$rddir" ] && rm -rf "$rddir"
467