common.ksh revision caaceb365d0f555e83c883de4ea0b4339d8a1eb2
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
unset LD_LIBRARY_PATH
export PATH
# Use the ipkg-brand ZFS property for denoting the zone root's active dataset.
PROP_ACTIVE="org.opensolaris.libbe:active"
f_sanity_vers=$(gettext "The image release version must be 10 (got %s), the zone is not usable on this system.")
f_sanity_downrev=$(gettext "The image patch level is downrev for running in a solaris10 branded zone.\n(patchlist %s)")
f_no_active_ds=$(gettext "No active dataset; the zone's ZFS root dataset must be configured as\n\ta zone boot environment.")
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")
{
typeset dir="$1"
res=0
#
# Check for some required directories and make sure this isn't a
# sparse zone image.
#
if [[ ! -e $dir/$x ]]; then
log "$f_sanity_detail" "$x" "$dir"
res=1
fi
done
# Files from SUNWcsr and SUNWcsu that are in sparse inherit-pkg-dirs.
if [[ ! -e $dir/$x ]]; then
log "$f_sanity_detail" "$x" "$dir"
res=1
fi
done
fi
return
fi
#
# Check image release to be sure its S10.
#
image_vers="unknown"
fi
res=1
fi
#
# Make sure we have the minimal KU patch we support. These are the
# KUs for S10u8.
#
req_patch="141445-09"
else
req_patch="141444-09"
fi
do
res=1
fi
done
#
# Check the core kernel pkg for the required KU patch.
#
found=0
do
do
if [[ $patch == $req_patch ]]; then
found=1
break
fi
done
break
fi
done
res=1
fi
#
# Check the S10 image for a required version of the emulation.
#
if [[ -f $dir/$VERS_FILE ]]; then
fi
# Now get the current emulation version.
# Verify that the emulation can run this version of S10.
res=1
fi
fi
}
# $1 ZONEPATH_DS
-o name,$PROP_ACTIVE $1/ROOT | \
if ($1 ~ /ROOT\/[^\/]+$/ && $2 == "on") {
print $1
if (found == 1)
exit 1
found = 1
}
}'`
if [ $? -ne 0 ]; then
fi
fi
}
#
# Make sure the active dataset is mounted for the zone. There are several
# cases to consider:
# 1) First boot of the zone, nothing is mounted
# 2) Zone is halting, active dataset remains the same.
# 3) Zone is halting, there is a new active dataset to mount.
#
if (( $? == 0 )); then
# Umount current dataset on the root (it might be an old BE).
if (( $? != 0 )); then
# The umount failed, leave the old BE mounted. If
# there are zone processes (i.e. zsched) in the fs,
# then we're umounting because we failed validation
# during boot, otherwise, warn about gz process
# preventing umount.
printf "$f_zfs_unmount" "$zonepath/root"
fi
return
fi
fi
# Mount active dataset on the root.
}
#
# Set up ZFS dataset hierarchy for the zone root dataset.
#
# Find the zone's current dataset. This should have been created by
# zoneadm (or the attach hook).
#
# We need to tolerate errors while creating the datasets and making the
# mountpoint, since these could already exist from an attach scenario.
#
if (( $? != 0 )); then
if (( $? != 0 )); then
fi
else
/usr/sbin/zfs set mountpoint=legacy $ZONEPATH_DS/ROOT \
fi
if (( $? != 0 )); then
$ZONEPATH_DS/ROOT/$BENAME >/dev/null 2>&1
if (( $? != 0 )); then
fi
else
/usr/sbin/zfs set $PROP_ACTIVE=on $ZONEPATH_DS/ROOT/$BENAME \
fi
if [ ! -d $ZONEROOT ]; then
fi
}
#
# Before booting the zone we may need to create a few mnt points, just in
# case they don't exist for some reason.
#
# Whenever we reach into the zone while running in the global zone we
# need to validate that none of the interim directories are symlinks
# that could cause us to inadvertently modify the global zone.
#
mkdir -m 1777 -p $ZONEROOT/tmp || exit $EXIT_CODE
fi
mkdir -m 1755 -p $ZONEROOT/var/run || exit $EXIT_CODE
fi
mkdir -m 1777 -p $ZONEROOT/var/tmp || exit $EXIT_CODE
fi
fi
mkdir -m 755 -p $ZONEROOT/proc || exit $EXIT_CODE
fi
mkdir -m 755 -p $ZONEROOT/dev || exit $EXIT_CODE
fi
fi
}
#
# We're sys-unconfig-ing the zone. This will normally halt the zone, however
# there are problems with sys-unconfig and it can hang when the zone is booted
# to milestone=none. Sys-unconfig also sometimes hangs halting the zone.
# Thus, we take some care to workaround these sys-unconfig limitations.
#
# On entry we expect the zone to be booted. We use sys-unconfig -R to make it
# think its working on an alternate root and let the caller halt the zone.
#
if (( $? != 0 )); then
return 1
fi
return 0
}