xref: /illumos-gate/usr/src/cmd/boot/scripts/root_archive.ksh (revision 437220cd296f6d8b6654d6d52508b40b1e2d1ac7)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27
28# utility to pack and unpack a boot/root archive
29# both ufs and hsfs (iso9660) format archives are unpacked
30# only ufs archives are generated
31#
32# usage: pack   <archive> <root>
33#        unpack <archive> <root>
34#        packmedia   <solaris_image> <root>
35#        unpackmedia <solaris_image> <root>
36#
37#   Where <root> is the directory to unpack to and will be cleaned out
38#   if it exists.
39#
40#   In the case of (un)packmedia, the image is packed or unpacked to/from
41#   Solaris media and all the things that don't go into the ramdisk image
42#   are (un)cpio'd as well
43#
44# This utility is also used to pack parts (in essence the window system,
45# usr/dt and usr/openwin) of the non ramdisk SPARC
46# miniroot. (un)packmedia will recognize that they are being run a SPARC
47# miniroot and do the appropriate work.
48#
49
50usage()
51{
52	printf "usage: root_archive pack <archive> <root>\n"
53	printf "       root_archive unpack <archive> <root>\n"
54	printf "       root_archive packmedia   <solaris_image> <root>\n"
55	printf "       root_archive unpackmedia <solaris_image> <root>\n"
56}
57
58cleanup()
59{
60	if [ -d $MNT ] ; then
61		umount $MNT 2> /dev/null
62		rmdir $MNT
63	fi
64
65	lofiadm -d "$TMR" 2>/dev/null
66	rm -f "$TMR" "$TMR.gz"
67}
68
69archive_Gnome()
70{
71	MEDIA="$1"
72	MINIROOT="$2"
73
74	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
75	RELEASE=`basename "$RELEASE"`
76
77	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
78		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
79		mkdir -p "$CPIO_DIR"
80	else
81		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
82	fi
83
84
85	# Create the gnome archive
86	#
87	(
88		# Prepopulate the gconf database. This needs to be done and
89		# done first for several reasons. 1) Archiving out the gnome
90		# libraries and binaries causes the gconftool-2 to not run
91		# appropriately at boot time. 2) The binaries and libraries
92		# needed to run this are big and thus we want to archive
93		# them separately. 3) Having schemas prepopluated in the
94		# miniroot means faster boot times.
95		#
96
97		cd "$MINIROOT"
98		HOME="./tmp/root"
99		export HOME
100		umask 0022
101		GCONF_CONFIG_SOURCE="xml:merged:"$MINIROOT"/.tmp_proto/root/etc/gconf/gconf.xml.defaults"
102		export GCONF_CONFIG_SOURCE
103		SCHEMADIR="$MINIROOT/.tmp_proto/root/etc/gconf/schemas"
104		export SCHEMADIR
105		/usr/bin/gconftool-2 --makefile-install-rule $SCHEMADIR/*.schemas >/dev/null 2>&1
106		# usr/share gnome stuff
107		cd "$MINIROOT"
108		find usr/share/GConf usr/share/application-registry \
109		    usr/share/autostart usr/share/dbus-1 usr/share/dtds \
110		    usr/share/emacs usr/share/gnome usr/share/gnome-2.0 \
111		    usr/share/gnome-background-properties \
112		    usr/share/gtk-engines usr/share/gui-install \
113		    usr/share/icon-naming-utils usr/share/control-center \
114		    usr/share/icons usr/share/locale usr/share/metacity \
115		    usr/share/mime usr/share/mime-info usr/share/pixmaps \
116		    usr/share/scrollkeeper usr/share/sgml usr/share/themes \
117		    usr/share/xml \
118		    -print > /tmp/gnome_share.$$ 2>/dev/null
119
120		if [ ! -f /tmp/gnome_share.$$ ] ; then
121			echo "/tmp/gnome_share.$$ file list not found."
122			return
123		fi
124
125		# usr/lib gnome stuff
126
127		find usr/lib/libgnome*\.so\.* \
128		    usr/lib/libgst*\.so\.* usr/lib/libgconf*\.so\.* \
129		    usr/lib/libgdk*\.so\.* usr/lib/libgtk*\.so\.* \
130		    usr/lib/libglade*\.so\.* usr/lib/libmetacity*\.so\.* \
131		    usr/lib/libfontconfig*\.so\.* usr/lib/libgmodule*\.so\.* \
132		    usr/lib/libgobject*\.so\.* usr/lib/libgthread*\.so\.* \
133		    usr/lib/libpopt*\.so\.* usr/lib/libstartup*\.so\.* \
134		    usr/lib/libexif*\.so\.* usr/lib/libtiff*\.so\.* \
135		    usr/lib/libdbus*\.so\.* usr/lib/libstartup*\.so\.* \
136		    usr/lib/libexif*\.so\.* usr/lib/libORBit*\.so\.* \
137	 	    usr/lib/libmlib*\.so\.* usr/lib/libxsl*\.so\.* \
138		    usr/lib/libpango*\.so\.* usr/lib/libpng*\.so\.* \
139		    usr/lib/liboil*\.so\.* usr/lib/libbonobo*\.so\.* \
140		    usr/lib/libart*\.so\.* usr/lib/libcairo*\.so\.* \
141		    usr/lib/libjpeg*\.so\.* \
142		    usr/lib/libpolkit*\.so\.* \
143			-print | egrep -v '\.so\.[0]$' > \
144		       /tmp/gnome_lib.$$ 2>/dev/null
145
146		find usr/lib/nautilus usr/lib/pango usr/lib/iconv \
147		    usr/lib/metacity-dialog usr/lib/window-manager-settings \
148		    usr/lib/bonobo-2.0 usr/lib/bononbo usr/lib/gtk-2.0 \
149		    usr/lib/GConf usr/lib/bonobo-activation-server \
150		    usr/lib/python2.4 usr/lib/gstreamer-0.10 \
151		    usr/lib/gconf-sanity-check-2 usr/lib/gconfd \
152		    usr/lib/gnome-vfs-2.0 usr/lib/dbus-daemon \
153		    usr/lib/gnome-vfs-daemon usr/lib/gnome-settings-daemon \
154		    usr/lib/gnome_segv2 usr/lib/orbit-2.0 \
155		    usr/lib/libmlib \
156		    print > /tmp/gnome_libdir.$$ 2>/dev/null
157
158		if [ ! -f /tmp/gnome_lib.$$  -a ! -f gnome_libdir.$$ ] ; then
159			echo "/tmp/gnome_lib.$$ file list not found."
160			return
161		fi
162
163		# /usr/sfw gnome stuff
164		find usr/sfw/bin usr/sfw/include usr/sfw/share usr/sfw/src \
165		    -print > /tmp/gnome_sfw.$$ 2>/dev/null
166
167		if [ ! -f /tmp/gnome_sfw.$$ ] ; then
168			echo "/tmp/gnome_sfw.$$ file list not found."
169			return
170		fi
171
172		# gnome app binaries usr/bin
173		find usr/bin/gnome* usr/bin/gui-install usr/bin/bonobo* \
174		    usr/bin/gtk-* usr/bin/fax* usr/bin/gdk* usr/bin/gif2tiff \
175		    usr/bin/install-lan \
176		    usr/bin/metacity* usr/bin/gst-* usr/bin/gconftool-2 \
177		    usr/bin/pango* usr/bin/desktop* usr/bin/djpeg \
178		    usr/bin/notify-send usr/bin/oil-bugreport \
179		    usr/bin/bmp2tiff usr/bin/thembus-theme-applier \
180		    usr/bin/thumbnail usr/lib/update-* \
181		    usr/bin/ras2tiff usr/bin/raw2tiff usr/bin/rdjpgcom \
182		    usr/bin/thumbnail usr/bin/dbus* \
183		    usr/bin/tiff* usr/bin/rgb2ycbcr \
184		    usr/bin/fc-cache usr/bin/fc-list \
185			-print > /tmp/gnome_bin.$$ 2>/dev/null
186
187		if [ ! -f /tmp/gnome_bin.$$ ] ; then
188			echo "/tmp/gnome_bin.$$ file list not found."
189			return
190		fi
191
192		# Cat all the files together and create the gnome archive
193		#
194
195		cat /tmp/gnome_libdir.$$ /tmp/gnome_lib.$$ \
196		     /tmp/gnome_share.$$ /tmp/gnome_sfw.$$ /tmp/gnome_bin.$$ \
197		    > /tmp/gnome.$$
198
199		if [ ! -f /tmp/gnome.$$ ] ; then
200			echo "/tmp/gnome.$$ file not found."
201			return
202		fi
203		# Save off this file in the miniroot for use later
204		# when unpacking. Clean up old cruft if there.
205		#
206
207		if [ -f .tmp_proto/gnome_saved ]; then
208			rm -f .tmp_proto/gnome_saved
209		fi
210
211		cp /tmp/gnome.$$ .tmp_proto/gnome_saved
212
213		# Create gnome archive
214		#
215
216		cpio -ocmPuB < /tmp/gnome.$$ 2>/dev/null | bzip2 > \
217		    "$CPIO_DIR/gnome.cpio.bz2"
218
219		# Remove files from miniroot that are in archive.
220		# Create symlinks for files in archive
221
222		rm -rf `cat /tmp/gnome_share.$$`
223
224		for i in `cat /tmp/gnome_share.$$`
225		do
226			ln -s /tmp/root/$i $i 2>/dev/null
227		done
228
229		rm -rf `cat /tmp/gnome_lib.$$`
230		for i in `cat /tmp/gnome_lib.$$`
231		do
232			ln -s /tmp/root/$i $i 2>/dev/null
233		done
234
235		rm -rf `cat /tmp/gnome_libdir.$$`
236		for i in `cat /tmp/gnome_libdir.$$`
237		do
238			ln -s /tmp/root/$i $i 2>/dev/null
239		done
240
241		rm -rf `cat /tmp/gnome_sfw.$$`
242		for i in `cat /tmp/gnome_sfw.$$`
243		do
244			ln -s /tmp/root/$i $i 2>/dev/null
245		done
246
247		rm -rf `cat /tmp/gnome_bin.$$`
248		for i in `cat /tmp/gnome_bin.$$`
249		do
250			ln -s /tmp/root/$i $i 2>/dev/null
251		done
252		rm -f /tmp/gnome_share.$$
253		rm -f /tmp/gnome_lib.$$
254		rm -f /tmp/gnome_libdir.$$
255		rm -f /tmp/gnome_bin.$$
256	)
257}
258
259archive_JavaGUI()
260{
261	MEDIA="$1"
262	MINIROOT="$2"
263
264	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
265	RELEASE=`basename "$RELEASE"`
266
267	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
268		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
269		mkdir -p "$CPIO_DIR"
270	else
271		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
272	fi
273
274	# Archive the java wizard components that are only used in the
275	# non developer express path.
276	#
277	(
278		# path is usr/lib/install/data
279		cd "$MINIROOT"
280		find usr/lib/install/data/wizards \
281		    -print > /tmp/java_ui.$$ 2>/dev/null
282
283		if [ ! -f /tmp/java_ui.$$ ] ; then
284			echo "/tmp/java_ui.$$ file list not found."
285			return
286		fi
287
288		cpio -ocmPuB < /tmp/java_ui.$$ 2>/dev/null | bzip2 > \
289		    "$CPIO_DIR/javaui.cpio.bz2"
290
291		rm -rf `cat /tmp/java_ui.$$`
292		ln -s /tmp/root/usr/lib/install/data/wizards usr/lib/install/data/wizards 2>/dev/null
293
294		rm -f /tmp/java_ui.$$
295
296	)
297}
298
299archive_Misc()
300{
301	MEDIA="$1"
302	MINIROOT="$2"
303
304	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
305	RELEASE=`basename "$RELEASE"`
306
307	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
308		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
309		mkdir -p "$CPIO_DIR"
310	else
311		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
312	fi
313
314	# Archive misc stuff that is needed by non devex installer
315	#
316	(
317		# usr/lib stuff
318		cd "$MINIROOT"
319		find usr/lib/lp -print > /tmp/lp.$$ 2>/dev/null
320		if [ ! -f /tmp/lp.$$ ] ; then
321			echo "/tmp/lp.$$ file list not found."
322			return
323		fi
324
325		cpio -ocmPuB < /tmp/lp.$$ 2>/dev/null | bzip2 > \
326		    "$CPIO_DIR/lpmisc.cpio.bz2"
327
328		rm -rf `cat /tmp/lp.$$`
329		ln -s /tmp/root/usr/lib/lp usr/lib/lp 2>/dev/null
330
331		rm -f /tmp/lp.$$
332	)
333
334}
335
336archive_Perl()
337{
338	MEDIA="$1"
339	MINIROOT="$2"
340
341	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
342	RELEASE=`basename "$RELEASE"`
343
344	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
345		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
346		mkdir -p "$CPIO_DIR"
347	else
348		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
349	fi
350
351	# Archive perl, it is only needed by gnome gui.
352	#
353	(
354		# in usr
355		cd "$MINIROOT"
356		find usr/perl5 -print > /tmp/perl.$$ 2>/dev/null
357
358		if [ ! -f /tmp/perl.$$ ] ; then
359			echo "/tmp/perl.$$ file list not found."
360			return
361		fi
362		cpio -ocmPuB < /tmp/perl.$$ 2>/dev/null | bzip2 > \
363		    "$CPIO_DIR/perl.cpio.bz2"
364
365		rm -rf `cat /tmp/perl.$$` 2>/dev/null
366		ln -s /tmp/root/perl5 usr/perl5 2>/dev/null
367
368		rm -f /tmp/perl.$$
369	)
370}
371archive_X()
372{
373	MEDIA="$1"
374	MINIROOT="$2"
375
376	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
377	RELEASE=`basename "$RELEASE"`
378
379	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
380		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
381		mkdir -p "$CPIO_DIR"
382	else
383		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
384	fi
385
386	# create the graphics and non-graphics X archive
387	#
388	(
389		cd "$MINIROOT"
390		find usr/openwin usr/dt usr/X11 -print 2> /dev/null |\
391		    cpio -ocmPuB 2> /dev/null | bzip2 > "$CPIO_DIR/X.cpio.bz2"
392
393		find usr/openwin/bin/mkfontdir \
394		     usr/openwin/lib/installalias \
395		     usr/openwin/server/lib/libfont.so.1 \
396		     usr/openwin/server/lib/libtypesclr.so.0 \
397			 -print | cpio -ocmPuB 2> /dev/null | bzip2 > \
398			 "$CPIO_DIR/X_small.cpio.bz2"
399
400		rm -rf usr/dt usr/openwin usr/X11
401		ln -s /tmp/root/usr/dt usr/dt
402		ln -s /tmp/root/usr/openwin usr/openwin
403		ln -s /tmp/root/usr/X11 usr/X11
404	)
405}
406
407packmedia()
408{
409	MEDIA="$1"
410	MINIROOT="$2"
411
412	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
413	RELEASE=`basename "$RELEASE"`
414
415	mkdir -p "$MEDIA/$RELEASE/Tools/Boot"
416	mkdir -p "$MEDIA/boot/platform/i86pc/kernel"
417
418	# archive package databases to conserve memory
419	#
420	(
421		cd "$MINIROOT"
422		find tmp/root/var/sadm/install tmp/root/var/sadm/pkg -print | \
423		    cpio -ocmPuB 2> /dev/null | bzip2 > \
424		    "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2"
425	)
426
427	rm -rf "$MINIROOT/tmp/root/var/sadm/install"
428	rm -rf "$MINIROOT/tmp/root/var/sadm/pkg"
429
430	# clear out 64 bit support to conserve memory
431	#
432	if [ "$STRIP_AMD64" != false ] ; then
433		find "$MINIROOT" -name amd64 -type directory | xargs rm -rf
434	fi
435
436	archive_X "$MEDIA" "$MINIROOT"
437
438	# Take out the gnome and java parts of the installer from
439	# the miniroot. These are not required to boot the system
440	# and start the installers.
441
442	archive_Gnome "$MEDIA" "$MINIROOT"
443	archive_JavaGUI "$MEDIA" "$MINIROOT"
444	archive_Perl "$MEDIA" "$MINIROOT"
445	archive_Misc "$MEDIA" "$MINIROOT"
446
447	cp "$MINIROOT/platform/i86pc/multiboot" "$MEDIA/boot"
448	cp "$MINIROOT/platform/i86pc/kernel/unix" \
449	    "$MEDIA/boot/platform/i86pc/kernel/unix"
450
451	# copy the install menu to menu.lst so we have a menu
452	# on the install media
453	#
454	if [ -f "${MINIROOT}/boot/grub/install_menu" ] ; then
455		cp ${MINIROOT}/boot/grub/install_menu \
456		    ${MEDIA}/boot/grub/menu.lst
457	fi
458
459	(
460		cd "$MEDIA/$RELEASE/Tools/Boot"
461		ln -sf ../../../boot/x86.miniroot
462		ln -sf ../../../boot/multiboot
463		ln -sf ../../../boot/grub/pxegrub
464	)
465}
466
467unarchive_X()
468{
469	MEDIA="$1"
470	UNPACKED_ROOT="$2"
471
472	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
473	RELEASE=`basename "$RELEASE"`
474
475	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
476		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
477	else
478		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
479	fi
480
481	# unpack X
482	#
483	(
484		cd "$UNPACKED_ROOT"
485		rm -rf usr/dt usr/openwin usr/X11
486		bzcat "$CPIO_DIR/X.cpio.bz2" | cpio -icdmu 2> /dev/null
487	)
488}
489
490unpackmedia()
491{
492	MEDIA="$1"
493	UNPACKED_ROOT="$2"
494
495	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
496	RELEASE=`basename "$RELEASE"`
497
498	unarchive_X "$MEDIA" "$UNPACKED_ROOT"
499
500	# unpack package databases
501	#
502	(
503		cd "$UNPACKED_ROOT"
504		bzcat "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" |
505		    cpio -icdmu 2> /dev/null
506
507		# unpack gnome, perl, java and misc
508		# Remove symlinks left from unpacking x86.miniroot so that
509		# unpacking subsequent archives will populate appropriately.
510		#
511		rm -rf usr/perl5
512		rm -rf usr/lib/install/data/wizards
513		rm -rf usr/lib/lp
514
515		# Gnome list saved off from packmedia
516		for i in `cat .tmp_proto/gnome_saved`
517		do
518			rm -rf $i
519		done
520
521		bzcat "$MEDIA/$RELEASE/Tools/Boot/gnome.cpio.bz2" |
522		    cpio -icdmu 2>/dev/null
523		bzcat "$MEDIA/$RELEASE/Tools/Boot/javaui.cpio.bz2" |
524		    cpio -icdmu 2>/dev/null
525		bzcat "$MEDIA/$RELEASE/Tools/Boot/lpmisc.cpio.bz2" |
526		    cpio -icdmu 2>/dev/null
527		bzcat "$MEDIA/$RELEASE/Tools/Boot/perl.cpio.bz2" |
528		    cpio -icdmu 2>/dev/null
529	)
530}
531
532do_unpack()
533{
534	rm -rf "$UNPACKED_ROOT"
535	mkdir -p "$UNPACKED_ROOT"
536	(
537		cd $MNT
538		find . -print | cpio -pdum "$UNPACKED_ROOT" 2> /dev/null
539	)
540	umount $MNT
541}
542
543unpack()
544{
545
546	if [ ! -f "$MR" ] ; then
547		usage
548		exit 1
549	fi
550
551	gzcat "$MR" > $TMR
552
553	LOFIDEV=`/usr/sbin/lofiadm -a $TMR`
554	if [ $? != 0 ] ; then
555		echo lofi plumb failed
556		exit 2
557	fi
558
559	mkdir -p $MNT
560
561	FSTYP=`fstyp $LOFIDEV`
562
563	if [ "$FSTYP" = ufs ] ; then
564		/usr/sbin/mount -o ro,nologging $LOFIDEV $MNT
565		do_unpack
566	elif [ "$FSTYP" = hsfs ] ; then
567		/usr/sbin/mount -F hsfs -o ro $LOFIDEV $MNT
568		do_unpack
569	else
570		printf "invalid root archive\n"
571	fi
572
573	rmdir $MNT
574	lofiadm -d $TMR ; LOFIDEV=
575	rm $TMR
576}
577
578pack()
579{
580	if [ ! -d "$UNPACKED_ROOT" -o -z "$MR" ] ; then
581		usage
582		exit 1
583	fi
584
585	# Estimate image size and add %10 overhead for ufs stuff.
586	# Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem,
587	# e.g. zfs, in which the disk usage is less than the sum of the file
588	# sizes.  The nawk code
589	#
590	#	{t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
591	#
592	# below rounds up the size of a file/directory, in bytes, to the
593	# next multiple of 1024.  This mimics the behavior of ufs especially
594	# with directories.  This results in a total size that's slightly
595	# bigger than if du was called on a ufs directory.
596	size=$(find "$UNPACKED_ROOT" -ls | nawk '
597	    {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
598	    END {print int(t * 1.10 / 1024)}')
599
600	/usr/sbin/mkfile ${size}k "$TMR"
601
602	LOFIDEV=`/usr/sbin/lofiadm -a "$TMR"`
603	if [ $? != 0 ] ; then
604		echo lofi plumb failed
605		exit 2
606	fi
607
608	RLOFIDEV=`echo $LOFIDEV | sed s/lofi/rlofi/`
609	newfs $RLOFIDEV < /dev/null 2> /dev/null
610	mkdir -p $MNT
611	mount -o nologging $LOFIDEV $MNT
612	rmdir $MNT/lost+found
613	(
614		cd "$UNPACKED_ROOT"
615		find . -print | cpio -pdum $MNT 2> /dev/null
616	)
617	lockfs -f $MNT
618	umount $MNT
619	rmdir $MNT
620	lofiadm -d $LOFIDEV
621	LOFIDEV=
622
623	rm -f "$TMR.gz"
624	gzip -f "$TMR"
625	mv "$TMR.gz" "$MR"
626	chmod a+r "$MR"
627}
628
629# main
630#
631
632EXTRA_SPACE=0
633STRIP_AMD64=
634
635while getopts s:6 opt ; do
636	case $opt in
637	s)	EXTRA_SPACE="$OPTARG"
638		;;
639	6)	STRIP_AMD64=false
640		;;
641	*)	usage
642		exit 1
643		;;
644	esac
645done
646shift `expr $OPTIND - 1`
647
648if [ $# != 3 ] ; then
649	usage
650	exit 1
651fi
652
653UNPACKED_ROOT="$3"
654BASE="`pwd`"
655MNT=/tmp/mnt$$
656TMR=/tmp/mr$$
657LOFIDEV=
658MR="$2"
659
660if [ "`dirname $MR`" = . ] ; then
661	MR="$BASE/$MR"
662fi
663if [ "`dirname $UNPACKED_ROOT`" = . ] ; then
664	UNPACKED_ROOT="$BASE/$UNPACKED_ROOT"
665fi
666
667trap cleanup EXIT
668
669case $1 in
670	packmedia)
671		MEDIA="$MR"
672		MR="$MR/boot/x86.miniroot"
673
674		if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
675			archive_X "$MEDIA" "$UNPACKED_ROOT"
676		else
677			packmedia "$MEDIA" "$UNPACKED_ROOT"
678			pack
679		fi ;;
680	unpackmedia)
681		MEDIA="$MR"
682		MR="$MR/boot/x86.miniroot"
683
684		if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
685			unarchive_X "$MEDIA" "$UNPACKED_ROOT"
686		else
687			unpack
688			unpackmedia "$MEDIA" "$UNPACKED_ROOT"
689		fi ;;
690	pack)	pack ;;
691	unpack)	unpack ;;
692	*)	usage ;;
693esac
694