Print this page
    
Modernize CDDL license text and copyrights for OmniTI-original code.
Checkpoint for find-and-install
Generalize rpool to variable RPOOL in disk_help.sh
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/disk_help.sh
          +++ new/disk_help.sh
   1    1  #!/usr/bin/bash
        2 +
   2    3  #
   3      -# CDDL HEADER START
        4 +# This file and its contents are supplied under the terms of the
        5 +# Common Development and Distribution License ("CDDL"), version 1.0.
        6 +# You may only use this file in accordance with the terms of version
        7 +# 1.0 of the CDDL.
   4    8  #
   5      -# The contents of this file are subject to the terms of the
   6      -# Common Development and Distribution License, Version 1.0 only
   7      -# (the "License").  You may not use this file except in compliance
   8      -# with the License.
        9 +# A full copy of the text of the CDDL should have accompanied this
       10 +# source.  A copy of the CDDL is also available via the Internet at
       11 +# http://www.illumos.org/license/CDDL.
   9   12  #
  10      -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  11      -# or http://www.opensolaris.org/os/licensing.
  12      -# See the License for the specific language governing permissions
  13      -# and limitations under the License.
       13 +
  14   14  #
  15      -# When distributing Covered Code, include this CDDL HEADER in each
  16      -# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  17      -# If applicable, add the following below this CDDL HEADER, with the
  18      -# fields enclosed by brackets "[]" replaced with your own identifying
  19      -# information: Portions Copyright [yyyy] [name of copyright owner]
       15 +# Copyright 2017 OmniTI Computer Consulting, Inc.  All rights reserved.
  20   16  #
  21      -# CDDL HEADER END
  22      -#
  23      -#
  24      -# Copyright 2012 OmniTI Computer Consulting, Inc.  All rights reserved.
  25      -# Use is subject to license terms.
  26      -#
       17 +
  27   18  ListDisks() {
  28   19    declare -A disksize
  29   20    declare -A diskname
  30   21    for rdsk in $(prtconf -v | grep dev_link | awk -F= '/\/dev\/rdsk\/c.*p0/{print $2;}')
  31   22    do
  32   23      disk=`echo $rdsk | sed -e 's/.*\///g; s/p0//;'`
  33   24      size=`prtvtoc $rdsk 2>/dev/null | awk '/bytes\/sector/{bps=$2} /sectors\/cylinder/{bpc=bps*$2} /accessible sectors/{print ($2*bps)/1048576;} /accessible cylinders/{print int(($2*bpc)/1048576);}'`
  34   25      disksize+=([$disk]=$size)
  35   26    done
  36   27  
  37   28    disk=""
  38   29    while builtin read diskline
  39   30    do
  40   31      if [[ -n "$disk" ]]; then
  41   32        desc=`echo $diskline | sed -e 's/^[^\<]*//; s/[\<\>]//g;'`
  42   33        diskname+=([$disk]=$desc)
  43   34        disk=""
  44   35      else
  45   36        disk=$diskline
  46   37      fi
  47   38    done < <(format < /dev/null | awk '/^ *[0-9]*\. /{print $2; print;}')
  48   39  
  49   40    for want in $*
  50   41    do
  51   42      for disk in "${!disksize[@]}" ; do
  52   43        case "$want" in
  53   44          \>*)
  54   45              if [[ -n ${disksize[$disk]} && "${disksize[$disk]}" -ge "${want:1}" ]]; then
  55   46                echo $disk
  56   47              fi
  57   48            ;;
  58   49          \<*)
  59   50              if [[ -n ${disksize[$disk]} && "${disksize[$disk]}" -le "${want:1}" ]]; then
  60   51                echo $disk
  61   52              fi
  62   53            ;;
  63   54          *)
  64   55            if [[ "$disk" == "$want" ]]; then
  65   56              echo $disk
  66   57            fi
  67   58            ;;
  68   59        esac
  69   60      done
  70   61  
  71   62      for disk in "${!diskname[@]}" ; do
  72   63        case "$want" in
  73   64          ~*)
  74   65            PAT=${want:1}
  75   66            if [[ -n $(echo ${diskname[$disk]} | egrep -e "$PAT") ]]; then
  76   67              echo $disk
  77   68            fi
  78   69            ;;
  79   70        esac
  80   71      done
  81   72    done
  82   73  }
  83   74  ListDisksAnd() {
  84   75    EXPECT=$(( $(echo "$1" | sed -e 's/[^,]//g;' | wc -c) + 0))
  
    | 
      ↓ open down ↓ | 
    48 lines elided | 
    
      ↑ open up ↑ | 
  
  85   76    for part in $(echo "$1" | sed -e 's/,/ /g;'); do
  86   77      ListDisks $part
  87   78    done | sort | uniq -c | awk '{if($1=='$EXPECT'){print $2;}}'
  88   79  }
  89   80  ListDisksUnique(){
  90   81    for term in $*; do
  91   82      ListDisksAnd $term
  92   83    done | sort | uniq | xargs
  93   84  }
  94   85  
  95      -BuildRpool() {
       86 +BuildRpoolOnly() {
  96   87    ztype=""
  97   88    ztgt=""
  98   89    disks=`ListDisksUnique $*`
  99      -  log "Disks being used for rpool: $disks"
       90 +  log "Disks being used for root pool $RPOOL: $disks"
 100   91    if [[ -z "$disks" ]]; then
 101      -    bomb "No matching disks found to build rpool"
       92 +    bomb "No matching disks found to build root pool $RPOOL"
 102   93    fi
 103   94    rm -f /tmp/kayak-disk-list
 104   95    for i in $disks
 105   96    do
 106   97      if [[ -n "$ztgt" ]]; then
 107   98        ztype="mirror"
 108   99      fi
 109  100      ztgt="$ztgt ${i}"
 110  101      # Keep track of disks for later...
 111  102      echo ${i} >> /tmp/kayak-disk-list
 112  103    done
 113      -  log "zpool destroy rpool (just in case we've been run twice)"
 114      -  zpool destroy rpool 2> /dev/null
 115      -  log "Creating rpool with: zpool create -f rpool $ztype $ztgt"
      104 +  log "zpool destroy $RPOOL (just in case we've been run twice)"
      105 +  zpool destroy $RPOOL 2> /dev/null
      106 +  log "Creating root pool with: zpool create -f $RPOOL $ztype $ztgt"
 116  107    # Just let "zpool create" do its thing. We want GPT disks now.
 117      -  zpool create -f rpool $ztype $ztgt || bomb "Failed to create rpool"
      108 +  zpool create -f $RPOOL $ztype $ztgt || bomb "Failed to create root pool $RPOOL"
      109 +}
      110 +BuildRpool() {
      111 +  BuildRpoolOnly $*
 118  112    BuildBE
 119  113  }
 120  114  GetTargetVolSize() {
 121  115      # Aim for 25% of physical memory (minimum 1G)
 122  116      # prtconf always reports in megabytes
 123  117      local mem=`/usr/sbin/prtconf | /bin/awk '/^Memory size/ { print $3 }'`
 124  118      if [[ $mem -lt 4096 ]]; then
 125  119          local vsize=1
 126  120      else
 127  121          local quart=`echo "scale=1;$mem/4096" | /bin/bc`
 128  122          local vsize=`printf %0.f $quart`
 129  123      fi
 130  124      echo $vsize
 131  125  }    
 132  126  GetRpoolFree() {
 133      -    local zfsavail=`/sbin/zfs list -H -o avail rpool`
      127 +    local zfsavail=`/sbin/zfs list -H -o avail $RPOOL` 
 134  128      if [[ ${zfsavail:(-1)} = "G" ]]; then
 135  129          local avail=`printf %0.f ${zfsavail::-1}`
 136  130      elif [[ ${zfsavail:(-1)} = "T" ]]; then
 137  131          local gigs=`echo "scale=1;${zfsavail::-1}*1024" | /bin/bc`
 138  132          avail=`printf %0.f $gigs`
 139  133      else
 140  134          # If we get here, there's too little space left to be usable
 141  135          avail=0
 142  136      fi
 143  137      echo $avail
 144  138  }
 145  139  MakeSwapDump() {
 146  140      local size=`GetTargetVolSize`
 147  141      local totalvols=""
 148  142      local usable=""
 149  143      local finalsize=""
 150  144      local savecore=""
 151  145  
 152  146      # We're creating both swap and dump volumes of the same size
 153  147      let totalvols=${size}*2
 154  148  
 155  149      # We want at least 10GB left free after swap/dump
 156  150      # If we can't make swap/dump at least 1G each, don't bother
 157  151      let usable=`GetRpoolFree`-10
 158  152      if [[ $usable -lt 2 ]]; then
 159  153          log "Not enough free space for reasonably-sized swap and dump; not creating either."
 160  154          return 0
 161  155      fi
 162  156  
 163  157      # If the total of swap and dump is greater than the usable free space,
  
    | 
      ↓ open down ↓ | 
    20 lines elided | 
    
      ↑ open up ↑ | 
  
 164  158      # make swap and dump each take half but don't enable savecore
 165  159      if [[ $totalvols -ge $usable ]]; then
 166  160          let finalsize=${usable}/2
 167  161          savecore="-n"
 168  162      else
 169  163          finalsize=$size
 170  164          savecore="-y"
 171  165      fi
 172  166  
 173  167      for volname in swap dump; do
 174      -        /sbin/zfs create -V ${finalsize}G rpool/$volname || \
 175      -            bomb "Failed to create rpool/$volname"
      168 +        /sbin/zfs create -V ${finalsize}G $RPOOL/$volname || \
      169 +            bomb "Failed to create $RPOOL/$volname"
 176  170      done
 177      -    printf "/dev/zvol/dsk/rpool/swap\t-\t-\tswap\t-\tno\t-\n" >> $ALTROOT/etc/vfstab
 178      -    Postboot /usr/sbin/dumpadm $savecore -d /dev/zvol/dsk/rpool/dump
      171 +    printf "/dev/zvol/dsk/$RPOOL/swap\t-\t-\tswap\t-\tno\t-\n" >> $ALTROOT/etc/vfstab
      172 +    Postboot /usr/sbin/dumpadm $savecore -d /dev/zvol/dsk/$RPOOL/dump
 179  173      return 0
 180  174  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX