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
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.
15 # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
21 for rdsk
in $
(prtconf
-v |
grep dev_link |
awk -F= '/\/dev\/rdsk\/c.*p0/{print $2;}')
23 disk
=`echo $rdsk | sed -e 's/.*\///g; s/p0//;'`
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);}'`
25 disksize
+=([$disk]=$size)
29 while builtin read diskline
31 if [[ -n "$disk" ]]; then
32 desc
=`echo $diskline | sed -e 's/^[^\<]*//; s/[\<\>]//g;'`
33 diskname
+=([$disk]=$desc)
38 done < <(format
< /dev
/null |
awk '/^ *[0-9]*\. /{print $2; print;}')
42 for disk
in "${!disksize[@]}" ; do
45 if [[ -n ${disksize[$disk]} && "${disksize[$disk]}" -ge "${want:1}" ]]; then
50 if [[ -n ${disksize[$disk]} && "${disksize[$disk]}" -le "${want:1}" ]]; then
55 if [[ "$disk" == "$want" ]]; then
62 for disk
in "${!diskname[@]}" ; do
66 if [[ -n $
(echo ${diskname[$disk]} |
egrep -e "$PAT") ]]; then
75 EXPECT
=$
(( $
(echo "$1" |
sed -e 's/[^,]//g;' |
wc -c) + 0))
76 for part
in $
(echo "$1" |
sed -e 's/,/ /g;'); do
78 done |
sort |
uniq -c |
awk '{if($1=='$EXPECT'){print $2;}}'
83 done |
sort |
uniq |
xargs
89 disks
=`ListDisksUnique $*`
90 log
"Disks being used for root pool $RPOOL: $disks"
91 if [[ -z "$disks" ]]; then
92 bomb
"No matching disks found to build root pool $RPOOL"
94 rm -f /tmp
/kayak-disk-list
97 if [[ -n "$ztgt" ]]; then
101 # Keep track of disks for later...
102 echo ${i} >> /tmp
/kayak-disk-list
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"
107 # Just let "zpool create" do its thing. We want GPT disks now.
108 zpool create
-f $RPOOL $ztype $ztgt || bomb
"Failed to create root pool $RPOOL"
115 # Aim for 25% of physical memory (minimum 1G)
116 # prtconf always reports in megabytes
117 local mem
=`/usr/sbin/prtconf | /bin/awk '/^Memory size/ { print $3 }'`
118 if [[ $mem -lt 4096 ]]; then
121 local quart
=`echo "scale=1;$mem/4096" | /bin/bc`
122 local vsize
=`printf %0.f $quart`
127 local zfsavail
=`/sbin/zfs list -H -o avail $RPOOL`
128 if [[ ${zfsavail:(-1)} = "G" ]]; then
129 local avail
=`printf %0.f ${zfsavail::-1}`
130 elif [[ ${zfsavail:(-1)} = "T" ]]; then
131 local gigs
=`echo "scale=1;${zfsavail::-1}*1024" | /bin/bc`
132 avail
=`printf %0.f $gigs`
134 # If we get here, there's too little space left to be usable
140 local size
=`GetTargetVolSize`
146 # We're creating both swap and dump volumes of the same size
147 let totalvols
=${size}*2
149 # We want at least 10GB left free after swap/dump
150 # If we can't make swap/dump at least 1G each, don't bother
151 let usable
=`GetRpoolFree`-10
152 if [[ $usable -lt 2 ]]; then
153 log
"Not enough free space for reasonably-sized swap and dump; not creating either."
157 # If the total of swap and dump is greater than the usable free space,
158 # make swap and dump each take half but don't enable savecore
159 if [[ $totalvols -ge $usable ]]; then
160 let finalsize
=${usable}/2
161 savecore
="DUMPADM_ENABLE=no"
164 savecore
="DUMPADM_ENABLE=yes"
167 /sbin
/zfs create
-o volblocksize
=4k
-V ${finalsize}G
$RPOOL/swap || \
168 bomb
"Failed to create $RPOOL/swap"
169 /sbin
/zfs create
-V ${finalsize}G
$RPOOL/dump || \
170 bomb
"Failed to create $RPOOL/dump"
171 printf "/dev/zvol/dsk/$RPOOL/swap\t-\t-\tswap\t-\tno\t-\n" >> $ALTROOT/etc
/vfstab
172 printf "DUMPADM_DEVICE=/dev/zvol/dsk/${RPOOL}/dump\n${savecore}\n" > $ALTROOT/etc
/dumpadm.conf
173 # we're already compressing rpool, no point making savecore compress also
174 printf "DUMPADM_CSAVE=off\n" >> $ALTROOT/etc
/dumpadm.conf