5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
26 .
/usr
/lib
/brand
/solaris10
/common.ksh
28 m_attach_log
=$
(gettext "Log File: %s")
29 m_zfs
=$
(gettext "A ZFS file system was created for the zone.")
30 m_attaching
=$
(gettext "Attaching...")
31 m_usage
=$
(gettext "solaris10 brand usage:\n\tattach [-a archive | -d directory | -r recv_type]\n\tThe -a archive option specifies an archive name which can be a flar,\n\ttar, pax or cpio archive.\n\tThe -d directory option specifies an existing directory.\n\tThe -r recv_type option specifies the type of archive to be read from\n\tstdin.")
32 m_complete
=$
(gettext "Attach complete.")
34 install_fail
=$
(gettext "*** Attach FAILED ***")
36 f_n_unimpl
=$
(gettext "The -n option is not yet implemented.")
37 f_zfs
=$
(gettext "Error creating a ZFS file system (%s) for the zone.")
38 f_nodataset
=$
(gettext "Error: there is no ZFS file system for the zone.")
39 f_zfsdestroy
=$
(gettext "Error destroying ZFS file system %s.")
41 f_sanity_notzone
=$
(gettext "Error: this is a system image and not a zone image.")
43 f_baddir
=$
(gettext "Invalid '%s' directory within the zone")
45 # Clean up on interrupt
48 msg
=$
(gettext "Installation cancelled due to interrupt.")
51 # umount any mounted file systems
57 # If the attach failed then clean up the ZFS datasets we created.
60 if [[ $EXIT_CODE != $ZONE_SUBPROC_OK && $rm_ds == 1 ]]; then
61 /usr
/lib
/brand
/solaris10
/uninstall
$ZONENAME $ZONEPATH -F
67 EXIT_CODE
=$ZONE_SUBPROC_USAGE
74 # If we weren't passed at least two arguments, exit now.
75 (( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
79 # XXX shared/common script currently uses lower case zonename & zonepath
83 shift; shift # remove ZONENAME and ZONEPATH from arguments array
85 ZONEROOT
="$ZONEPATH/root"
86 logdir
="$ZONEROOT/var/log"
92 # Other brand attach options are invalid for this brand.
93 while getopts "a:d:nr:" opt
; do
96 if [[ -n "$inst_type" ]]; then
97 fatal
"$incompat_options" "$m_usage"
100 install_media
="$OPTARG"
103 if [[ -n "$inst_type" ]]; then
104 fatal
"$incompat_options" "$m_usage"
106 inst_type
="directory"
107 install_media
="$OPTARG"
108 # '-d -' means use the existing zonepath.
109 if [[ "$install_media" == "$ZONEPATH" ]]; then
115 if [[ -n "$inst_type" ]]; then
116 fatal
"$incompat_options" "$m_usage"
119 install_media
="$OPTARG"
121 ?
) printf "$m_usage\n"
122 exit $ZONE_SUBPROC_USAGE;;
123 *) printf "$m_usage\n"
124 exit $ZONE_SUBPROC_USAGE;;
129 if [[ $noexecute == 1 && -n "$inst_type" ]]; then
133 if [ $noexecute -eq 1 ]; then
135 # The zone doesn't have to exist when the -n option is used, so do
139 # XXX do the sw validation for solaris10 minimal patch level to ensure
140 # everything will be ok.
141 EXIT_CODE
=$ZONE_SUBPROC_NOTCOMPLETE
145 EXIT_CODE
=$ZONE_SUBPROC_NOTCOMPLETE
147 if [[ -z "$inst_type" ]]; then
148 inst_type
="directory"
150 elif [[ "$install_media" != "-" ]]; then
152 # If we're not using a pre-existing zone directory layout then create
153 # the zone datasets and mount them.
156 pdir
=$
(/usr
/bin
/dirname $ZONEPATH)
157 zds
=$
(/usr
/sbin
/zfs list
-H -t filesystem
-o name
$pdir 2>/dev
/null
)
158 if (( $?
== 0 )); then
159 pnm
=$
(/usr
/bin
/basename $ZONEPATH)
160 /usr
/sbin
/zfs create
"$zds/$pnm"
161 if (( $?
== 0 )); then
166 log
"$f_zfs" "$zds/$pnm"
174 # The zone's datasets are now in place, validate that things
175 # are setup correctly.
178 get_zonepath_ds
$zonepath
180 /usr
/sbin
/zfs list
-H -o name
$ZONEPATH_DS/ROOT
>/dev
/null
2>&1
181 (( $?
!= 0 )) && fail_fatal
"$f_no_active_ds"
183 zfs
set mountpoint
=legacy
$ZONEPATH_DS/ROOT
>/dev
/null
2>&1
184 zfs
set zoned
=on
$ZONEPATH_DS/ROOT
>/dev
/null
2>&1
186 get_active_ds
$ZONEPATH_DS
187 zfs list
-H -o name
$ACTIVE_DS >/dev
/null
2>&1
188 (( $?
!= 0 )) && fail_fatal
"$f_zfs_create"
190 zfs
set canmount
=noauto
$ACTIVE_DS >/dev
/null
2>&1
191 zfs inherit mountpoint
$ACTIVE_DS >/dev
/null
2>&1
192 zfs inherit zoned
$ACTIVE_DS >/dev
/null
2>&1
194 if [ ! -d $ZONEROOT ]; then
195 mkdir
-p $ZONEROOT || fail_fatal
"$f_mkdir" "$ZONEROOT"
196 chmod 700 $ZONEPATH || fail_fatal
"$f_chmod" "$ZONEPATH"
199 mnted
=`zfs get -H mounted $ACTIVE_DS | cut -f3`
200 if [[ $mnted = "no" ]]; then
201 mount
-F zfs
$ACTIVE_DS $ZONEROOT || fail_fatal
"$f_zfs_mount"
204 LOGFILE
=$
(/usr
/bin
/mktemp
-t -p /var
/tmp
$zonename.attach_log.XXXXXX
)
205 if [[ -z "$LOGFILE" ]]; then
209 log
"$m_attach_log" "$LOGFILE"
212 install_image
"$inst_type" "$install_media"
217 # Perform a final check that this is really a zone image and not an archive of
218 # a system image which would need p2v. Check for a well-known S10 SMF service
219 # that shouldn't exist in a zone.
221 if [[ -e $ZONEROOT/var
/svc
/manifest
/system
/sysevent.xml
]]; then
222 log
"$f_sanity_notzone"
223 exit $ZONE_SUBPROC_NOTCOMPLETE
226 EXIT_CODE
=$ZONE_SUBPROC_OK
230 zone_logfile
="${logdir}/$zonename.attach$$.log"
234 safe_copy
$LOGFILE $zone_logfile
236 log
"$m_attach_log" "$zone_logfile"
239 exit $ZONE_SUBPROC_OK