Print this page
    
Remove extraneous OmniTI copyright
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/boot/scripts/root_archive.ksh
          +++ new/usr/src/cmd/boot/scripts/root_archive.ksh
   1    1  #!/bin/ksh -p
   2    2  #
   3    3  # CDDL HEADER START
   4    4  #
   5    5  # The contents of this file are subject to the terms of the
   6    6  # Common Development and Distribution License (the "License").
   7    7  # You may not use this file except in compliance with the License.
   8    8  #
   9    9  # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10   10  # or http://www.opensolaris.org/os/licensing.
  11   11  # See the License for the specific language governing permissions
  12   12  # and limitations under the License.
  13   13  #
  14   14  # When distributing Covered Code, include this CDDL HEADER in each
  
    | 
      ↓ open down ↓ | 
    14 lines elided | 
    
      ↑ open up ↑ | 
  
  15   15  # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16  # If applicable, add the following below this CDDL HEADER, with the
  17   17  # fields enclosed by brackets "[]" replaced with your own identifying
  18   18  # information: Portions Copyright [yyyy] [name of copyright owner]
  19   19  #
  20   20  # CDDL HEADER END
  21   21  #
  22   22  
  23   23  # Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24   24  # Use is subject to license terms.
  25      -# Copyright 2012 OmniTI Computer Consulting, Inc.  All rights reserved.
  26   25  #
  27   26  # Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  28   27  
  29   28  # utility to pack and unpack a boot/root archive
  30   29  # both ufs and hsfs (iso9660) format archives are unpacked
  31   30  # only ufs archives are generated
  32   31  #
  33   32  # usage: pack   <archive> <root>
  34   33  #        unpack <archive> <root>
  35   34  #
  36   35  #   Where <root> is the directory to unpack to and will be cleaned out
  37   36  #   if it exists.
  38   37  #
  39   38  
  40   39  usage()
  41   40  {
  42   41          printf "usage: root_archive pack <archive> <root>\n"
  43   42          printf "       root_archive unpack <archive> <root>\n"
  44   43          exit 1
  45   44  }
  46   45  
  47   46  cleanup()
  48   47  {
  49   48          if [ -d $MNT ] ; then
  50   49                  umount $MNT 2> /dev/null
  51   50                  rmdir $MNT
  52   51          fi
  53   52  
  54   53          lofiadm -d "$TMR" 2>/dev/null
  55   54          if [ "$REALTHING" != true ] ; then
  56   55                  rm -f "$TMR"
  57   56          fi
  58   57          rm -f "$TMR.gz"
  59   58          rm -f /tmp/flist$$
  60   59  }
  61   60  
  62   61  do_unpack()
  63   62  {
  64   63          (
  65   64                  cd $MNT
  66   65                  find . -print | cpio -pdum "$UNPACKED_ROOT" 2> /dev/null
  67   66          )
  68   67          # increase the chances the unmount will succeed
  69   68          umount -f $MNT
  70   69  }
  71   70  
  72   71  unpack()
  73   72  {
  74   73          MR=$1
  75   74          if [ ! -f "$MR" ] ; then
  76   75                  printf "$MR: not found\n"
  77   76                  usage
  78   77          fi
  79   78  
  80   79          if [ `uname -i` = i86pc ] ; then
  81   80                  gzcat "$MR" > $TMR
  82   81          else
  83   82                  REALTHING=true ; export REALTHING
  84   83                  TMR="$MR"
  85   84          fi
  86   85  
  87   86          LOFIDEV=`/usr/sbin/lofiadm -a $TMR`
  88   87          if [ $? != 0 ] ; then
  89   88                  echo lofi plumb failed
  90   89                  exit 2
  91   90          fi
  92   91  
  93   92          mkdir -p $MNT
  94   93  
  95   94          FSTYP=`fstyp $LOFIDEV`
  96   95  
  97   96          if [ "$FSTYP" = ufs ] ; then
  98   97                  /usr/sbin/mount -o ro,nologging $LOFIDEV $MNT
  99   98                  do_unpack
 100   99          elif [ "$FSTYP" = hsfs ] ; then
 101  100                  /usr/sbin/mount -F hsfs -o ro $LOFIDEV $MNT
 102  101                  do_unpack
 103  102          else
 104  103                  printf "invalid root archive\n"
 105  104          fi
 106  105  
 107  106  
 108  107          rmdir $MNT
 109  108          lofiadm -d $TMR ; LOFIDEV=
 110  109          if [ "$REALTHING" != true ] ; then
 111  110                  rm $TMR
 112  111          fi
 113  112  }
 114  113  
 115  114  compress()
 116  115  {
 117  116          SRC=$1
 118  117          DST=$2
 119  118  
 120  119          (
 121  120                  cd $SRC
 122  121                  filelist=`find .`
 123  122  
 124  123                  for file in $filelist ; do
 125  124  
 126  125                          file=`echo $file | sed s#^./##`
 127  126  
 128  127                          # copy all files over to preserve hard links
 129  128                          #
 130  129                          echo $file | cpio -pdum $DST 2> /dev/null
 131  130  
 132  131                          if [ -f $file ] && [ -s $file ] && [ ! -h $file ] ; then
 133  132                                  fiocompress -mc $file $DST/$file &
 134  133                          fi
 135  134  
 136  135                  done
 137  136  
 138  137                  wait `pgrep fiocompress`
 139  138  
 140  139                  # now re-copy a couple of uncompressed files
 141  140  
 142  141                  if [ -d "$SRC/platform/i86pc" ] ; then
 143  142                          find `cat boot/solaris/filelist.ramdisk` -type file \
 144  143                              -print 2> /dev/null > /tmp/flist$$
 145  144                          find usr/kernel -type file -print 2> /dev/null \
 146  145                              >> /tmp/flist$$
 147  146                          # some of the files are replaced with links into
 148  147                          # tmp/root on the miniroot, so find the backing files
 149  148                          # from there as well and add them to the list ti
 150  149                          # be copied uncompressed
 151  150                          (
 152  151                                  cd $SRC/tmp/root
 153  152                                  find `cat ../../boot/solaris/filelist.ramdisk` \
 154  153                                      -type file -print 2> /dev/null | \
 155  154                                      sed 's#^#tmp/root/#' >> /tmp/flist$$
 156  155                          )
 157  156                          flist=`cat /tmp/flist$$`
 158  157                          (
 159  158                                  cd $DST
 160  159                                  rm -f $flist
 161  160                          )
 162  161                          for file in $flist ; do
 163  162                                  echo $file | cpio -pdum $DST 2> /dev/null
 164  163                          done
 165  164                  else
 166  165                          find kernel platform -name unix | \
 167  166                              cpio -pdum $DST 2> /dev/null
 168  167                          find kernel platform -name genunix | cpio -pdum $DST \
 169  168                              2> /dev/null
 170  169                          find kernel platform -name platmod | cpio -pdum $DST \
 171  170                              2> /dev/null
 172  171                          find `find kernel platform -name cpu` | \
 173  172                              cpio -pdum $DST 2> /dev/null
 174  173                          find `find kernel platform -name kmdb\*` | \
 175  174                                  cpio -pdum $DST 2> /dev/null
 176  175                          find kernel/misc/sparcv9/ctf kernel/fs/sparcv9/dcfs \
 177  176                              etc/system etc/name_to_major etc/path_to_inst \
 178  177                              etc/name_to_sysnum  etc/driver_aliases \
 179  178                              etc/driver_classes etc/minor_perm | \
 180  179                              cpio -pdum $DST 2> /dev/null
 181  180                  fi
 182  181          )
 183  182  }
 184  183  
 185  184  root_is_ramdisk()
 186  185  {
 187  186          grep -v "set root_is_ramdisk=" "$UNPACKED_ROOT"/etc/system | \
 188  187              grep -v "set ramdisk_size=" > /tmp/system.$$
 189  188          cat /tmp/system.$$ > "$UNPACKED_ROOT"/etc/system
 190  189          rm /tmp/system.$$
 191  190  
 192  191          echo set root_is_ramdisk=1 >> "$UNPACKED_ROOT"/etc/system
 193  192          echo set ramdisk_size=$1 >> "$UNPACKED_ROOT"/etc/system
 194  193  }
 195  194  
 196  195  pack()
 197  196  {
 198  197          MR="$1"
 199  198          [ -d "$UNPACKED_ROOT" ] || usage
 200  199  
 201  200          # always compress if fiocompress exists
 202  201          #
 203  202          if [ -x /usr/sbin/fiocompress ] ; then
 204  203                  COMPRESS=true
 205  204          fi
 206  205  
 207  206          # Estimate image size and add %10 overhead for ufs stuff.
 208  207          # Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem,
 209  208          # e.g. zfs, in which the disk usage is less than the sum of the file
 210  209          # sizes.  The nawk code
 211  210          #
 212  211          #       {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
 213  212          #
 214  213          # below rounds up the size of a file/directory, in bytes, to the
 215  214          # next multiple of 1024.  This mimics the behavior of ufs especially
 216  215          # with directories.  This results in a total size that's slightly
 217  216          # bigger than if du was called on a ufs directory.
 218  217          #
 219  218          # if the operation in turn is compressing the files the amount
 220  219          # of typical shrinkage is used to come up with a useful archive
 221  220          # size
 222  221          size=$(find "$UNPACKED_ROOT" -ls | nawk '
 223  222              {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
 224  223              END {print int(t * 1.10 / 1024)}')
 225  224          if [ "$COMPRESS" = true ] ; then
 226  225                  size=`echo $size | nawk '{s = $1} END {print int(s * 0.6)}'`
 227  226          fi
 228  227  
 229  228          /usr/sbin/mkfile ${size}k "$TMR"
 230  229  
 231  230          LOFIDEV=`/usr/sbin/lofiadm -a "$TMR"`
 232  231          if [ $? != 0 ] ; then
 233  232                  echo lofi plumb failed
 234  233                  exit 2
 235  234          fi
 236  235  
 237  236          RLOFIDEV=`echo $LOFIDEV | sed s/lofi/rlofi/`
 238  237          newfs $RLOFIDEV < /dev/null 2> /dev/null
 239  238          mkdir -p $MNT
 240  239          mount -o nologging $LOFIDEV $MNT
 241  240          rmdir $MNT/lost+found
 242  241  
 243  242          if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
 244  243                  root_is_ramdisk $size
 245  244          fi
 246  245  
 247  246          (
 248  247                  cd "$UNPACKED_ROOT"
 249  248                  if [ "$COMPRESS" = true ] ; then
 250  249                          compress . $MNT
 251  250                  else
 252  251                          find . -print | cpio -pdum $MNT 2> /dev/null
 253  252                  fi
 254  253          )
 255  254          lockfs -f $MNT
 256  255          umount $MNT
 257  256          rmdir $MNT
 258  257  
 259  258          if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
 260  259                  "$UNPACKED_ROOT/usr/sbin/installboot" \
 261  260                      "$UNPACKED_ROOT/platform/sun4u/lib/fs/ufs/bootblk" \
 262  261                      $RLOFIDEV
 263  262          fi
 264  263  
 265  264          lofiadm -d $LOFIDEV
 266  265          LOFIDEV=
 267  266  
 268  267          rm -f "$TMR.gz"
 269  268  
 270  269          if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
 271  270                  mv "$TMR" "$MR"
 272  271          else
 273  272                  gzip -f "$TMR"
 274  273                  mv "$TMR.gz" "$MR"
 275  274          fi
 276  275  
 277  276          chmod a+r "$MR"
 278  277  }
 279  278  
 280  279  strip_amd64()
 281  280  {
 282  281          find "$UNPACKED_ROOT" -name amd64 -type directory | xargs rm -rf
 283  282  }
 284  283  
 285  284  # main
 286  285  #
 287  286  
 288  287  EXTRA_SPACE=0
 289  288  STRIP_AMD64=
 290  289  COMPRESS=
 291  290  
 292  291  PATH=/usr/sbin:/usr/bin:/opt/sfw/bin ; export PATH
 293  292  
 294  293  while getopts s:6c opt ; do
 295  294          case $opt in
 296  295          s)      EXTRA_SPACE="$OPTARG"
 297  296                  ;;
 298  297          6)      STRIP_AMD64=false
 299  298                  ;;
 300  299          c)      COMPRESS=true
 301  300                  ;;
 302  301          *)      usage
 303  302                  ;;
 304  303          esac
 305  304  done
 306  305  shift `expr $OPTIND - 1`
 307  306  
 308  307  [ $# == 3 ] || usage
 309  308  
 310  309  UNPACKED_ROOT="$3"
 311  310  BASE="`pwd`"
 312  311  MNT=/tmp/mnt$$
 313  312  TMR=/tmp/mr$$
 314  313  LOFIDEV=
 315  314  MR="$2"
 316  315  
 317  316  # sanity check
 318  317  [ "$UNPACKED_ROOT" != "/" ] || usage
 319  318  
 320  319  if [ "`dirname $MR`" = . ] ; then
 321  320          MR="$BASE/$MR"
 322  321  fi
 323  322  if [ "`dirname $UNPACKED_ROOT`" = . ] ; then
 324  323          UNPACKED_ROOT="$BASE/$UNPACKED_ROOT"
 325  324  fi
 326  325  
 327  326  trap cleanup EXIT
 328  327  
 329  328  # always unpack into a fresh root
 330  329  case $1 in
 331  330          unpack)
 332  331                  rm -rf "$UNPACKED_ROOT"
 333  332                  mkdir -p "$UNPACKED_ROOT"
 334  333                  ;;
 335  334  esac
 336  335  [ -d "$UNPACKED_ROOT" ] || usage
 337  336  
 338  337  case $1 in
 339  338          pack)   pack "$MR"
 340  339                  ;;
 341  340          unpack) unpack "$MR"
 342  341                  ;;
 343  342          *)      usage
 344  343                  ;;
 345  344  esac
  
    | 
      ↓ open down ↓ | 
    310 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX