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
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.
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]
24 # Copyright 2012 OmniTI Computer Consulting, Inc. All rights reserved.
25 # Use is subject to license terms.
30 for rdsk
in $
(prtconf
-v |
grep dev_link |
awk -F= '/\/dev\/rdsk\/c.*p0/{print $2;}')
32 disk
=`echo $rdsk | sed -e 's/.*\///g; s/p0//;'`
33 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 disksize
+=([$disk]=$size)
38 while builtin read diskline
40 if [[ -n "$disk" ]]; then
41 desc
=`echo $diskline | sed -e 's/^[^\<]*//; s/[\<\>]//g;'`
42 diskname
+=([$disk]=$desc)
47 done < <(format
< /dev
/null |
awk '/^ *[0-9]*\. /{print $2; print;}')
51 for disk
in "${!disksize[@]}" ; do
54 if [[ -n ${disksize[$disk]} && "${disksize[$disk]}" -ge "${want:1}" ]]; then
59 if [[ -n ${disksize[$disk]} && "${disksize[$disk]}" -le "${want:1}" ]]; then
64 if [[ "$disk" == "$want" ]]; then
71 for disk
in "${!diskname[@]}" ; do
75 if [[ -n $
(echo ${diskname[$disk]} |
egrep -e "$PAT") ]]; then
84 EXPECT
=$
(( $
(echo "$1" |
sed -e 's/[^,]//g;' |
wc -c) + 0))
85 for part
in $
(echo "$1" |
sed -e 's/,/ /g;'); do
87 done |
sort |
uniq -c |
awk '{if($1=='$EXPECT'){print $2;}}'
92 done |
sort |
uniq |
xargs
98 disks
=`ListDisksUnique $*`
99 log
"Disks being used for root pool $RPOOL: $disks"
100 if [[ -z "$disks" ]]; then
101 bomb
"No matching disks found to build root pool $RPOOL"
103 rm -f /tmp
/kayak-disk-list
106 if [[ -n "$ztgt" ]]; then
110 # Keep track of disks for later...
111 echo ${i} >> /tmp
/kayak-disk-list
113 log
"zpool destroy $RPOOL (just in case we've been run twice)"
114 zpool destroy
$RPOOL 2> /dev
/null
115 log
"Creating root pool with: zpool create -f $RPOOL $ztype $ztgt"
116 # Just let "zpool create" do its thing. We want GPT disks now.
117 zpool create
-f $RPOOL $ztype $ztgt || bomb
"Failed to create root pool $RPOOL"
124 # Aim for 25% of physical memory (minimum 1G)
125 # prtconf always reports in megabytes
126 local mem
=`/usr/sbin/prtconf | /bin/awk '/^Memory size/ { print $3 }'`
127 if [[ $mem -lt 4096 ]]; then
130 local quart
=`echo "scale=1;$mem/4096" | /bin/bc`
131 local vsize
=`printf %0.f $quart`
136 local zfsavail
=`/sbin/zfs list -H -o avail $RPOOL`
137 if [[ ${zfsavail:(-1)} = "G" ]]; then
138 local avail
=`printf %0.f ${zfsavail::-1}`
139 elif [[ ${zfsavail:(-1)} = "T" ]]; then
140 local gigs
=`echo "scale=1;${zfsavail::-1}*1024" | /bin/bc`
141 avail
=`printf %0.f $gigs`
143 # If we get here, there's too little space left to be usable
149 local size
=`GetTargetVolSize`
155 # We're creating both swap and dump volumes of the same size
156 let totalvols
=${size}*2
158 # We want at least 10GB left free after swap/dump
159 # If we can't make swap/dump at least 1G each, don't bother
160 let usable
=`GetRpoolFree`-10
161 if [[ $usable -lt 2 ]]; then
162 log
"Not enough free space for reasonably-sized swap and dump; not creating either."
166 # If the total of swap and dump is greater than the usable free space,
167 # make swap and dump each take half but don't enable savecore
168 if [[ $totalvols -ge $usable ]]; then
169 let finalsize
=${usable}/2
176 for volname
in swap dump
; do
177 /sbin
/zfs create
-V ${finalsize}G
$RPOOL/$volname || \
178 bomb
"Failed to create $RPOOL/$volname"
180 printf "/dev/zvol/dsk/$RPOOL/swap\t-\t-\tswap\t-\tno\t-\n" >> $ALTROOT/etc
/vfstab
181 Postboot
/usr
/sbin
/dumpadm
$savecore -d /dev
/zvol
/dsk
/$RPOOL/dump