Print this page
XXX Remove nawk(1)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/brand/solaris10/zone/common.ksh
+++ new/usr/src/lib/brand/solaris10/zone/common.ksh
1 1 #
2 2 # CDDL HEADER START
3 3 #
4 4 # The contents of this file are subject to the terms of the
5 5 # Common Development and Distribution License (the "License").
6 6 # You may not use this file except in compliance with the License.
7 7 #
8 8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 # or http://www.opensolaris.org/os/licensing.
10 10 # See the License for the specific language governing permissions
11 11 # and limitations under the License.
12 12 #
13 13 # When distributing Covered Code, include this CDDL HEADER in each
14 14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 # If applicable, add the following below this CDDL HEADER, with the
16 16 # fields enclosed by brackets "[]" replaced with your own identifying
17 17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 18 #
19 19 # CDDL HEADER END
20 20 #
21 21 #
22 22 # Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 # Use is subject to license terms.
24 24 #
25 25
26 26 unset LD_LIBRARY_PATH
27 27 PATH=/usr/bin:/usr/sbin
28 28 export PATH
29 29
30 30 . /usr/lib/brand/shared/common.ksh
31 31
32 32 # Values for service tags.
33 33 STCLIENT=/usr/bin/stclient
34 34 ST_PRODUCT_NAME="Solaris 10 Containers"
35 35 ST_PRODUCT_REV="1.0"
36 36 ST_PRODUCT_UUID="urn:uuid:2f459121-dec7-11de-9af7-080020a9ed93"
37 37
38 38 w_sanity_detail=$(gettext " WARNING: Skipping image sanity checks.")
39 39 f_sanity_detail=$(gettext "Missing %s at %s")
40 40 f_sanity_sparse=$(gettext "Is this a sparse zone image? The image must be whole-root.")
41 41 f_sanity_vers=$(gettext "The image release version must be 10 (got %s), the zone is not usable on this system.")
42 42 f_not_s10_image=$(gettext "%s doesn't look like a Solaris 10 image.")
43 43 f_sanity_nopatch=$(gettext "Unable to determine the image's patch level.")
44 44 f_sanity_downrev=$(gettext "The image patch level is downrev for running in a solaris10 branded zone.\n(patchlist %s)")
45 45 f_need_newer_emul=$(gettext "The image requires a newer version of the solaris10 brand emulation.")
46 46 f_zfs_create=$(gettext "Unable to create the zone's ZFS dataset.")
47 47 f_no_ds=$(gettext "No zonepath dataset; the zonepath must be a ZFS dataset.")
48 48 f_multiple_ds=$(gettext "Multiple active datasets.")
49 49 f_no_active_ds=$(gettext "No active dataset; the zone's ZFS root dataset must be configured as\n\ta zone boot environment.")
50 50 f_zfs_unmount=$(gettext "Unable to unmount the zone's root ZFS dataset (%s).\nIs there a global zone process inside the zone root?\nThe current zone boot environment will remain mounted.\n")
51 51 f_zfs_mount=$(gettext "Unable to mount the zone's ZFS dataset.")
52 52 incompat_options=$(gettext "mutually exclusive options.\n%s")
53 53
54 54 sanity_ok=$(gettext " Sanity Check: Passed. Looks like a Solaris 10 image.")
55 55 sanity_fail=$(gettext " Sanity Check: FAILED (see log for details).")
56 56
57 57 e_badboot=$(gettext "Zone boot failed")
58 58 e_nosingleuser=$(gettext "ERROR: zone did not finish booting to single-user.")
59 59 e_unconfig=$(gettext "sys-unconfig failed")
60 60 v_unconfig=$(gettext "Performing zone sys-unconfig")
61 61
62 62 v_no_tags=$(gettext "Service tags facility not present.")
63 63 e_bad_uuid=$(gettext "Failed to get zone UUID")
64 64 v_addtag=$(gettext "Adding service tag: %s")
65 65 v_deltag=$(gettext "Removing service tag: %s")
66 66 e_addtag_fail=$(gettext "Adding service tag failed (error: %s)")
67 67
68 68 sanity_check()
69 69 {
70 70 typeset dir="$1"
71 71 res=0
72 72
73 73 #
74 74 # Check for some required directories and make sure this isn't a
75 75 # sparse zone image.
76 76 #
77 77 checks="etc etc/svc var var/svc"
78 78 for x in $checks; do
79 79 if [[ ! -e $dir/$x ]]; then
80 80 log "$f_sanity_detail" "$x" "$dir"
81 81 res=1
82 82 fi
83 83 done
84 84 # Files from SUNWcsr and SUNWcsu that are in sparse inherit-pkg-dirs.
85 85 checks="lib/svc sbin/zonename usr/bin/chmod"
86 86 for x in $checks; do
87 87 if [[ ! -e $dir/$x ]]; then
88 88 log "$f_sanity_detail" "$x" "$dir"
89 89 log "$f_sanity_sparse"
90 90 res=1
91 91 fi
92 92 done
93 93
94 94 if (( $res != 0 )); then
95 95 log "$sanity_fail"
96 96 fatal "$install_fail" "$ZONENAME"
97 97 fi
98 98
↓ open down ↓ |
98 lines elided |
↑ open up ↑ |
99 99 if [[ "$SANITY_SKIP" == 1 ]]; then
100 100 log "$w_sanity_detail"
101 101 return
102 102 fi
103 103
104 104 #
105 105 # Check image release to be sure its S10.
106 106 #
107 107 image_vers="unknown"
108 108 if [[ -f $dir/var/sadm/system/admin/INST_RELEASE ]]; then
109 - image_vers=$(nawk -F= '{if ($1 == "VERSION") print $2}' \
109 + image_vers=$(/usr/xpg4/bin/awk -F= '{if ($1 == "VERSION") print $2}' \
110 110 $dir/var/sadm/system/admin/INST_RELEASE)
111 111 fi
112 112
113 113 if [[ "$image_vers" != "10" ]]; then
114 114 log "$f_sanity_vers" "$image_vers"
115 115 res=1
116 116 fi
117 117
118 118 #
119 119 # Make sure we have the minimal KU patch we support. These are the
120 120 # KUs for S10u8.
121 121 #
122 122 if [[ $(uname -p) == "i386" ]]; then
123 123 req_patch="141445-09"
124 124 else
125 125 req_patch="141444-09"
126 126 fi
127 127
128 128 for i in $dir/var/sadm/pkg/SUNWcakr*
129 129 do
130 130 if [[ ! -d $i || ! -f $i/pkginfo ]]; then
131 131 log "$f_sanity_nopatch"
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
132 132 res=1
133 133 fi
134 134 done
135 135
136 136 #
137 137 # Check the core kernel pkg for the required KU patch.
138 138 #
139 139 found=0
140 140 for i in $dir/var/sadm/pkg/SUNWcakr*/pkginfo
141 141 do
142 - patches=$(nawk -F= '{if ($1 == "PATCHLIST") print $2}' $i)
142 + patches=$(/usr/xpg4/bin/awk -F= '{if ($1 == "PATCHLIST") print $2}' $i)
143 143 for patch in $patches
144 144 do
145 145 if [[ $patch == $req_patch ]]; then
146 146 found=1
147 147 break
148 148 fi
149 149 done
150 150
151 151 if (( $found == 1 )); then
152 152 break
153 153 fi
154 154 done
155 155
156 156 if (( $found != 1 )); then
157 157 log "$f_sanity_downrev" "$patches"
158 158 res=1
159 159 fi
160 160
161 161 #
162 162 # Check the S10 image for a required version of the emulation.
163 163 #
164 164 VERS_FILE=/usr/lib/brand/solaris10/version
165 165 s10vers_needs=0
166 166 if [[ -f $dir/$VERS_FILE ]]; then
167 167 s10vers_needs=$(/usr/bin/egrep -v "^#" $dir/$VERS_FILE)
168 168 fi
169 169
170 170 # Now get the current emulation version.
171 171 emul_vers=$(/usr/bin/egrep -v "^#" $VERS_FILE)
172 172
173 173 # Verify that the emulation can run this version of S10.
174 174 if (( $s10vers_needs > $emul_vers )); then
175 175 log "$f_need_newer_emul"
176 176 res=1
177 177 fi
178 178
179 179 if (( $res != 0 )); then
180 180 log "$sanity_fail"
181 181 fatal "$install_fail" "$ZONENAME"
182 182 fi
183 183
184 184 vlog "$sanity_ok"
185 185 }
186 186
187 187 # Find the active dataset under the zonepath dataset to mount on zonepath/root.
188 188 # $1 ZONEPATH_DS
189 189 get_active_ds() {
190 190 ACTIVE_DS=$1/ROOT/zbe-0
191 191 }
192 192
193 193 #
194 194 # Make sure the active dataset is mounted for the zone.
195 195 #
196 196 mount_active_ds() {
197 197 get_zonepath_ds $zonepath
198 198 get_active_ds $ZONEPATH_DS
199 199
200 200 # If already mounted then we're done.
201 201 mnted=`zfs get -H mounted $ACTIVE_DS | cut -f3`
202 202 [[ $mnted = "yes" ]] && return
203 203
204 204 mount -F zfs $ACTIVE_DS $zonepath/root || fail_fatal "$f_zfs_mount"
205 205 }
206 206
207 207 #
208 208 # Set up ZFS dataset hierarchy for the zone root dataset.
209 209 #
210 210 create_active_ds() {
211 211 # Find the zone's current dataset. This should have been created by
212 212 # zoneadm (or the attach hook).
213 213 get_zonepath_ds $zonepath
214 214
215 215 #
216 216 # We need to tolerate errors while creating the datasets and making the
217 217 # mountpoint, since these could already exist from an attach scenario.
218 218 #
219 219
220 220 /usr/sbin/zfs list -H -o name $ZONEPATH_DS/ROOT >/dev/null 2>&1
221 221 if (( $? != 0 )); then
222 222 /usr/sbin/zfs create -o mountpoint=legacy -o zoned=on \
223 223 $ZONEPATH_DS/ROOT
224 224 if (( $? != 0 )); then
225 225 fail_fatal "$f_zfs_create"
226 226 fi
227 227 else
228 228 /usr/sbin/zfs set mountpoint=legacy $ZONEPATH_DS/ROOT \
229 229 >/dev/null 2>&1
230 230 /usr/sbin/zfs set zoned=on $ZONEPATH_DS/ROOT \
231 231 >/dev/null 2>&1
232 232 fi
233 233
234 234 get_active_ds $ZONEPATH_DS
235 235 zfs list -H -o name $ACTIVE_DS >/dev/null 2>&1
236 236 if (( $? != 0 )); then
237 237 zfs create -o canmount=noauto $ACTIVE_DS
238 238 (( $? != 0 )) && fail_fatal "$f_zfs_create"
239 239 else
240 240 zfs set canmount=noauto $ACTIVE_DS >/dev/null 2>&1
241 241 zfs inherit mountpoint $ACTIVE_DS >/dev/null 2>&1
242 242 zfs inherit zoned $ACTIVE_DS >/dev/null 2>&1
243 243 fi
244 244
245 245 if [ ! -d $ZONEROOT ]; then
246 246 /usr/bin/mkdir -m 0755 -p $ZONEROOT || \
247 247 fail_fatal "$f_mkdir" "$ZONEROOT"
248 248 fi
249 249 /usr/bin/chmod 700 $ZONEPATH || fail_fatal "$f_chmod" "$ZONEPATH"
250 250
251 251 mount -F zfs $ACTIVE_DS $ZONEROOT || fail_fatal "$f_zfs_mount"
252 252 }
253 253
254 254 #
255 255 # Before booting the zone we may need to create a few mnt points, just in
256 256 # case they don't exist for some reason.
257 257 #
258 258 # Whenever we reach into the zone while running in the global zone we
259 259 # need to validate that none of the interim directories are symlinks
260 260 # that could cause us to inadvertently modify the global zone.
261 261 #
262 262 mk_zone_dirs() {
263 263 vlog "$v_mkdirs"
264 264 if [[ ! -f $ZONEROOT/tmp && ! -d $ZONEROOT/tmp ]]; then
265 265 mkdir -m 1777 -p $ZONEROOT/tmp || exit $EXIT_CODE
266 266 fi
267 267 if [[ ! -f $ZONEROOT/var/run && ! -d $ZONEROOT/var/run ]]; then
268 268 mkdir -m 1755 -p $ZONEROOT/var/run || exit $EXIT_CODE
269 269 fi
270 270 if [[ ! -f $ZONEROOT/var/tmp && ! -d $ZONEROOT/var/tmp ]]; then
271 271 mkdir -m 1777 -p $ZONEROOT/var/tmp || exit $EXIT_CODE
272 272 fi
273 273 if [[ ! -h $ZONEROOT/etc && ! -f $ZONEROOT/etc/mnttab ]]; then
274 274 /usr/bin/touch $ZONEROOT/etc/mnttab || exit $EXIT_CODE
275 275 /usr/bin/chmod 444 $ZONEROOT/etc/mnttab || exit $EXIT_CODE
276 276 fi
277 277 if [[ ! -f $ZONEROOT/proc && ! -d $ZONEROOT/proc ]]; then
278 278 mkdir -m 755 -p $ZONEROOT/proc || exit $EXIT_CODE
279 279 fi
280 280 if [[ ! -f $ZONEROOT/dev && ! -d $ZONEROOT/dev ]]; then
281 281 mkdir -m 755 -p $ZONEROOT/dev || exit $EXIT_CODE
282 282 fi
283 283 if [[ ! -h $ZONEROOT/etc && ! -h $ZONEROOT/etc/svc && \
284 284 ! -d $ZONEROOT/etc/svc ]]; then
285 285 mkdir -m 755 -p $ZONEROOT/etc/svc/volatile || exit $EXIT_CODE
286 286 fi
287 287 }
288 288
289 289 #
290 290 # We're sys-unconfig-ing the zone. This will normally halt the zone, however
291 291 # there are problems with sys-unconfig and it can hang when the zone is booted
292 292 # to milestone=none. Sys-unconfig also sometimes hangs halting the zone.
293 293 # Thus, we take some care to workaround these sys-unconfig limitations.
294 294 #
295 295 # On entry we expect the zone to be booted. We use sys-unconfig -R to make it
296 296 # think its working on an alternate root and let the caller halt the zone.
297 297 #
298 298 sysunconfig_zone() {
299 299 /usr/sbin/zlogin -S $ZONENAME /usr/sbin/sys-unconfig -R /./ \
300 300 >/dev/null 2>&1
301 301 if (( $? != 0 )); then
302 302 error "$e_unconfig"
303 303 return 1
304 304 fi
305 305
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
306 306 return 0
307 307 }
308 308
309 309 #
310 310 # Get zone's uuid for service tag.
311 311 #
312 312 get_inst_uuid()
313 313 {
314 314 typeset ZONENAME="$1"
315 315
316 - ZONEUUID=`zoneadm -z $ZONENAME list -p | nawk -F: '{print $5}'`
316 + ZONEUUID=`zoneadm -z $ZONENAME list -p | /usr/xpg4/bin/awk -F: '{print $5}'`
317 317 [[ $? -ne 0 || -z $ZONEUUID ]] && return 1
318 318
319 319 INSTANCE_UUID="urn:st:${ZONEUUID}"
320 320 return 0
321 321 }
322 322
323 323 #
324 324 # Add a service tag for a given zone. We use two UUIDs-- the first,
325 325 # the Product UUID, comes from the Sun swoRDFish ontology. The second
326 326 # is the UUID of the zone itself, which forms the instance UUID.
327 327 #
328 328 add_svc_tag()
329 329 {
330 330 typeset ZONENAME="$1"
331 331 typeset SOURCE="$2"
332 332
333 333 if [ ! -x $STCLIENT ]; then
334 334 vlog "$v_no_tags"
335 335 return 0
336 336 fi
337 337
338 338 get_inst_uuid "$ZONENAME" || (error "$e_bad_uuid"; return 1)
339 339
340 340 vlog "$v_addtag" "$INSTANCE_UUID"
341 341 $STCLIENT -a \
342 342 -p "$ST_PRODUCT_NAME" \
343 343 -e "$ST_PRODUCT_REV" \
344 344 -t "$ST_PRODUCT_UUID" \
345 345 -i "$INSTANCE_UUID" \
346 346 -P "none" \
347 347 -m "Sun" \
348 348 -A `uname -p` \
349 349 -z "$ZONENAME" \
350 350 -S "$SOURCE" >/dev/null 2>&1
351 351
352 352 err=$?
353 353
354 354 # 226 means "duplicate record," which we can ignore.
355 355 if [[ $err -ne 0 && $err -ne 226 ]]; then
356 356 error "$e_addtag_fail" "$err"
357 357 return 1
358 358 fi
359 359 return 0
360 360 }
361 361
362 362 #
363 363 # Remove a service tag for a given zone.
364 364 #
365 365 del_svc_tag()
366 366 {
367 367 typeset ZONENAME="$1"
368 368
369 369 if [ ! -x $STCLIENT ]; then
370 370 vlog "$v_no_tags"
371 371 return 0
372 372 fi
373 373
374 374 get_inst_uuid "$ZONENAME" || (error "$e_bad_uuid"; return 1)
375 375
376 376 vlog "$v_deltag" "$INSTANCE_UUID"
377 377 $STCLIENT -d -i "$INSTANCE_UUID" >/dev/null 2>&1
378 378 return 0
379 379 }
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX