#!/sbin/sh -
# $Id: vxunroot.sh,v 1.13.45.13 2002/11/28 00:38:24 ruchi Exp $
#ident "$Source: /project/unixvm-cvs/src/sol/cmd/vxvm/support/vxunroot.sh,v $"

# Copyright (c) 2001 VERITAS Software Corporation.  ALL RIGHTS RESERVED.
# UNPUBLISHED -- RIGHTS RESERVED UNDER THE COPYRIGHT
# LAWS OF THE UNITED STATES.  USE OF A COPYRIGHT NOTICE
# IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
# OR DISCLOSURE.
# 
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND
# TRADE SECRETS OF VERITAS SOFTWARE.  USE, DISCLOSURE,
# OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
# EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
# 
#               RESTRICTED RIGHTS LEGEND
# USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT IS
# SUBJECT TO RESTRICTIONS AS SET FORTH IN SUBPARAGRAPH
# (C) (1) (ii) OF THE RIGHTS IN TECHNICAL DATA AND
# COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013.
#               VERITAS SOFTWARE
# 1600 PLYMOUTH STREET, MOUNTAIN VIEW, CA 94043


: ${VOLROOT_DIR:=$__VXVM_ROOT_DIR}
. ${VOL_SCRIPTS_LIB:-$VOLROOT_DIR/usr/lib/vxvm/lib}/vxcommon

voladm_help_push yorn.help
voladm_menu_push -M vxvmshm:0 VolumeManager/Unroot

set_OS_variables

# Get info and set variables regarding the device slices and tags
eval `vxparms`

# The opt and tmp partition tag is set to the "unused" state
V_OPT=$V_UNUSED
V_TMP=$V_UNUSED 

#
# unroot_check - Check that no other object(s) but those removed by
# this script exist on the disk whose dm name is passed in as an
# argument.
#
# The approved list of objects is: rootvol swapvol usr var opt home tmp
#
unroot_check()
{
	disk_dm=$1
	disk=`vxprint -F "%da_name" $disk_dm`

	rm -f $tmpfile1 $tmpfile2 $tmpfile3

	#
	# Check for any unassociated plexes on this disk
	#
	vxprint -g "rootdg" -pn \
		-e "!assoc && aslist.sd_dm_name==\"$disk_dm\"" > $tmpfile2

	#
	# Check for any unassociated subdisks on this disk that do not
	# belong to this list of exceptions: ...G ...Priv ...-B0
	#
	vxprint -g "rootdg" -n -sd -e "!assoc && sd_dm_name==\"$disk_dm\"" | \
	    egrep -v "^${disk_dm}G\$|^${disk_dm}Priv\$|^${disk_dm}-B0\$"> $tmpfile3

	if [ -s $tmpfile1 -o -s $tmpfile2 -o -s $tmpfile3 ]; then
export tmpfile1 tmpfile2 tmpfile3 disk; ewritemsg -M vxvmshm:168 \
"ERROR: The vxunroot operation cannot proceed unless the 
	following objects on $disk are (re)moved."
		(echo ""; cat $tmpfile1 $tmpfile2 $tmpfile3; echo "") | \
		voladm_display
		quit 10
	fi

	return 0
}

# return the offset of the public region of a given disk in pub_off 
get_pub_offset() {

	[ -z "$VOL_PUB_SLICE_TAG" ] && 	VOL_PUB_SLICE_TAG=0xe
	disk=$1
	dogi_device_rawpath $disk rawpath
	$PRTVTOC -f $tmpfile1 $rawpath
	exec 4<&0 < $tmpfile1
	pub_off=0

	while read slice tag flags start size
	do
		if [ "$tag" = "$VOL_PUB_SLICE_TAG" ] ; then
			pub_off=$start
		fi
	done
	exec 0<&4 4<&-
}

# return the size of private region
get_priv_size()
{
	[ -z "$VOL_PRIV_SLICE_TAG" ] && VOL_PRIV_SLICE_TAG=0xf
	disk=$1
	dogi_device_rawpath $disk rawpath
	$PRTVTOC -f $tmpfile1 $rawpath
	exec 4<&0 < $tmpfile1

	while read slice_p tag_p flags_p start_p size_p
	do
		if [ "$tag_p" = "$VOL_PRIV_SLICE_TAG" ] ; then
			eval "${2}=$size_p"
		fi
	done
	exec 0<&4 4<&-
	
}

# sliceinfo varprefix daname sliceno -- get information on the given slice
sliceinfo()
{
	_prefix=$1
	dogi_whole_slice $2 whole_slice || return
	dogi_slice_rawpath $whole_slice rawpath
	set `vxpartinfo "\$rawpath" $3 2> /dev/null`
	if [ $# -ne 5 ] 
	then
		return 1
	fi
	eval "${_prefix}_tag=$2"
	eval "${_prefix}_flags=$3"
	eval "${_prefix}_offset=$4"
	eval "${_prefix}_len=$5"
	return 0
}

# is_free_slice daname sliceno tag -- determine if a slice is
# in use or has been picked already
is_free_slice()
{
	list_member $1:$2 $slices_pending && return 1
	sliceinfo _slc "$1" $2 || return 1
	[ $# -gt 2 -a "X$_slc_tag" = "X$3" -a ${_slc_offset} -eq 0 -a ${_slc_len} -eq 0 ] && return 0
	[ "X$_slc_tag" = X0x0 ] && return 0
	return 1
}

# find_slice varname "trylist" da tag -- Used to find a free slice
# on the disk
find_slice()
{
	for tslice in $2
	do
		is_free_slice $3 $tslice $4 && {
			eval "$1=\$tslice"
			append_list slices_pending "$3:$tslice"
			return 0
		}
	done
	eval "$1="
	return 1
}

#
# DMP:
# dmpdisk_to_subpath: Function to check which subpath was specified
# in the /etc/vfstab and put that subpath correctly for the mount
# point entries.  If this information is not available from reconfig.d
# directory then use any of the active subpaths, hopefully system should
# work after vxunroot. If there is only one subpath for the dmp root
# device then use that directly. If not DMP device, use the name
# directly.
#

dmpdisk_to_subpath()
{
	dmpdisk=$1

	vxdisk list $dmpdisk  > $tmpfile1
	grep '^numpaths' $tmpfile1 > $tmpfile2 2> /dev/null

	if [ $? -ne 0 ]
	then
		eval "${2}=$dmpdisk"
		return 0
	fi

	exec 3<&0 < $tmpfile2
	read numpaths num
	exec 0<&3 3<&-

	vxdisk list $dmpdisk  > $tmpfile1
	grep "^c[0-9]" $tmpfile1 > $tmpfile2 2> /dev/null
	exec 3<&0 < $tmpfile2
	while read line; do
		subpath=`echo $line | cut -f 1 -d " "`
		state=`echo $line | cut -f 2 -d " "`
		if [ X"$state" = Xstate=enabled ]
		then
			break
		fi
	done
	exec 0<&3 3<&-
	
	if [ X"$subpath" != X ]
	then
		dogi_slice_to_device $subpath subpathdev
		eval "${2}=$subpathdev"
		return 0
	fi

	grep '^#rename' $DISKDIR/$dmpdisk/newpart > $tmpfile1 2> /dev/null
	if [ $? -eq 0 ]
	then
		exec 3<&0 < $tmpfile1
		read rename subpath voldmpdev
		exec 0<&3 3<&-
		dogi_slice_to_device $subpath subpathdev
		eval "${2}=$subpathdev"
		return 0
	fi

	eval "${2}=$dmpdisk"
	return 0
}

#
# Build the sliceno list, which is assigned back to argument #1.
#
# This function is intended to be call before find_slice(). The slice list
# that this function creates dictate the search order of free slices in
# find_slice() function. For example, a slice list of "7 3 4 5 1 6" indicates
# that slice 7 will be searched first for free slice, follow by slice 3, then
# 4, and so on.
# 
# The sliceno list is built based on the volume name (i.e. argument #2) and
# knowledge of pre-encapsulated parition information (located in the commented
# section of /etc/vfstab). With the goal of putting slices back in the same
# place as pre-encapsulation, we build a list with the first entry matching
# the slice number this volume had at pre-encapsulation. For example, if at
# pre-encapsulation, /opt was in slice #5, then the sliceno list will have "5"
# in the beginning of the list. That is, the returned list will be
# "5 7 3 4 1 6"
#
# Input:
#  $2 = volume name, e.g. "opt"
#  $3 = the default slice number list
#
# Output:
#  $1 = the newly modified slice number list
#
build_sliceno_list()
{
	# Pre-set the slice list to supplied preferred list. We will default
	# to this list in case any error occurs.
	preset_sliceno_list="$3"

	# Initialize pre-encapsulated sliceno to nothing. Currently, we have
	# not found one yet.
	preencapsulated_sliceno=

	if [ ! -s $SYSROOT/etc/vfstab ]
	then
		# Actually, if /etc/vfstab is NOT found, we should have bigger
		# problems elsewhere. Anyway, we can not process further so
		# just return original pre-set sliceno list
		eval "$1=\"$preset_sliceno_list\""
		return
	fi
		
	# Pre-encapsulated slice information are stored in vfstab
	# with a "#NOTE:" prefix.
	preencap_sliceentry=`cat $SYSROOT/etc/vfstab \
		| egrep "^#NOTE: volume $2" | egrep "encapsulated partition"`

	# If that vfstab entry is missing, then just return the preset
	# sliceno list
	# OLD Entry Fails when preencap_slicentry is null 
	# if [ ! -n $preencap_sliceentry ]
	# Alternative Fix is if [ ! -n "$preencap_sliceentry" ]
	# chose to avoid the double negative here
	# OLD FIX Failed Incosistent ,if [[  -z $preencap_sliceentry ]]
	if [ ! -n "$preencap_sliceentry" ]
	then
		eval "$1=\"$preset_sliceno_list\""
		return
	fi

	# Extract sliceno from device name. For example, the sliceno of
	# "c0t0d0s4" is 4.
	preencapsulated_sliceno=`echo $preencap_sliceentry \
		| awk '{ print substr($NF, length($NF), 1) }'`

	# Make sure we have a valid slice number
	case $preencapsulated_sliceno in
		[3-7])	;;
		1)	;;
		*)	
			# Invalid slice number. Just return pre-set list
			#  instead.
			eval "$1=\"$preset_sliceno_list\""
			return
	esac

	# Remove the sliceno from the pre-set list. Later on, we will
	# add the sliceno at the beginning of the list, which will have
	# the net effect of moving the sliceno to the beginning.
	tmplist=`echo $preset_sliceno_list \
		| sed s/$preencapsulated_sliceno//g | sed s/"  "/" "/g`

	# Prefix the pre-set list with a sliceno. This causes this sliceno to
	#  be searched FIRST when running the find_slice() function.
	new_slicelist="$preencapsulated_sliceno $tmplist"

	eval "${1}=\"$new_slicelist\""
	return
}

#
# Return all the encapsulated volumes in the root disk
# Any Modification to this function has to be repeated in vxupgrade_start.sh
#
get_encap_vols()
{
	tmpf1=${tmpfile1}
	tmpf2=${tmpfile2}
	ENCAP_PATH=""
	encap_vol_list=""

	# checking for the presence of rootvol
	vnames=`vxprint -F "%vname" -s -e "(!sd_is_log)" | sort -u`
	echo "$vnames" | grep "^rootvol$" 2>&1 > /dev/null
	if [ $? -ne 0 ]
	then
		eval "${1}=\${encap_vol_list}"
		return
	fi
	disk_dm=`vxprint -g rootdg -hqt rootvol | grep "^sd" | \
					awk '{print $4}' | uniq`

	# find the saved vtoc file for the encapsulated disk
	for i in $disk_dm
	do
		da_name=`vxprint -F '%daname' ${i}`
		da_name=`vxdisk list $da_name | \
				egrep "^c[0-9]*t[0-9]*d[0-9]*s[0-9]*" |\
				head -1 | awk '{print $1}' | \
				sed 's/\(.*\)s[0-9]*$/\1/'`
		if [ -f "/etc/vx/reconfig.d/disk.d/${da_name}/vtoc" ]; then
			ENCAP_PATH="/etc/vx/reconfig.d/disk.d/${da_name}/vtoc"
			break
		fi
	done

	vol_list=`vxprint -g "rootdg" -vn \
			-e "aslist.aslist.sd_dm_name==\"${i}\""`

	if [ -z "$ENCAP_PATH" ]; then
                nvol=`echo "$vol_list" | wc -l`
                if [ $nvol -gt 5 ]; then
			export CMD nvol;  ewritemsg -M vxvmshm:0 \
"$CMD can at most unroot five volumes from the root disk. 
  The current root disk contains $nvol volumes, move or 
  delete the surplus volumes from the root disk before 
  retrying $CMD.\n"
                        exit 1
                fi
                vol_list=`echo $vol_list`
                eval "${1}=\${vol_list}"
                return
        fi

	# Find the encapsulated volumes in rootdisk from the list of
	# all volumes in the disk.
	for vname in $vol_list
	do
		vxprint -g rootdg -hqt $vname > $tmpf1
		grep '^sd' $tmpf1 > $tmpf2
		exec 3<&0 < $tmpf2
		read sd disksd pl voldisk_dm volstart vollen var dash

		# Omit ghost sd

		sub=0
		if [ $vollen -eq $VOL_GHOST_LEN ]
		then
			read sd disksd pl voldisk_dm volstart vollen var dash
			vollen=`expr $vollen + $VOL_GHOST_LEN`
			sub=$VOL_GHOST_LEN
		fi
		volstart=`vxprint -F  "%dev_offset" $disksd`
		volstart=`expr $volstart - $sub`

		voldisk=`vxprint -F "%da_name" $voldisk_dm`
		dogi_slice_to_device $voldisk voldisk
		get_pub_offset $voldisk
		volstart=`expr $volstart + $pub_off`

		exec 0<&3 3<&-

		exec 3<&0 < $ENCAP_PATH
		while read slice tag flags start size
		do
			case $slice in
			[0-9])  sliceno=$slice;;
			'#'*)   continue;;
			esac

			# if no disk space available for private region
			# while encapsulation, swap region is used for 
			# private region, which needs to be handled.
			if [ "$vname" = "swapvol" ]; then
				p_size=
				get_priv_size $voldisk p_size
				volstart1=`expr $volstart - $p_size`
				vollen1=`expr $vollen + $p_size`
				if [ $start -eq $volstart ] && [ $size -eq $vollen ]
				then
					encap_vol_list=`echo $encap_vol_list $vname`
					break
				elif [ $start -eq $volstart1 ] && [ $size -eq $vollen1 ]
				then
					encap_vol_list=`echo $encap_vol_list $vname`
					break
				fi
			elif [ $start -eq $volstart ] && [ $size -eq $vollen ]
			then
				encap_vol_list=`echo $encap_vol_list $vname`
				break
			fi
		done
		exec 0<&3 3<&-
	done
	rm -f $tmpf1 $tmpf2
	eval "${1}=\${encap_vol_list}"
}

append_list()
{
	_list=$1
	shift
	eval "set -- \$$_list \$*"
	eval "$_list=\$*"
}

#
# list_explode [-t fieldsep] listname var1 var2 ...
#
# Explode a list and store elements into the named variables.  If
# some variables could not be filled (because the named list didn't
# have enough members) return a non-zero status.
#
list_explode()
{
	_le_save=$IFS
	_le_ifs=$IFS
	[ "X$1" = X-t ] && {
		_le_ifs=$2
		shift 2
	}
	_le_list=$1
	shift
	_le_vars="$*"
	IFS="$_le_ifs"
	eval "set \$$_le_list"
	IFS="$_le_save"
	for _le_var in $_le_vars
	do
		[ $# -eq 0 ] && {
			return 1
		}
		eval "$_le_var=\$1"
		shift
	done
	return 0
}

CMD=$0
tempdisk=

# find all encapsulated volume on rootdisk if it has

list_vnames=
get_encap_vols list_vnames

# If no root volume then we can exit now.
echo "$list_vnames" | grep -w rootvol 2>&1 > /dev/null

if [ $? -ne 0 ]
then
        export CMD; egettxt "$CMD: No rootvol found." \
        vxvmshm:991 $CMD  >&2
        quit 1

fi

nopart_vol=
for vol in `echo $vol_list`
do
        echo "$list_vnames" | grep -w "$vol" 1>&2 1> /dev/null
        [ $? -ne 0 ] && nopart_vol=`echo $nopart_vol $vol`
done

[ ! -z "$nopart_vol" ] &&
{
                export nopart_vol; ewritemsg -M vxvmshm:1562 \
"The following volumes detected on the root disk of your system are not
  derivatives of partitions that were on the pre-encapsulated root disk:
  \n\t$nopart_vol\n"
                ewritemsg -M vxvmshm:1560 \
"Please move these volumes and comment out corresponding entries in
  /etc/vfstab before you rerun vxunroot."
                echo
                quit 10

}

export list_vnames; ewritemsg -M vxvmshm:1564 \
"This operation will convert the following file systems from
  volumes to regular partitions:\n\n\t$list_vnames"

# Assert that the count of plexes for the volumes is exactly one.

for vname in $list_vnames
do
	vxprint -g rootdg -F "%pl_num" $vname > $tmpfile1
	if [ $? -ne 0 ]
	then
		export vname; ewritemsg -M vxvmshm:504 \
"WARNING: Cannot determine the count of plexes for the $vname volume"
	else
		if [ "X`cat $tmpfile1`" != X1 ]
		then
export tmpfile1 vname; ewritemsg -M vxvmshm:170 \
"ERROR: There are `cat $tmpfile1` plexes associated with volume $vname
         The vxunroot operation cannot proceed."
			quit 10
		fi
	fi
	rm -f $tmpfile1
done

# Find the disk and the partition number on which volumes resides

worklist1=
worklist2=
for vname in $list_vnames
do
	voldisk=
	voldisk_dm=
	good_vol=
	vxprint -g rootdg -hqt $vname  > $tmpfile1
	grep '^sd' $tmpfile1 > $tmpfile2
	exec 3<&0 < $tmpfile2
	read sd disksd pl voldisk_dm volstart vollen var dash


	# Omit ghost sd

	sub=0
	if [ $vollen -eq $VOL_GHOST_LEN ] 
	then
		read sd disksd pl voldisk_dm volstart vollen var dash
		vollen=`expr $vollen + $VOL_GHOST_LEN` 
		sub=1
	fi
	volstart=`vxprint -F  "%dev_offset" $disksd`
	volstart=`expr $volstart - $sub`
	voldisk=`vxprint -F "%da_name" $voldisk_dm`
	dogi_slice_to_device $voldisk voldisk
	#voldisk=`expr ${voldisk} : '\(.*\)s.'`
	exec 0<&3 3<&-

	if [ -z "$voldisk" ]
	then
		ewritemsg -M vxvmshm:1559 \
	"ERROR: Cannot determine the disks on which $vname resides."
		quit 1
	fi

	# Find out one good path of the disk so that its vtoc can be read..
	dmpdisk_to_subpath $voldisk good_vol
	if [ $vname = "rootvol" ]; then
		good_root_vol=$good_vol
	fi

	get_pub_offset $good_vol
	volstart=`expr $volstart + $pub_off`
	append_list worklist1 \
		$vname:$good_vol:$volstart:$vollen:$voldisk_dm:$voldisk
done

# Find volume slice on its disk
# Must send the active disk path because we are doing a prtvtoc on it 

for work in $worklist1
do
	list_explode -t : work vname good_vol volstart vollen \
				voldisk_dm voldisk || {
		echo "Internal Inconsistency"
		quit 1
	}
	mkpart=
	dogi_device_rawpath $good_vol volrpath
	$PRTVTOC -f $tmpfile1 $volrpath
	exec 3<&0 < $tmpfile1
	slno=
	while read slice tag flags start size
	do
		case $slice in
		[0-9])	sliceno=$slice;;
		'#'*)	continue;;
		esac
		if [ $start -eq $volstart ] && [ $size -eq $vollen ]
		then 
			slno=$sliceno
		fi
	done
	exec 0<&3 3<&-

	if [ $vname = "rootvol" ]; then
		good_root_vol=${good_root_vol}s${slno}
	fi
	if [ $vname != "rootvol" -a $vname != "swapvol" ]
	then
		if [ -z "$slno" ]
		then
			sliceno_list=
			option=$V_USR
			if [ $vname = "var" ]; then
				option=$V_VAR
			fi
			if [ $vname = "opt" ]; then
				option=$V_OPT
			fi
			if [ $vname = "home" ]; then
				option=$V_HOME
			fi
			if [ $vname = "tmp" ]; then
				option=$V_TMP
			fi
			build_sliceno_list sliceno_list $vname "6 7 3 4 5 1"
			find_slice slno "$sliceno_list" $voldisk $option
			mkpart=yes
		fi
	fi

	if [ -z "$slno" ]
	then
		export voldisk; ewritemsg -M vxvmshm:1558 \
"Disk $voldisk does not have a suitable ROOT partition to use.
  Perhaps the *${vname}* plex is not the original one created by 
  vxrootmir or not the original one created when the rootdisk
  was encapsulated; or perhaps the $vname partition no longer 
  exists on this disk.

  The vxunroot operation cannot proceed."
		quit 10
	fi

	unroot_check $voldisk_dm

	if [ -n "$mkpart" ]
	then
		dogi_device_rawpath $voldisk usrpath
		vxpartadd $usrpath $slno $option 0x200 $volstart $vollen
		if [ $? -ne 0 ]
		then
		ewritemsg -M vxvmshm:1565 \
"Unable to create partition for $vname volume"
			quit 10
		fi
	fi
	append_list worklist2 $vname:$good_vol:$slno:$voldisk_dm:$voldisk

done

export slno volslice swapno voldisk;  ewritemsg -M vxvmshm:0 \
"Replacing volumes in root disk to partitions will require a system 
  reboot. If you choose to continue with this operation, system
  configuration will be updated to discontinue use of the volume
  manager for your root and swap devices."

voladm_yorn -M vxvmshm:162 "Do you wish to do this now" y || quit 10

[ -d $STATEDIR ] || volmkdirs

rm -f $rmvols
rm -f $rmvmdisks

cd $SAVEDIR
ewritemsg -M vxvmshm:287 "Restoring kernel configuration..."

#
# Remove ROOT partition stuff from /etc/system ...
# NOTE: don't remove any and all "rootdev" lines, just ours ...
# NOTE: restore any "rootdev" lines that we commented out ...
#
grep -v rootdev_is_volume $SYSROOT/etc/system > $tmpfile1
doit mv $tmpfile1 $SYSROOT/etc/system || quit 10

grep -v "^rootdev:/pseudo/vxio@0:0" $SYSROOT/etc/system > $tmpfile1
doit mv $tmpfile1 $SYSROOT/etc/system || quit 10

restore_commented_rootdev $SYSROOT/etc/system

for work in $worklist2
do
	list_explode -t : work vname good_vol slno voldisk_dm voldisk || {
		echo "Internal Inconsistency"
		quit 1
	}
	# We already have the active path in $good_vol
	#dmpdisk_to_subpath $voldisk tempdisk
	dogi_device_slice $good_vol $slno volslice
	dogi_slice_rawpath $volslice volrpath
	dogi_slice_blkpath $volslice volbpath

	#
	# Replace volume with slices in /etc/vfstab
	#
	doit sed -e "s;/dev/vx/dsk/${vname}\\([	 ]\\);${volbpath}\\1;" \
	 	-e "s;/dev/vx/rdsk/${vname}\\([	 ]\\);${volrpath}\\1;" \
			< $SYSROOT/etc/vfstab > $tmpfile1 || quit 10

	doit mv $tmpfile1 $SYSROOT/etc/vfstab || quit 10

	echo $vname >> $rmvols
	(grep $voldisk_dm $rmvmdisks 2>&1 ) > /dev/null
	if [ $? -ne 0 ] ; then
		echo $voldisk_dm >> $rmvmdisks
	fi

done


doit rm -f $rootfile $rootsvfile

doit rm -f /etc/vx/.dumpadm

#
# Change the default boot-device so that the system boots from the pathname
# which is there in /etc/vfstab.
#

if dogi_name_is_slice $good_root_vol
then
	new_root=$good_root_vol
else
	dogi_device_slice $good_root_vol 0 new_root
fi

case $new_root in
	mc*)
		new_root_wo_ap=`echo $new_root | awk -Fm '{print $2}'`
		tmp_root_path=`ls -l /dev/dsk/$new_root_wo_ap | \
						awk '{print $NF}'`
		;;
	*)
		tmp_root_path=`ls -l /dev/dsk/$new_root | awk '{print $NF}'`
		;;
esac	
root_path=`expr $tmp_root_path : '.*devices\(.*\)$'`
vxeeprom boot-device $root_path > /dev/null 2>&1

if [ $? != 0 ]
then
	export root_path; ewritemsg -M vxvmshm:874 \
	"Please set boot-device to $root_path before shutdown.
	 To do this type

	 eeprom set boot-device $root_path"
	echo ""
	quit 10
fi

#
# Remove unwanted comments with pre-encapsulation slice information
#
grep -v "^#NOTE: volume .* \(.*\) encapsulated partition" \
        $SYSROOT/etc/vfstab > $tmpfile1
doit mv $tmpfile1 $SYSROOT/etc/vfstab || quit 10

#
# Notify user
#
ewritemsg -M vxvmshm:78 \
"A shutdown is now required to install the new kernel.
  You can choose to shutdown now, or you can shutdown later, at your
  convenience."

voladm_yorn -M vxvmshm:163 "Do you wish to shutdown now" n
if [ $? -ne 0 ]
then
	ewritemsg -M vxvmshm:258 \
"Please shutdown before you perform any additional volume manager
  or disk reconfiguration.  To shutdown your system cd to / and type

  	shutdown -g0 -y -i6"
	echo ""
	quit 10
fi

# The following is not within scope for i18n so -M is unused
ewritemsg "shutdown -g0 -y -i6"
cd /
doit shutdown -g0 -y -i6 && { sleep 1200; quit 0; }

egettxt "The shutdown failed.  Consult your system administration guide." vxvmshm:390
quit 10
