p2v.ksh revision edfa49ff6d1bd39465e21e3b28aee863e91c5e3f
#
# 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.
#
# NOTE: this script runs in the global zone and touches the non-global
# zone, so care should be taken to validate any modifications so that they
# are safe.
MSG_PREFIX="p2v: "
usage()
{
echo "$0 [-s] [-m msgprefix] [-u] [-v] [-b patchid]* zonename" >&2
exit $EXIT_CODE
}
# Clean up on interrupt
{
fi
exit $EXIT_CODE
}
#
# For an exclusive stack zone, fix up the network configuration files.
# We need to do this even if unconfiguring the zone so sys-unconfig works
# correctly.
#
fix_net()
{
return
fi
if (( $? != 0 )); then
error "$e_badinfo" "net"
return
fi
for (i = 1; i < NF; i++) {
if ($i == "physical:") {
if (length(net) == 0) {
i++
net = $i
} else {
multiple=1
}
}
}
}
END { if (!multiple)
print net
}')
return
fi
fi
}
#
# Disable all of the shares since the zone cannot be an NFS server.
# SMF service in the fix_smf function.
#
fix_nfs()
{
error "$e_badfile" "/etc/dfs/dfstab"
return
fi
return
fi
if (substr($1, 0, 1) == "#") {
print $0
} else {
print "#", $0
modified=1
}
}
END {
if (modified == 1) {
printf("# Modified by p2v ")
exit 0
}
exit 1
if (( $? == 0 )); then
if [[ ! -f $zonedfs/dfstab.pre_p2v ]]; then
fi
fi
}
#
# Comment out most of the old mounts since they are either unneeded or
# likely incorrect within a zone. Specific mounts can be manually
# reenabled if the corresponding device is added to the zone.
#
{
error "$e_badfile" "/etc/vfstab"
return
fi
return
fi
if (substr($1, 0, 1) == "#") {
print $0
} else if ($1 == "fd" || $1 == "/proc" || $1 == "swap" ||
$1 == "ctfs" || $1 == "objfs" || $1 == "sharefs" ||
$4 == "nfs" || $4 == "lofs") {
print $0
} else {
print "#", $0
modified=1
}
}
END {
if (modified == 1) {
printf("# Modified by p2v ")
exit 0
}
exit 1
if (( $? == 0 )); then
if [[ ! -f $ZONEROOT/etc/vfstab.pre_p2v ]]; then
fi
fi
}
#
# Delete or disable SMF services.
# Zone is booted to milestone=none when this function is called.
#
fix_smf()
{
#
# Delete services that are delivered in hollow pkgs.
#
# Start by getting the svc manifests that are delivered by hollow
# pkgs then use 'svccfg inventory' to get the names of the svcs
# delivered by those manifests. The svc names are saved into a
# temporary file. We then login to the zone and delete them from SMF
# so that the various dependencies also get cleaned up properly.
#
smftmpfile=$(/usr/bin/mktemp -t -p /var/tmp smf.XXXXXX)
return
fi
do
continue
for j in $manifests
do
svcs=$(SVCCFG_NOVALIDATE=1 /usr/sbin/svccfg \
inventory /$j)
do
case $k in
*:default)
# ignore default instance
;;
*)
echo $k >> $smftmpfile
;;
esac
done
done
fi
done
#
# Zone was already booted to milestone=none, wait until SMF door exists.
#
for i in 0 1 2 3 4 5 6 7 8 9
do
[[ -r $ZONEROOT/etc/svc/volatile/repository_door ]] && break
sleep 5
done
then
/usr/bin/rm -f $smftmpfile
return
fi
insttmpfile=$(/usr/bin/mktemp -t -p /var/tmp instsmf.XXXXXX)
/usr/bin/rm -f $smftmpfile
return
fi
# Get a list of the svcs that exist in the zone.
[[ -n $LOGFILE ]] && \
[[ -n $LOGFILE ]] && cat $insttmpfile >&2
for i in $(cat $smftmpfile)
do
# Skip svcs not installed in the zone.
# Delete the svc.
done
/usr/bin/rm -f $smftmpfile
#
# Fix network services if shared stack.
#
NETPHYSDEF="svc:/network/physical:default"
NETPHYSNWAM="svc:/network/physical:nwam"
if (( $? == 0 )); then
/usr/sbin/svcadm enable $NETPHYSDEF || \
fi
if (( $? == 0 )); then
/usr/sbin/svcadm disable $NETPHYSNWAM || \
fi
do
# Disable the svc.
done
fi
#
# Disable well-known services that don't run in a zone.
#
do
# Skip svcs not installed in the zone.
# Disable the svc.
done
#
# Since zones can't be NFS servers, disable all of the instances of
# the shares svc.
#
do
done
/usr/bin/rm -f $insttmpfile
}
#
# Remove well-known pkgs that do not work inside a zone.
#
rm_pkgs()
{
mail=
instance=overwrite
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
basedir=default
EOF
do
done
}
#
# Zoneadmd writes a one-line index file into the zone when the zone boots,
# so any information about installed zones from the original system will
# be lost at that time. Here we'll warn the sysadmin about any pre-existing
# zones that they might want to clean up by hand, but we'll leave the zonepaths
# in place in case they're on shared storage and will be migrated to
# a new host.
#
{
if [[ -h $zoneconfig/index || ! -f $zoneconfig/index ]]; then
error "$e_badfile" "/etc/zones/index"
return
fi
if (substr($1, 0, 1) == "#" || $1 == "global")
continue
if ($2 == "installed")
printf("%s ", $1)
}' $zoneconfig/index)
# Return if there are no installed zones to warn about.
log "$v_rmzones" "$NGZ"
if (substr($1, 0, 1) == "#" || $1 == "global")
continue
if ($2 == "installed")
printf("%s ", $3)
}' $zoneconfig/index)
do
log " %s" "$i"
done
}
unset LD_LIBRARY_PATH
export PATH
#
# ^C Should cleanup; if the zone is running, it should try to halt it.
#
trap trap_cleanup INT
#
# Parse the command line options.
#
unset backout
while getopts "b:uvm:l:" opt
do
b) if [[ -n "$backout" ]]; then
else
fi
;;
u) OPT_U="-u";;
v) OPT_V="-v";;
*) usage;;
esac
done
shift OPTIND-1
ZONENAME=$1
ZONEPATH=$2
#
# Do some validation on the paths we'll be accessing
#
# Now do the work to update the zone.
# 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.
fi
fi
fi
fi
fi
then
fi
# Check for zones inside of image.
#
# Run update on attach. State is currently 'incomplete' so use the private
# force-update option.
#
res=$?
if (( $? != 0 )); then
else
fi
#
# Any errors in these functions are not considered fatal. The zone can be
# be fixed up manually afterwards and it may need some additional manual
# cleanup in any case.
#
if (( $? != 0 )); then
error "$e_badinfo" "stacktype"
fi
#
# Boot the zone so that we can do all of the SMF updates needed on the zone's
# repository.
#
# The 'update on attach' left the zone installed.
if (( $? != 0 )); then
fi
# cleanup SMF services
# remove invalid pkgs
if (( $? != 0 )); then
failed=1
fi
#
# We're sys-unconfiging the zone. This will halt the zone, however
# there are problems with sys-unconfig and it usually hangs when the
# zone is booted to milestone=none. This is why we previously halted
# the zone. We now boot to milestone=single-user. Again, the
# sys-unconfig can hang if the zone is still in the process of
# booting when we try to run sys-unconfig. Wait until the boot is
# done, which we do by checking for sulogin, or waiting 30 seconds,
# whichever comes first.
#
if (( $? != 0 )); then
fi
do
sleep 10
if ($1 == "online")
exit 0
else
exit 1
}' && break
done
if (( $i == 9 )); then
fi
if (( $? != 0 )); then
failed=1
fi
fi
if [[ -n $failed ]]; then
fi
exit 0