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 2009 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26 27# utility to pack and unpack a boot/root archive 28# both ufs and hsfs (iso9660) format archives are unpacked 29# only ufs archives are generated 30# 31# usage: pack <archive> <root> 32# unpack <archive> <root> 33# packmedia <solaris_image> <root> 34# unpackmedia <solaris_image> <root> 35# 36# Where <root> is the directory to unpack to and will be cleaned out 37# if it exists. 38# 39# In the case of (un)packmedia, the image is packed or unpacked to/from 40# Solaris media and all the things that don't go into the ramdisk image 41# are (un)cpio'd as well 42# 43 44usage() 45{ 46 printf "usage: root_archive pack <archive> <root>\n" 47 printf " root_archive unpack <archive> <root>\n" 48 printf " root_archive packmedia <solaris_image> <root>\n" 49 printf " root_archive unpackmedia <solaris_image> <root>\n" 50 exit 1 51} 52 53cleanup() 54{ 55 if [ -d $MNT ] ; then 56 umount $MNT 2> /dev/null 57 rmdir $MNT 58 fi 59 60 lofiadm -d "$TMR" 2>/dev/null 61 if [ "$REALTHING" != true ] ; then 62 rm -f "$TMR" 63 fi 64 rm -f "$TMR.gz" 65 rm -f /tmp/flist$$ 66} 67 68preload_Gnome() 69{ 70 MEDIA="$1" 71 MINIROOT="$2" 72 73 74 ( 75 # Prepopulate the gconf database. This needs to be done and 76 # done first for several reasons. 1) Archiving out the gnome 77 # libraries and binaries causes the gconftool-2 to not run 78 # appropriately at boot time. 2) The binaries and libraries 79 # needed to run this are big and thus we want to archive 80 # them separately. 3) Having schemas prepopluated in the 81 # miniroot means faster boot times. 82 # 83 84 cd "$MINIROOT" 85 HOME="./tmp/root" 86 export HOME 87 umask 0022 88 mumble=.tmp_proto/root/etc/gconf/gconf.xml.defaults 89 GCONF_CONFIG_SOURCE="xml:merged:$MINIROOT/$mumble" 90 export GCONF_CONFIG_SOURCE 91 SCHEMADIR="$MINIROOT/.tmp_proto/root/etc/gconf/schemas" 92 export SCHEMADIR 93 /usr/bin/gconftool-2 --makefile-install-rule \ 94 $SCHEMADIR/*.schemas >/dev/null 2>&1 95 echo ' 96 xml:readwrite:/tmp/root/.gconf 97 xml:readonly:/etc/gconf/gconf.xml.defaults 98 ' > /"$MINIROOT"/.tmp_proto/root/etc/gconf/2/path 99 ) 100} 101 102archive_Gnome() 103{ 104 MEDIA="$1" 105 MINIROOT="$2" 106 107 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 108 RELEASE=`basename "$RELEASE"` 109 CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 110 111 # Create the gnome archive 112 # 113 ( 114 # usr/share gnome stuff 115 cd "$MINIROOT" 116 find usr/share/GConf usr/share/application-registry \ 117 usr/share/autostart usr/share/dtds \ 118 usr/share/emacs usr/share/gnome usr/share/gnome-2.0 \ 119 usr/share/gnome-background-properties \ 120 usr/share/gtk-engines usr/share/gui-install \ 121 usr/share/icon-naming-utils usr/share/control-center \ 122 usr/share/icons usr/share/locale usr/share/metacity \ 123 usr/share/mime usr/share/mime-info usr/share/pixmaps \ 124 usr/share/scrollkeeper usr/share/sgml usr/share/themes \ 125 usr/share/xml \ 126 -print > /tmp/gnome_share.$$ 2>/dev/null 127 128 if [ ! -f /tmp/gnome_share.$$ ] ; then 129 echo "/tmp/gnome_share.$$ file list not found." 130 return 131 fi 132 133 # usr/lib gnome stuff 134 135 find usr/lib/libgnome*\.so\.* \ 136 usr/lib/libgst*\.so\.* usr/lib/libgconf*\.so\.* \ 137 usr/lib/libgdk*\.so\.* usr/lib/libgtk*\.so\.* \ 138 usr/lib/libglade*\.so\.* usr/lib/libmetacity*\.so\.* \ 139 usr/lib/libfontconfig*\.so\.* usr/lib/libgmodule*\.so\.* \ 140 usr/lib/libgobject*\.so\.* usr/lib/libgthread*\.so\.* \ 141 usr/lib/libpopt*\.so\.* usr/lib/libstartup*\.so\.* \ 142 usr/lib/libexif*\.so\.* usr/lib/libtiff*\.so\.* \ 143 usr/lib/libstartup*\.so\.* \ 144 usr/lib/libexif*\.so\.* usr/lib/libORBit*\.so\.* \ 145 usr/lib/libmlib*\.so\.* usr/lib/libxsl*\.so\.* \ 146 usr/lib/libpango*\.so\.* usr/lib/libpng*\.so\.* \ 147 usr/lib/liboil*\.so\.* usr/lib/libbonobo*\.so\.* \ 148 usr/lib/libart*\.so\.* usr/lib/libcairo*\.so\.* \ 149 usr/lib/libjpeg*\.so\.* \ 150 usr/lib/libpolkit*\.so\.* \ 151 -print | egrep -v '\.so\.[0]$' > \ 152 /tmp/gnome_lib.$$ 2>/dev/null 153 154 find usr/lib/nautilus usr/lib/pango usr/lib/iconv \ 155 usr/lib/metacity-dialog usr/lib/window-manager-settings \ 156 usr/lib/bonobo-2.0 usr/lib/bononbo usr/lib/gtk-2.0 \ 157 usr/lib/GConf usr/lib/bonobo-activation-server \ 158 usr/lib/python2.4 usr/lib/gstreamer-0.10 \ 159 usr/lib/gconf-sanity-check-2 usr/lib/gconfd \ 160 usr/lib/gnome-vfs-2.0 usr/lib/dbus-daemon \ 161 usr/lib/gnome-vfs-daemon usr/lib/gnome-settings-daemon \ 162 usr/lib/gnome_segv2 usr/lib/orbit-2.0 \ 163 usr/lib/libmlib \ 164 print > /tmp/gnome_libdir.$$ 2>/dev/null 165 166 if [ ! -f /tmp/gnome_lib.$$ -a ! -f gnome_libdir.$$ ] ; then 167 echo "/tmp/gnome_lib.$$ file list not found." 168 return 169 fi 170 171 # /usr/sfw gnome stuff 172 find usr/sfw/bin usr/sfw/include usr/sfw/share usr/sfw/src \ 173 -print > /tmp/gnome_sfw.$$ 2>/dev/null 174 175 if [ ! -f /tmp/gnome_sfw.$$ ] ; then 176 echo "/tmp/gnome_sfw.$$ file list not found." 177 return 178 fi 179 180 # gnome app binaries usr/bin 181 find usr/bin/gnome* usr/bin/gui-install usr/bin/bonobo* \ 182 usr/bin/gtk-* usr/bin/fax* usr/bin/gdk* usr/bin/gif2tiff \ 183 usr/bin/install-lan \ 184 usr/bin/metacity* usr/bin/gst-* usr/bin/gconftool-2 \ 185 usr/bin/pango* usr/bin/desktop* usr/bin/djpeg \ 186 usr/bin/notify-send usr/bin/oil-bugreport \ 187 usr/bin/bmp2tiff usr/bin/thembus-theme-applier \ 188 usr/bin/thumbnail usr/lib/update-* \ 189 usr/bin/ras2tiff usr/bin/raw2tiff usr/bin/rdjpgcom \ 190 usr/bin/thumbnail usr/bin/dbus* \ 191 usr/bin/tiff* usr/bin/rgb2ycbcr \ 192 usr/bin/fc-cache usr/bin/fc-list \ 193 -print > /tmp/gnome_bin.$$ 2>/dev/null 194 195 if [ ! -f /tmp/gnome_bin.$$ ] ; then 196 echo "/tmp/gnome_bin.$$ file list not found." 197 return 198 fi 199 200 # Cat all the files together and create the gnome archive 201 # 202 203 cat /tmp/gnome_libdir.$$ /tmp/gnome_lib.$$ \ 204 /tmp/gnome_share.$$ /tmp/gnome_sfw.$$ /tmp/gnome_bin.$$ \ 205 > /tmp/gnome.$$ 206 207 if [ ! -f /tmp/gnome.$$ ] ; then 208 echo "/tmp/gnome.$$ file not found." 209 return 210 fi 211 # Save off this file in the miniroot for use later 212 # when unpacking. Clean up old cruft if there. 213 # 214 215 if [ -f .tmp_proto/gnome_saved ]; then 216 rm -f .tmp_proto/gnome_saved 217 fi 218 219 cp /tmp/gnome.$$ .tmp_proto/gnome_saved 220 221 # Create gnome archive 222 # 223 224 cpio -ocmPuB < /tmp/gnome.$$ 2>/dev/null | bzip2 > \ 225 "$CPIO_DIR/gnome.cpio.bz2" 226 227 # Remove files from miniroot that are in archive. 228 # Create symlinks for files in archive 229 230 rm -rf `cat /tmp/gnome_share.$$` 231 232 for i in `cat /tmp/gnome_share.$$` 233 do 234 ln -s /tmp/root/$i $i 2>/dev/null 235 done 236 237 rm -rf `cat /tmp/gnome_lib.$$` 238 for i in `cat /tmp/gnome_lib.$$` 239 do 240 ln -s /tmp/root/$i $i 2>/dev/null 241 done 242 243 rm -rf `cat /tmp/gnome_libdir.$$` 244 for i in `cat /tmp/gnome_libdir.$$` 245 do 246 ln -s /tmp/root/$i $i 2>/dev/null 247 done 248 249 rm -rf `cat /tmp/gnome_sfw.$$` 250 for i in `cat /tmp/gnome_sfw.$$` 251 do 252 ln -s /tmp/root/$i $i 2>/dev/null 253 done 254 255 rm -rf `cat /tmp/gnome_bin.$$` 256 for i in `cat /tmp/gnome_bin.$$` 257 do 258 ln -s /tmp/root/$i $i 2>/dev/null 259 done 260 rm -f /tmp/gnome_share.$$ 261 rm -f /tmp/gnome_lib.$$ 262 rm -f /tmp/gnome_libdir.$$ 263 rm -f /tmp/gnome_bin.$$ 264 ) 265} 266 267archive_JavaGUI() 268{ 269 MEDIA="$1" 270 MINIROOT="$2" 271 272 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 273 RELEASE=`basename "$RELEASE"` 274 275 CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 276 277 # Archive the java wizard components that are only used in the 278 # non developer express path. 279 # 280 ( 281 # path is usr/lib/install/data 282 cd "$MINIROOT" 283 find usr/lib/install/data/wizards \ 284 -print > /tmp/java_ui.$$ 2>/dev/null 285 286 if [ ! -f /tmp/java_ui.$$ ] ; then 287 echo "/tmp/java_ui.$$ file list not found." 288 return 289 fi 290 291 cpio -ocmPuB < /tmp/java_ui.$$ 2>/dev/null | bzip2 > \ 292 "$CPIO_DIR/javaui.cpio.bz2" 293 294 rm -rf `cat /tmp/java_ui.$$` 295 ln -s /tmp/root/usr/lib/install/data/wizards \ 296 usr/lib/install/data/wizards 2>/dev/null 297 298 rm -f /tmp/java_ui.$$ 299 300 ) 301} 302 303archive_Misc() 304{ 305 MEDIA="$1" 306 MINIROOT="$2" 307 308 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 309 RELEASE=`basename "$RELEASE"` 310 311 CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 312 313 # Archive misc stuff that is needed by non devex installer 314 # 315 ( 316 # usr/lib stuff 317 cd "$MINIROOT" 318 find usr/lib/lp -print > /tmp/lp.$$ 2>/dev/null 319 if [ ! -f /tmp/lp.$$ ] ; then 320 echo "/tmp/lp.$$ file list not found." 321 return 322 fi 323 324 cpio -ocmPuB < /tmp/lp.$$ 2>/dev/null | bzip2 > \ 325 "$CPIO_DIR/lpmisc.cpio.bz2" 326 327 rm -rf `cat /tmp/lp.$$` 328 ln -s /tmp/root/usr/lib/lp usr/lib/lp 2>/dev/null 329 330 rm -f /tmp/lp.$$ 331 ) 332 333} 334 335archive_Perl() 336{ 337 MEDIA="$1" 338 MINIROOT="$2" 339 340 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 341 RELEASE=`basename "$RELEASE"` 342 343 CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 344 345 # Archive perl, it is only needed by gnome gui. 346 # 347 ( 348 # in usr 349 cd "$MINIROOT" 350 find usr/perl5 -print > /tmp/perl.$$ 2>/dev/null 351 352 if [ ! -f /tmp/perl.$$ ] ; then 353 echo "/tmp/perl.$$ file list not found." 354 return 355 fi 356 cpio -ocmPuB < /tmp/perl.$$ 2>/dev/null | bzip2 > \ 357 "$CPIO_DIR/perl.cpio.bz2" 358 359 rm -rf `cat /tmp/perl.$$` 2>/dev/null 360 ln -s /tmp/root/usr/perl5 usr/perl5 2>/dev/null 361 362 rm -f /tmp/perl.$$ 363 ) 364} 365archive_X() 366{ 367 MEDIA="$1" 368 MINIROOT="$2" 369 370 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 371 RELEASE=`basename "$RELEASE"` 372 373 CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 374 375 # create the graphics and non-graphics X archive 376 # 377 ( 378 cd "$MINIROOT" 379 find usr/openwin usr/dt usr/X11 -print 2> /dev/null |\ 380 cpio -ocmPuB 2> /dev/null | bzip2 > "$CPIO_DIR/X.cpio.bz2" 381 382 find usr/openwin/bin/mkfontdir \ 383 usr/openwin/lib/installalias \ 384 usr/openwin/server/lib/libfont.so.1 \ 385 usr/openwin/server/lib/libtypesclr.so.0 \ 386 -print | cpio -ocmPuB 2> /dev/null | bzip2 > \ 387 "$CPIO_DIR/X_small.cpio.bz2" 388 389 rm -rf usr/dt usr/openwin usr/X11 390 ln -s /tmp/root/usr/dt usr/dt 391 ln -s /tmp/root/usr/openwin usr/openwin 392 ln -s /tmp/root/usr/X11 usr/X11 393 ) 394} 395 396archive_lu() 397{ 398 MEDIA="$1" 399 MINIROOT="$2" 400 401 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 402 RELEASE=`basename "$RELEASE"` 403 404 CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 405 406 ( 407 cd "$MINIROOT" 408 find usr/lib/install usr/snadm usr/sbin usr/lib/locale \ 409 boot/grub boot/solaris/bootenv.rc \ 410 tmp/root/boot/grub tmp/root/boot/solaris/bootenv.rc \ 411 2> /dev/null | cpio -ocmPuB 2> /dev/null | bzip2 \ 412 > "$CPIO_DIR"/lu.cpio.bz2 413 ls platform > "$CPIO_DIR/lu.platforms" 414 ) 415} 416 417cleanout_pkgdata() 418{ 419 rm -Rf tmp/root/var/sadm/install tmp/root/var/sadm/pkg 420} 421 422packmedia() 423{ 424 MEDIA="$1" 425 MINIROOT="$2" 426 427 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 428 RELEASE=`basename "$RELEASE"` 429 ARCHIVES="X X_small perl lpmisc javaui gnome" 430 431 mkdir -p "$MEDIA/$RELEASE/Tools/Boot" 432 433 if [ -d "$MINIROOT/platform/i86pc" ] ; then 434 mkdir -p "$MEDIA/boot/amd64" 435 mkdir -p "$MEDIA/boot/platform/i86pc/kernel" 436 mkdir -p "$MEDIA/boot/platform/i86pc/kernel/amd64" 437 mkdir -p "$MEDIA/boot/platform/i86xpv/kernel" 438 mkdir -p "$MEDIA/boot/platform/i86xpv/kernel/amd64" 439 cp "$MINIROOT/platform/i86pc/multiboot" "$MEDIA/boot" 440 cp "$MINIROOT/platform/i86pc/kernel/unix" \ 441 "$MEDIA/boot/platform/i86pc/kernel/unix" 442 cp "$MINIROOT/platform/i86pc/kernel/amd64/unix" \ 443 "$MEDIA/boot/platform/i86pc/kernel/amd64/unix" 444 cp "$MINIROOT/platform/i86xpv/kernel/unix" \ 445 "$MEDIA/boot/platform/i86xpv/kernel/unix" 446 cp "$MINIROOT/platform/i86xpv/kernel/amd64/unix" \ 447 "$MEDIA/boot/platform/i86xpv/kernel/amd64/unix" 448 ( 449 cd "$MEDIA/$RELEASE/Tools/Boot" 450 ln -sf ../../../boot/x86.miniroot 451 ln -sf ../../../boot/multiboot 452 ln -sf ../../../boot/platform/i86pc/kernel/unix 453 ln -sf ../../../boot/platform/i86pc/kernel/amd64/unix 454 ln -sf ../../../boot/platform/i86xpv/kernel/unix 455 ln -sf ../../../boot/platform/i86xpv/kernel/amd64/unix 456 ln -sf ../../../boot/grub/pxegrub 457 ) 458 fi 459 460 if [ -d "$MINIROOT/platform/sun4u" ] ; then 461 mkdir -p "$MEDIA/boot" 462 dd if="$MINIROOT/platform/sun4u/lib/fs/hsfs/bootblk" \ 463 of="$MEDIA/boot/hsfs.bootblock" \ 464 bs=1b oseek=1 count=15 conv=sync 2> /dev/null 465 fi 466 467 for arch in sun4u sun4v ; do 468 if [ -d "$MINIROOT/platform/$arch" ] ; then 469 archdir="$MEDIA/$RELEASE/Tools/Boot/platform/$arch" 470 mkdir -p $archdir 471 ln -sf ../../../../../boot/sparc.miniroot \ 472 "$archdir/boot_archive" 473 cp "$MINIROOT/usr/platform/$arch/lib/fs/nfs/inetboot" \ 474 "$archdir" 475 cp "$MINIROOT/platform/$arch/wanboot" \ 476 "$archdir" 477 mkdir -p "$MEDIA/platform/$arch" 478 ln -sf ../../boot/sparc.miniroot \ 479 "$MEDIA/platform/$arch/boot_archive" 480 ln -sf ../../$RELEASE/Tools/Boot/platform/$arch/wanboot \ 481 "$MEDIA/platform/$arch/wanboot" 482 fi 483 done 484 485 # archive package databases to conserve memory 486 # 487 ( 488 cd "$MINIROOT" 489 find tmp/root/var/sadm/install tmp/root/var/sadm/pkg -print | \ 490 cpio -ocmPuB 2> /dev/null | bzip2 > \ 491 "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" 492 493 cleanout_pkgdata 494 ) 495 496 archive_lu "$MEDIA" "$MINIROOT" 497 498 archive_X "$MEDIA" "$MINIROOT" 499 500 # Take out the gnome and java parts of the installer from 501 # the miniroot. These are not required to boot the system 502 # and start the installers. 503 504 if [ -d "$MINIROOT/platform/i86pc" ] ; then 505 preload_Gnome "$MEDIA" "$MINIROOT" 506 archive_Gnome "$MEDIA" "$MINIROOT" 507 archive_JavaGUI "$MEDIA" "$MINIROOT" 508 archive_Misc "$MEDIA" "$MINIROOT" 509 archive_Perl "$MEDIA" "$MINIROOT" 510 pack "$MEDIA/boot/amd64/x86.miniroot" 511 512 # Now that the 64-bit archives & miniroot have been created, 513 # restore the files from archives and save the 64-bit 514 # archives. Strip the 64-bit objects and create the 515 # 32-bit archives and miniroot 516 517 unpackmedia "$MEDIA" "$MINIROOT" 518 cleanout_pkgdata 519 mkdir -p "$MEDIA/$RELEASE/Tools/Boot/amd64" 520 for i in $ARCHIVES; do 521 mv "$MEDIA/$RELEASE/Tools/Boot/${i}.cpio.bz2" \ 522 "$MEDIA/$RELEASE/Tools/Boot/amd64" 523 done 524 if [ -z "$STRIP_AMD64" ]; then 525 strip_amd64 526 fi 527 528 archive_X "$MEDIA" "$MINIROOT" 529 archive_Gnome "$MEDIA" "$MINIROOT" 530 archive_JavaGUI "$MEDIA" "$MINIROOT" 531 archive_Perl "$MEDIA" "$MINIROOT" 532 archive_Misc "$MEDIA" "$MINIROOT" 533 fi 534 535 # copy the install menu to menu.lst so we have a menu 536 # on the install media 537 # 538 if [ -f "$MINIROOT/boot/grub/install_menu" ] ; then 539 cp $MINIROOT/boot/grub/install_menu \ 540 $MEDIA/boot/grub/menu.lst 541 fi 542 543 # 544 # jumpstart utilities in usr/sbin/install.d 545 # 546 if [ -d "$MINIROOT/usr/sbin/install.d" ] ; then 547 ( 548 cd ${MINIROOT} 549 find usr/sbin/install.d/chkprobe \ 550 -print | cpio -ocmPuB 2> /dev/null | bzip2 > \ 551 ${MEDIA}/${RELEASE}/Tools/Boot/usr_sbin_install_d.cpio.bz2 552 ) 553 fi 554} 555 556unarchive_X() 557{ 558 MEDIA="$1" 559 UNPACKED_ROOT="$2" 560 561 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 562 RELEASE=`basename "$RELEASE"` 563 564 CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot" 565 566 # unpack X 567 # 568 ( 569 cd "$UNPACKED_ROOT" 570 rm -rf usr/dt usr/openwin usr/X11 571 bzcat "$CPIO_DIR/X.cpio.bz2" | cpio -icdmu 2> /dev/null 572 ) 573} 574 575unpackmedia() 576{ 577 MEDIA="$1" 578 UNPACKED_ROOT="$2" 579 580 RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*` 581 RELEASE=`basename "$RELEASE"` 582 583 unarchive_X "$MEDIA" "$UNPACKED_ROOT" 584 585 # unpack package databases 586 # 587 ( 588 cd "$UNPACKED_ROOT" 589 bzcat "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" | 590 cpio -icdmu 2> /dev/null 591 592 if [ -d "$MINIROOT/platform/i86pc" ] ; then 593 594 # unpack gnome, perl, java and misc 595 # Remove symlinks left from unpacking x86.miniroot 596 # so that unpacking subsequent archives will populate 597 # appropriately. 598 # 599 rm -rf usr/perl5 600 rm -rf usr/lib/install/data/wizards 601 rm -rf usr/lib/lp 602 603 # Gnome list saved off from packmedia 604 for i in `cat .tmp_proto/gnome_saved` 605 do 606 rm -rf $i 607 done 608 609 bzcat "$MEDIA/$RELEASE/Tools/Boot/gnome.cpio.bz2" | 610 cpio -icdmu 2>/dev/null 611 bzcat "$MEDIA/$RELEASE/Tools/Boot/javaui.cpio.bz2" | 612 cpio -icdmu 2>/dev/null 613 bzcat "$MEDIA/$RELEASE/Tools/Boot/lpmisc.cpio.bz2" | 614 cpio -icdmu 2>/dev/null 615 bzcat "$MEDIA/$RELEASE/Tools/Boot/perl.cpio.bz2" | 616 cpio -icdmu 2>/dev/null 617 fi 618 ) 619} 620 621do_unpack() 622{ 623 ( 624 cd $MNT 625 find . -print | cpio -pdum "$UNPACKED_ROOT" 2> /dev/null 626 ) 627 # increase the chances the unmount will succeed 628 umount -f $MNT 629} 630 631unpack() 632{ 633 MR=$1 634 if [ ! -f "$MR" ] ; then 635 printf "$MR: not found\n" 636 usage 637 fi 638 639 if [ `uname -i` = i86pc ] ; then 640 gzcat "$MR" > $TMR 641 else 642 REALTHING=true ; export REALTHING 643 TMR="$MR" 644 fi 645 646 LOFIDEV=`/usr/sbin/lofiadm -a $TMR` 647 if [ $? != 0 ] ; then 648 echo lofi plumb failed 649 exit 2 650 fi 651 652 mkdir -p $MNT 653 654 FSTYP=`fstyp $LOFIDEV` 655 656 if [ "$FSTYP" = ufs ] ; then 657 /usr/sbin/mount -o ro,nologging $LOFIDEV $MNT 658 do_unpack 659 elif [ "$FSTYP" = hsfs ] ; then 660 /usr/sbin/mount -F hsfs -o ro $LOFIDEV $MNT 661 do_unpack 662 else 663 printf "invalid root archive\n" 664 fi 665 666 667 rmdir $MNT 668 lofiadm -d $TMR ; LOFIDEV= 669 if [ "$REALTHING" != true ] ; then 670 rm $TMR 671 fi 672} 673 674compress() 675{ 676 SRC=$1 677 DST=$2 678 679 ( 680 cd $SRC 681 filelist=`find .` 682 683 for file in $filelist ; do 684 685 file=`echo $file | sed s#^./##` 686 687 # copy all files over to preserve hard links 688 # 689 echo $file | cpio -pdum $DST 2> /dev/null 690 691 if [ -f $file ] && [ -s $file ] && [ ! -h $file ] ; then 692 fiocompress -mc $file $DST/$file & 693 fi 694 695 done 696 697 wait `pgrep fiocompress` 698 699 # now re-copy a couple of uncompressed files 700 701 if [ -d "$SRC/platform/i86pc" ] ; then 702 find `cat boot/solaris/filelist.ramdisk` -type file \ 703 -print 2> /dev/null > /tmp/flist$$ 704 find usr/kernel -type file -print 2> /dev/null \ 705 >> /tmp/flist$$ 706 # some of the files are replaced with links into 707 # tmp/root on the miniroot, so find the backing files 708 # from there as well and add them to the list ti 709 # be copied uncompressed 710 ( 711 cd $SRC/tmp/root 712 find `cat ../../boot/solaris/filelist.ramdisk` \ 713 -type file -print 2> /dev/null | \ 714 sed 's#^#tmp/root/#' >> /tmp/flist$$ 715 ) 716 flist=`cat /tmp/flist$$` 717 ( 718 cd $DST 719 rm -f $flist 720 ) 721 for file in $flist ; do 722 echo $file | cpio -pdum $DST 2> /dev/null 723 done 724 else 725 find kernel platform -name unix | \ 726 cpio -pdum $DST 2> /dev/null 727 find kernel platform -name genunix | cpio -pdum $DST \ 728 2> /dev/null 729 find kernel platform -name platmod | cpio -pdum $DST \ 730 2> /dev/null 731 find `find kernel platform -name cpu` | \ 732 cpio -pdum $DST 2> /dev/null 733 find `find kernel platform -name kmdb\*` | \ 734 cpio -pdum $DST 2> /dev/null 735 find kernel/misc/sparcv9/ctf kernel/fs/sparcv9/dcfs \ 736 kernel/misc/ctf kernel/fs/dcfs \ 737 etc/system etc/name_to_major etc/path_to_inst \ 738 etc/name_to_sysnum | cpio -pdum $DST 2> /dev/null 739 fi 740 ) 741} 742 743root_is_ramdisk() 744{ 745 grep -v "set root_is_ramdisk=" "$UNPACKED_ROOT"/etc/system | \ 746 grep -v "set ramdisk_size=" > /tmp/system.$$ 747 cat /tmp/system.$$ > "$UNPACKED_ROOT"/etc/system 748 rm /tmp/system.$$ 749 750 echo set root_is_ramdisk=1 >> "$UNPACKED_ROOT"/etc/system 751 echo set ramdisk_size=$1 >> "$UNPACKED_ROOT"/etc/system 752} 753 754pack() 755{ 756 MR="$1" 757 [ -d "$UNPACKED_ROOT" ] || usage 758 759 # always compress if fiocompress exists 760 # 761 if [ -x /usr/sbin/fiocompress ] ; then 762 COMPRESS=true 763 fi 764 765 # Estimate image size and add %10 overhead for ufs stuff. 766 # Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem, 767 # e.g. zfs, in which the disk usage is less than the sum of the file 768 # sizes. The nawk code 769 # 770 # {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7} 771 # 772 # below rounds up the size of a file/directory, in bytes, to the 773 # next multiple of 1024. This mimics the behavior of ufs especially 774 # with directories. This results in a total size that's slightly 775 # bigger than if du was called on a ufs directory. 776 # 777 # if the operation in turn is compressing the files the amount 778 # of typical shrinkage is used to come up with a useful archive 779 # size 780 size=$(find "$UNPACKED_ROOT" -ls | nawk ' 781 {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7} 782 END {print int(t * 1.10 / 1024)}') 783 if [ "$COMPRESS" = true ] ; then 784 size=`echo $size | nawk '{s = $1} END {print int(s * 0.6)}'` 785 fi 786 787 /usr/sbin/mkfile ${size}k "$TMR" 788 789 LOFIDEV=`/usr/sbin/lofiadm -a "$TMR"` 790 if [ $? != 0 ] ; then 791 echo lofi plumb failed 792 exit 2 793 fi 794 795 RLOFIDEV=`echo $LOFIDEV | sed s/lofi/rlofi/` 796 newfs $RLOFIDEV < /dev/null 2> /dev/null 797 mkdir -p $MNT 798 mount -o nologging $LOFIDEV $MNT 799 rmdir $MNT/lost+found 800 801 if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then 802 root_is_ramdisk $size 803 fi 804 805 ( 806 cd "$UNPACKED_ROOT" 807 if [ "$COMPRESS" = true ] ; then 808 compress . $MNT 809 else 810 find . -print | cpio -pdum $MNT 2> /dev/null 811 fi 812 ) 813 lockfs -f $MNT 814 umount $MNT 815 rmdir $MNT 816 817 if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then 818 "$UNPACKED_ROOT/usr/sbin/installboot" \ 819 "$UNPACKED_ROOT/platform/sun4u/lib/fs/ufs/bootblk" \ 820 $RLOFIDEV 821 fi 822 823 lofiadm -d $LOFIDEV 824 LOFIDEV= 825 826 rm -f "$TMR.gz" 827 828 if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then 829 mv "$TMR" "$MR" 830 else 831 gzip -f "$TMR" 832 mv "$TMR.gz" "$MR" 833 fi 834 835 chmod a+r "$MR" 836} 837 838strip_amd64() 839{ 840 find "$UNPACKED_ROOT" -name amd64 -type directory | xargs rm -rf 841} 842 843# main 844# 845 846EXTRA_SPACE=0 847STRIP_AMD64= 848COMPRESS= 849 850PATH=/usr/sbin:/usr/bin:/opt/sfw/bin ; export PATH 851 852while getopts s:6c opt ; do 853 case $opt in 854 s) EXTRA_SPACE="$OPTARG" 855 ;; 856 6) STRIP_AMD64=false 857 ;; 858 c) COMPRESS=true 859 ;; 860 *) usage 861 ;; 862 esac 863done 864shift `expr $OPTIND - 1` 865 866[ $# == 3 ] || usage 867 868UNPACKED_ROOT="$3" 869BASE="`pwd`" 870MNT=/tmp/mnt$$ 871TMR=/tmp/mr$$ 872LOFIDEV= 873MR="$2" 874 875# sanity check 876[ "$UNPACKED_ROOT" != "/" ] || usage 877 878if [ "`dirname $MR`" = . ] ; then 879 MR="$BASE/$MR" 880fi 881if [ "`dirname $UNPACKED_ROOT`" = . ] ; then 882 UNPACKED_ROOT="$BASE/$UNPACKED_ROOT" 883fi 884 885 886MEDIA="$MR" 887 888trap cleanup EXIT 889 890# always unpack into a fresh root 891case $1 in 892 unpack|unpackmedia) 893 rm -rf "$UNPACKED_ROOT" 894 mkdir -p "$UNPACKED_ROOT" 895 ;; 896esac 897[ -d "$UNPACKED_ROOT" ] || usage 898 899case $1 in 900 packmedia) 901 packmedia "$MEDIA" "$UNPACKED_ROOT" 902 if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then 903 pack "$MEDIA/boot/sparc.miniroot" 904 else 905 pack "$MEDIA/boot/x86.miniroot" 906 fi 907 908 ;; 909 unpackmedia) 910 if [ -f "$MEDIA/boot/sparc.miniroot" ] ; then 911 unpack "$MEDIA/boot/sparc.miniroot" 912 else 913 unpack "$MEDIA/boot/x86.miniroot" 914 unpack "$MEDIA/boot/amd64/x86.miniroot" 915 fi 916 unpackmedia "$MEDIA" "$UNPACKED_ROOT" 917 ;; 918 pack) pack "$MR" 919 ;; 920 unpack) unpack "$MR" 921 ;; 922 *) usage 923 ;; 924esac 925