10Sstevel@tonic-gate#!/bin/ksh 20Sstevel@tonic-gate# 30Sstevel@tonic-gate# CDDL HEADER START 40Sstevel@tonic-gate# 50Sstevel@tonic-gate# The contents of this file are subject to the terms of the 6*1777Ssetje# Common Development and Distribution License (the "License"). 7*1777Ssetje# You may not use this file except in compliance with the License. 80Sstevel@tonic-gate# 90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate# See the License for the specific language governing permissions 120Sstevel@tonic-gate# and limitations under the License. 130Sstevel@tonic-gate# 140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate# 200Sstevel@tonic-gate# CDDL HEADER END 210Sstevel@tonic-gate# 220Sstevel@tonic-gate 23*1777Ssetje# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate# Use is subject to license terms. 250Sstevel@tonic-gate# 26*1777Ssetje# ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate# utility to pack and unpack a boot/root archive 290Sstevel@tonic-gate# both ufs and hsfs (iso9660) format archives are unpacked 300Sstevel@tonic-gate# only ufs archives are generated 310Sstevel@tonic-gate# 320Sstevel@tonic-gate# usage: pack <archive> <root> 330Sstevel@tonic-gate# unpack <archive> <root> 340Sstevel@tonic-gate# packmedia <solaris_image> <root> 350Sstevel@tonic-gate# unpackmedia <solaris_image> <root> 360Sstevel@tonic-gate# 370Sstevel@tonic-gate# Where <root> is the directory to unpack to and will be cleaned out 380Sstevel@tonic-gate# if it exists. 390Sstevel@tonic-gate# 400Sstevel@tonic-gate# In the case of (un)packmedia, the image is packed or unpacked to/from 410Sstevel@tonic-gate# Solaris media and all the things that don't go into the ramdisk image 420Sstevel@tonic-gate# are (un)cpio'd as well 430Sstevel@tonic-gate# 44*1777Ssetje# This utility is also used to pack parts (in essence the window system, 45*1777Ssetje# usr/dt and usr/openwin) of the non ramdisk SPARC 46*1777Ssetje# miniroot. (un)packmedia will recognize that they are being run a SPARC 47*1777Ssetje# miniroot and do the appropriate work. 48*1777Ssetje# 490Sstevel@tonic-gate 500Sstevel@tonic-gateusage() 510Sstevel@tonic-gate{ 520Sstevel@tonic-gate printf "usage: root_archive pack <archive> <root>\n" 530Sstevel@tonic-gate printf " root_archive unpack <archive> <root>\n" 540Sstevel@tonic-gate printf " root_archive packmedia <solaris_image> <root>\n" 550Sstevel@tonic-gate printf " root_archive unpackmedia <solaris_image> <root>\n" 560Sstevel@tonic-gate} 570Sstevel@tonic-gate 58*1777Ssetjearchive_X() 590Sstevel@tonic-gate{ 60*1777Ssetje MEDIA="$1" 61*1777Ssetje MINIROOT="$2" 620Sstevel@tonic-gate 63*1777Ssetje RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 64*1777Ssetje RELEASE=`basename "$RELEASE"` 650Sstevel@tonic-gate 66*1777Ssetje if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then 67*1777Ssetje CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra" 68*1777Ssetje mkdir -p "$CPIO_DIR" 69*1777Ssetje else 70*1777Ssetje CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 71*1777Ssetje fi 720Sstevel@tonic-gate 730Sstevel@tonic-gate # create the graphics and non-graphics X archive 740Sstevel@tonic-gate # 75*1777Ssetje cd "$MINIROOT/usr" 760Sstevel@tonic-gate find openwin dt -print | cpio -ocmPuB 2> /dev/null | bzip2 > \ 77*1777Ssetje "$CPIO_DIR/X.cpio.bz2" 780Sstevel@tonic-gate 790Sstevel@tonic-gate find openwin/bin/mkfontdir \ 800Sstevel@tonic-gate openwin/lib/installalias \ 810Sstevel@tonic-gate openwin/server/lib/libfont.so.1 \ 820Sstevel@tonic-gate openwin/server/lib/libtypesclr.so.0 \ 830Sstevel@tonic-gate -print | cpio -ocmPuB 2> /dev/null | bzip2 > \ 84*1777Ssetje "$CPIO_DIR/X_small.cpio.bz2" 850Sstevel@tonic-gate 860Sstevel@tonic-gate rm -rf dt openwin 870Sstevel@tonic-gate ln -s ../tmp/root/usr/dt 880Sstevel@tonic-gate ln -s ../tmp/root/usr/openwin 890Sstevel@tonic-gate cd ../.. 90*1777Ssetje} 91*1777Ssetje 92*1777Ssetjepackmedia() 93*1777Ssetje{ 94*1777Ssetje MEDIA="$1" 95*1777Ssetje MINIROOT="$2" 96*1777Ssetje 97*1777Ssetje RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 98*1777Ssetje RELEASE=`basename "$RELEASE"` 99*1777Ssetje 100*1777Ssetje mkdir -p "$MEDIA/$RELEASE/Tools/Boot" 101*1777Ssetje mkdir -p "$MEDIA/boot" 102*1777Ssetje 103*1777Ssetje cd "$MINIROOT" 104*1777Ssetje 105*1777Ssetje # archive package databases to conserve memory 106*1777Ssetje # 107*1777Ssetje find tmp/root/var/sadm/install tmp/root/var/sadm/pkg -print | \ 108*1777Ssetje cpio -ocmPuB 2> /dev/null | bzip2 > \ 109*1777Ssetje "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" 110*1777Ssetje 111*1777Ssetje rm -rf "$MINIROOT/tmp/root/var/sadm/install" 112*1777Ssetje rm -rf "$MINIROOT/tmp/root/var/sadm/pkg" 113*1777Ssetje 114*1777Ssetje archive_X "$MEDIA" "$MINIROOT" 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate # clear out 64 bit support to conserve memory 1170Sstevel@tonic-gate # 118*1777Ssetje find "$MINIROOT" -name amd64 -type directory | xargs rm -rf 1190Sstevel@tonic-gate 120*1777Ssetje cp "$MINIROOT/platform/i86pc/multiboot" "$MEDIA/boot" 1210Sstevel@tonic-gate 122*1777Ssetje cd "$MEDIA/$RELEASE/Tools/Boot" 1230Sstevel@tonic-gate ln -sf ../../../boot/x86.miniroot 1240Sstevel@tonic-gate ln -sf ../../../boot/multiboot 1250Sstevel@tonic-gate ln -sf ../../../boot/grub/pxegrub 126*1777Ssetje} 1270Sstevel@tonic-gate 128*1777Ssetjeunarchive_X() 129*1777Ssetje{ 130*1777Ssetje MEDIA="$1" 131*1777Ssetje UNPACKED_ROOT="$2" 132*1777Ssetje 133*1777Ssetje RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 134*1777Ssetje RELEASE=`basename "$RELEASE"` 135*1777Ssetje 136*1777Ssetje if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then 137*1777Ssetje CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra" 138*1777Ssetje else 139*1777Ssetje CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 1400Sstevel@tonic-gate fi 141*1777Ssetje 142*1777Ssetje # unpack X 143*1777Ssetje # 144*1777Ssetje cd "$UNPACKED_ROOT/usr" 145*1777Ssetje rm -rf dt openwin 146*1777Ssetje bzcat "$CPIO_DIR/X.cpio.bz2" | cpio -icdmu 2> /dev/null 1470Sstevel@tonic-gate} 1480Sstevel@tonic-gate 1490Sstevel@tonic-gateunpackmedia() 150*1777Ssetje{ 151*1777Ssetje MEDIA="$1" 152*1777Ssetje UNPACKED_ROOT="$2" 1530Sstevel@tonic-gate 154*1777Ssetje RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 155*1777Ssetje RELEASE=`basename "$RELEASE"` 156*1777Ssetje 157*1777Ssetje unarchive_X "$MEDIA" "$UNPACKED_ROOT" 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate # unpack package databases 1600Sstevel@tonic-gate # 161*1777Ssetje cd "$UNPACKED_ROOT" 162*1777Ssetje bzcat "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" | cpio -icdmu \ 1630Sstevel@tonic-gate 2> /dev/null 1640Sstevel@tonic-gate} 1650Sstevel@tonic-gate 1660Sstevel@tonic-gatedo_unpack() 1670Sstevel@tonic-gate{ 168*1777Ssetje rm -rf "$UNPACKED_ROOT" 169*1777Ssetje mkdir -p "$UNPACKED_ROOT" 1700Sstevel@tonic-gate cd $MNT 171*1777Ssetje find . -print | cpio -pdum "$UNPACKED_ROOT" 2> /dev/null 172*1777Ssetje cd "$BASE" 1730Sstevel@tonic-gate umount $MNT 1740Sstevel@tonic-gate} 1750Sstevel@tonic-gate 1760Sstevel@tonic-gateunpack() 1770Sstevel@tonic-gate{ 1780Sstevel@tonic-gate 179*1777Ssetje if [ ! -f "$MR" ] ; then 1800Sstevel@tonic-gate usage 1810Sstevel@tonic-gate exit 1 1820Sstevel@tonic-gate fi 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate TMR=/tmp/mr$$ 185*1777Ssetje gzcat "$MR" > $TMR 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate lofidev=`/usr/sbin/lofiadm -a $TMR` 1880Sstevel@tonic-gate if [ $? != 0 ] ; then 1890Sstevel@tonic-gate echo lofi plumb failed 1900Sstevel@tonic-gate exit 2 1910Sstevel@tonic-gate fi 1920Sstevel@tonic-gate 193*1777Ssetje mkdir -p $MNT 1940Sstevel@tonic-gate 195*1777Ssetje FSTYP=`fstyp $lofidev` 1960Sstevel@tonic-gate 197*1777Ssetje if [ "$FSTYP" = ufs ] ; then 1980Sstevel@tonic-gate /usr/sbin/mount -o ro,nologging $lofidev $MNT 1990Sstevel@tonic-gate do_unpack 200*1777Ssetje elif [ "$FSTYP" = hsfs ] ; then 2010Sstevel@tonic-gate /usr/sbin/mount -F hsfs -o ro $lofidev $MNT 2020Sstevel@tonic-gate do_unpack 2030Sstevel@tonic-gate else 2040Sstevel@tonic-gate printf "invalid root archive\n" 2050Sstevel@tonic-gate fi 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate rmdir $MNT 2080Sstevel@tonic-gate lofiadm -d $TMR 2090Sstevel@tonic-gate rm $TMR 2100Sstevel@tonic-gate} 2110Sstevel@tonic-gate 2120Sstevel@tonic-gatepack() 2130Sstevel@tonic-gate{ 214*1777Ssetje if [ ! -d "$UNPACKED_ROOT" -o -z "$MR" ] ; then 2150Sstevel@tonic-gate usage 2160Sstevel@tonic-gate exit 1 2170Sstevel@tonic-gate fi 2180Sstevel@tonic-gate 219*1777Ssetje size=`du -sk "$UNPACKED_ROOT" | ( read size name; echo $size )` 2200Sstevel@tonic-gate size=`expr $size + \( $size \* 10 \) / 100` 221*1777Ssetje rm -f "$MR" 222*1777Ssetje /usr/sbin/mkfile ${size}k "$MR" 2230Sstevel@tonic-gate 224*1777Ssetje lofidev=`/usr/sbin/lofiadm -a "$MR"` 2250Sstevel@tonic-gate if [ $? != 0 ] ; then 2260Sstevel@tonic-gate echo lofi plumb failed 2270Sstevel@tonic-gate exit 2 2280Sstevel@tonic-gate fi 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate rlofidev=`echo $lofidev | sed s/lofi/rlofi/` 2310Sstevel@tonic-gate newfs $rlofidev < /dev/null 2> /dev/null 232*1777Ssetje mkdir -p $MNT 2330Sstevel@tonic-gate mount -o nologging $lofidev $MNT 234*1777Ssetje rmdir $MNT/lost+found 235*1777Ssetje cd "$UNPACKED_ROOT" 2360Sstevel@tonic-gate find . -print | cpio -pdum $MNT 2> /dev/null 2370Sstevel@tonic-gate lockfs -f $MNT 2380Sstevel@tonic-gate umount $MNT 2390Sstevel@tonic-gate rmdir $MNT 240*1777Ssetje lofiadm -d "$MR" 2410Sstevel@tonic-gate 242*1777Ssetje cd "$BASE" 2430Sstevel@tonic-gate 244*1777Ssetje rm -f "$MR.gz" 245*1777Ssetje gzip -f "$MR" 246*1777Ssetje mv "$MR.gz" "$MR" 247*1777Ssetje chmod a+r "$MR" 2480Sstevel@tonic-gate} 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate# main 2510Sstevel@tonic-gate# 2520Sstevel@tonic-gate 2530Sstevel@tonic-gateif [ $# != 3 ] ; then 2540Sstevel@tonic-gate usage 2550Sstevel@tonic-gate exit 1 2560Sstevel@tonic-gatefi 2570Sstevel@tonic-gate 258*1777SsetjeUNPACKED_ROOT="$3" 259*1777SsetjeBASE="`pwd`" 2600Sstevel@tonic-gateMNT=/tmp/mnt$$ 261*1777SsetjeMR="$2" 2620Sstevel@tonic-gate 2630Sstevel@tonic-gateif [ "`dirname $MR`" = . ] ; then 264*1777Ssetje MR="$BASE/$MR" 2650Sstevel@tonic-gatefi 2660Sstevel@tonic-gateif [ "`dirname $UNPACKED_ROOT`" = . ] ; then 267*1777Ssetje UNPACKED_ROOT="$BASE/$UNPACKED_ROOT" 2680Sstevel@tonic-gatefi 2690Sstevel@tonic-gate 2700Sstevel@tonic-gatecase $1 in 2710Sstevel@tonic-gate packmedia) 272*1777Ssetje MEDIA="$MR" 273*1777Ssetje MR="$MR/boot/x86.miniroot" 274*1777Ssetje 275*1777Ssetje if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then 276*1777Ssetje archive_X "$MEDIA" "$UNPACKED_ROOT" 277*1777Ssetje else 278*1777Ssetje packmedia "$MEDIA" "$UNPACKED_ROOT" 279*1777Ssetje pack 280*1777Ssetje fi ;; 2810Sstevel@tonic-gate unpackmedia) 282*1777Ssetje MEDIA="$MR" 283*1777Ssetje MR="$MR/boot/x86.miniroot" 284*1777Ssetje 285*1777Ssetje if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then 286*1777Ssetje unarchive_X "$MEDIA" "$UNPACKED_ROOT" 287*1777Ssetje else 288*1777Ssetje unpack 289*1777Ssetje unpackmedia "$MEDIA" "$UNPACKED_ROOT" 290*1777Ssetje fi ;; 2910Sstevel@tonic-gate pack) pack ;; 2920Sstevel@tonic-gate unpack) unpack ;; 2930Sstevel@tonic-gate *) usage ;; 2940Sstevel@tonic-gateesac 295