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 2010 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
27 .
/usr
/lib
/brand
/solaris10
/common.ksh
29 m_usage
=$
(gettext "solaris10 brand usage: clone {sourcezone}.")
30 f_nosource
=$
(gettext "Error: unable to determine source zone dataset.")
31 f_sysunconfig
=$
(gettext "Error: sys-unconfig failed.")
33 # Other brand clone options are invalid for this brand.
34 while getopts "R:z:" opt
; do
36 R
) ZONEPATH
="$OPTARG" ;;
37 z
) ZONENAME
="$OPTARG" ;;
38 *) printf "$m_usage\n"
39 exit $ZONE_SUBPROC_USAGE;;
45 fail_usage
"$0 {sourcezone}";
48 ZONEROOT
="$ZONEPATH/root"
51 # Find the active source zone dataset to clone.
52 sourcezonepath
=`/usr/sbin/zonecfg -z $sourcezone info zonepath | \
53 /usr/bin/cut -f2 -d' '`
54 if [ -z "$sourcezonepath" ]; then
55 fail_fatal
"$f_nosource"
58 get_zonepath_ds
$sourcezonepath
59 get_active_ds
$ZONEPATH_DS
63 # Now set up the zone's datasets
67 # First make the top-level dataset.
70 pdir
=`/usr/bin/dirname $ZONEPATH`
71 zpname
=`/usr/bin/basename $ZONEPATH`
76 # Create the datasets.
77 /usr
/sbin
/zfs create
$zpds/$zpname
78 if (( $?
!= 0 )); then
79 fail_fatal
"$f_zfs_create"
82 /usr
/sbin
/zfs create
-o mountpoint
=legacy
-o zoned
=on
$zpds/$zpname/ROOT
83 if (( $?
!= 0 )); then
84 fail_fatal
"$f_zfs_create"
88 SNAPNAME
=${ZONENAME}_snap
90 while [ $SNAPNUM -lt 100 ]; do
91 zfs snapshot
$ACTIVE_SRC@
$SNAPNAME
95 SNAPNUM
=`expr $SNAPNUM + 1`
96 SNAPNAME
="${ZONENAME}_snap$SNAPNUM"
99 if [ $SNAPNUM -ge 100 ]; then
100 fail_fatal
"$f_zfs_create"
104 get_active_ds
$zpds/$zpname
105 zfs clone
-o canmount
=noauto
$ACTIVE_SRC@
$SNAPNAME $ACTIVE_DS
106 (( $?
!= 0 )) && fail_fatal
"$f_zfs_create"
108 if [ ! -d $ZONEROOT ]; then
109 mkdir
-p $ZONEROOT || fail_fatal
"$f_mkdir" "$ZONEROOT"
110 chmod 700 $ZONEPATH || fail_fatal
"$f_chmod" "$ZONEPATH"
113 mount
-F zfs
$ACTIVE_DS $ZONEROOT || fail_fatal
"$f_zfs_mount"
115 # Don't re-sysunconfig if we've already done so
116 if [[ ! -f $ZONEROOT/etc
/.UNCONFIGURED
]]; then
117 /usr
/sbin
/zoneadm
-z $ZONENAME boot
-f -- -m milestone
=none
118 if (( $?
!= 0 )); then
120 fail_incomplete
"$f_sysunconfig"
124 if (( $?
!= 0 )); then
125 /usr
/sbin
/zoneadm
-z $ZONENAME halt
126 fail_incomplete
"$f_sysunconfig"
129 /usr
/sbin
/zoneadm
-z $ZONENAME halt
132 # Add a service tag for this zone.
133 add_svc_tag
"$ZONENAME" "clone $sourcezone"
135 exit $ZONE_SUBPROC_OK