#!/sbin/sh -
# @(#)src/cmd/vxvm/solaris/support/vxunroot.sh	3.1.1.3 06/04/97 04:44:42 - 
#ident	"@(#)vxvm:src/cmd/vxvm/solaris/support/vxunroot.sh	3.1.1.3"

# Copyright(C)1997 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 VolumeManager/Unroot

set_OS_variables

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

# The OPT partition tag is set to the "unused" state
V_OPT=$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
#
unroot_check()
{
	disk_dm=$1
	disk=`vxprint -F "%da_name" $disk_dm`

	#
	# Check for any volumes on this disk other than the approved list
	#
	vxprint -g "rootdg" -vn \
		-e "aslist.aslist.sd_dm_name==\"$disk_dm\"" | \
		 egrep -v "^rootvol$|^swapvol$|^usr$|^var$|^opt$"> $tmpfile1

	#
	# 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 3<&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<&3 3<&-
}

# 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" ] && 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<&-

	if [ $num = 1 ]
	then
		eval "${2}=$dmpdisk"
		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

	vxdisk list $dmpdisk  > $tmpfile1
	grep "^c[0-9]" $tmpfile1 > $tmpfile2 2> /dev/null
	exec 3<&0 < $tmpfile2
	while read subpath state; do
		if [ X"$state" = Xactive ]
		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

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


tempdisk=

# Find all subdisks that are not log subdisks for a plex.

vnames=`vxprint -F "%vname" -s\
    -e "(!sd_is_log)" | sort -u`
 
# If no root volume then we can exit now.
echo "$vnames" | grep -w rootvol 2>&1 > /dev/null
if [ $? -ne 0 ]
then
        egettxt "$0: No rootvol found." \
        vxvmshm:32 $0  >&2
        quit 1

fi

# Initialize list of slices

slices_pending=

# Find if swap, usr, var, and opt are also on volumes

swap_is_vol=
usr_is_vol=
var_is_vol=
opt_is_vol=
echo $vnames | grep -w swapvol 2>&1 > /dev/null
if [ $? -eq 0 ]
then
	swap_is_vol=yes
fi
echo $vnames | grep -w usr 2>&1 > /dev/null
if [ $? -eq 0 ]
then
	usr_is_vol=yes
fi
echo $vnames | grep -w var 2>&1 > /dev/null
if [ $? -eq 0 ]
then
	var_is_vol=yes
fi
echo $vnames | grep -w opt 2>&1 > /dev/null
if [ $? -eq 0 ]
then
	opt_is_vol=yes
fi

ewritemsg -M vxvmshm:433 \
"This operation will convert the following file systems from
  volumes to regular partitions: root swap usr var opt"

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

for vname in rootvol
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
done
rm -f $tmpfile1

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

if [ ! -z "$swap_is_vol" ]
then
	vxprint -g rootdg -F "%pl_num" swapvol  > $tmpfile1
	if [ $? -ne 0 ]
	then
		ewritemsg -M vxvmshm:505 \
"WARNING: Cannot determine the count of plexes for the swap volume"
	else
		if [ "X`cat $tmpfile1`" != X1 ]
		then
export tmpfile1 ; ewritemsg -M vxvmshm:169 \
"ERROR: There are `cat $tmpfile1` plexes associated with the swap volume
         The vxunroot operation cannot proceed."
			quit 10
		fi
	fi
fi

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

if [ ! -z "$usr_is_vol" ]
then
	vxprint -g rootdg -F "%pl_num" usr  > $tmpfile1
	if [ $? -ne 0 ]
	then
		ewritemsg -M vxvmshm:506 \
"WARNING: Cannot determine the count of plexes for the usr volume"
	else
		if [ "X`cat $tmpfile1`" != X1 ]
		then
export tmpfile1 ; ewritemsg -M vxvmshm:171 \
"ERROR: There are `cat $tmpfile1` plexes associated with volume usr
         The vxunroot operation cannot proceed."
			quit 10
		fi
	fi
fi

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

if [ ! -z "$var_is_vol" ]
then
	vxprint -g rootdg -F "%pl_num" var > $tmpfile1
	if [ $? -ne 0 ]
	then
		ewritemsg -M vxvmshm:507 \
"WARNING: Cannot determine the count of plexes for the var volume"
	else
		if [ "X`cat $tmpfile1`" != X1 ]
		then
export tmpfile1 ; ewritemsg -M vxvmshm:172 \
"ERROR: There are `cat $tmpfile1` plexes associated with volume var
         The vxunroot operation cannot proceed."
			quit 10
		fi
	fi
fi

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

if [ ! -z "$opt_is_vol" ]
then
	vxprint -g rootdg -F "%pl_num" opt > $tmpfile1
	if [ $? -ne 0 ]
	then
		ewritemsg -M vxvmshm:507 \
"WARNING: Cannot determine the count of plexes for the opt volume"
	else
		if [ "X`cat $tmpfile1`" != X1 ]
		then
export tmpfile1 ; ewritemsg -M vxvmshm:172 \
"ERROR: There are `cat $tmpfile1` plexes associated with volume opt
         The vxunroot operation cannot proceed."
			quit 10
		fi
	fi
fi

# Find the disk on which rootvol resides

rootdisk=
rootdisk_dm=
vxprint -g rootdg -hqt rootvol  > $tmpfile1
grep '^sd' $tmpfile1 > $tmpfile2
exec 3<&0 < $tmpfile2
read sd disksd pl rootdisk_dm rootstart rootlen var dash


# Omit ghost sd

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

if [ -z "$rootdisk" ]
then
	ewritemsg -M vxvmshm:164 \
	"ERROR: Cannot determine the rootdisk."
	quit 1
fi

get_pub_offset $rootdisk
rootstart=`expr $rootstart + $pub_off`

# Find the disk on which swapvol resides

swapdisk_dm=
swapdisk=
if [ ! -z "$swap_is_vol" ]
then
	vxprint -g rootdg -hqt swapvol  > $tmpfile1
	grep '^sd' $tmpfile1 > $tmpfile2
	exec 3<&0 < $tmpfile2
	read sd disksd pl swapdisk_dm swapstart swaplen var dash
	sub=0
	if [ $swaplen -eq $VOL_GHOST_LEN ]
	then
		read sd disksd pl swapdisk_dm swapstart swaplen var dash
		swaplen=`expr $swaplen + $VOL_GHOST_LEN` 
		sub=1
	fi
	swapstart=`vxprint -F  "%dev_offset" $disksd`
	swapstart=`expr $swapstart - $sub`
	swapdisk=`vxprint -F "%da_name" $swapdisk_dm`
	dogi_slice_to_device $swapdisk swapdisk
	#swapdisk=`expr ${swapdisk} : '\(.*\)s.'`
	exec 0<&3 3<&-
	if [ -z "$swapdisk" ]
	then
		ewritemsg -M vxvmshm:165 \
		"ERROR: Cannot determine the swapdisk."
		quit 1
	fi
	get_pub_offset $swapdisk
	swapstart=`expr $swapstart + $pub_off`
fi


# Find the disk on which usr resides

usrdisk_dm=
usrdisk=
if [ ! -z "$usr_is_vol" ]
then
	vxprint -g rootdg -hqt usr  > $tmpfile1
	grep '^sd' $tmpfile1 > $tmpfile2
	exec 3<&0 < $tmpfile2
	sub=0
	read sd disksd pl usrdisk_dm usrstart usrlen var dash
	if [ $usrlen -eq $VOL_GHOST_LEN ]
	then
		read sd disksd pl usrdisk_dm usrstart usrlen var dash
		usrlen=`expr $usrlen + $VOL_GHOST_LEN` 
		sub=1
	fi
	usrstart=`vxprint -F  "%dev_offset" $disksd`
	usrstart=`expr $usrstart - $sub`
	usrdisk=`vxprint -F "%da_name" $usrdisk_dm`
	dogi_slice_to_device $usrdisk usrdisk
	#usrdisk=`expr ${usrdisk} : '\(.*\)s.'`
	exec 0<&3 3<&-
	if [ -z "$usrdisk" ]
	then
		ewritemsg -M vxvmshm:166 \
		"ERROR: Cannot determine the usrdisk."
		quit 1
	fi
	get_pub_offset $usrdisk
	usrstart=`expr $usrstart + $pub_off`
fi

# Find the disk on which var resides

vardisk_dm=
vardisk=
if [ ! -z "$var_is_vol" ]
then
	vxprint -g rootdg -hqt var  > $tmpfile1
	grep '^sd' $tmpfile1 > $tmpfile2
	exec 3<&0 < $tmpfile2
	sub=0
	read sd disksd pl vardisk_dm varstart varlen var dash
	if [ $varlen -eq $VOL_GHOST_LEN ]
	then
		read sd disksd pl vardisk_dm varstart varlen var dash
		varlen=`expr $varlen + $VOL_GHOST_LEN` 
		sub=1
	fi
	varstart=`vxprint -F  "%dev_offset" $disksd`
	varstart=`expr $varstart - $sub`
	vardisk=`vxprint -F "%da_name" $vardisk_dm`
	dogi_slice_to_device $vardisk vardisk
	#vardisk=`expr ${vardisk} : '\(.*\)s.'`
	exec 0<&3 3<&-
	if [ -z "$vardisk" ]
	then
		ewritemsg -M vxvmshm:167 \
		"ERROR: Cannot determine the vardisk."
		quit 1
	fi
	get_pub_offset $vardisk
	varstart=`expr $varstart + $pub_off`
fi

# Find the disk on which opt resides

optdisk_dm=
optdisk=
if [ ! -z "$opt_is_vol" ]
then
	vxprint -g rootdg -hqt opt  > $tmpfile1
	grep '^sd' $tmpfile1 > $tmpfile2
	exec 3<&0 < $tmpfile2
	sub=0
	read sd disksd pl optdisk_dm optstart optlen var dash
	if [ $optlen -eq $VOL_GHOST_LEN ]
	then
		read sd disksd pl optdisk_dm optstart optlen var dash
		optlen=`expr $optlen + $VOL_GHOST_LEN` 
		sub=1
	fi
	optstart=`vxprint -F  "%dev_offset" $disksd`
	optstart=`expr $optstart - $sub`
	optdisk=`vxprint -F "%da_name" $optdisk_dm`
	dogi_slice_to_device $optdisk optdisk
	#optdisk=`expr ${optdisk} : '\(.*\)s.'`
	exec 0<&3 3<&-
	if [ -z "$optdisk" ]
	then
		ewritemsg -M vxvmshm:167 \
		"ERROR: Cannot determine the optdisk."
		quit 1
	fi
	get_pub_offset $optdisk
	optstart=`expr $optstart + $pub_off`
fi


# Find root slice on root disk

dogi_device_rawpath $rootdisk rootrpath
$PRTVTOC -f $tmpfile1 $rootrpath
exec 3<&0 < $tmpfile1
rootno=
while read slice tag flags start size
do
	case $slice in
	[0-9])	sliceno=$slice;;
	'#'*)	continue;;
	esac
	if [ $start -eq $rootstart ] && [ $size -eq $rootlen ]
	then
		rootno=$sliceno
	fi
done
exec 0<&3 3<&-

# Find swap slice on swap disk

if [ ! -z "$swap_is_vol" ]
then
	dogi_device_rawpath $swapdisk swaprpath
	$PRTVTOC -f $tmpfile1 $swaprpath
	exec 3<&0 < $tmpfile1
	swapno=
	while read slice tag flags start size
	do
		case $slice in
		[0-9])	sliceno=$slice;;
		'#'*)	continue;;
		esac
		if [ $start -eq $swapstart ] && [ $size -eq $swaplen ]
		then
			swapno=$sliceno
		fi
	done
	exec 0<&3 3<&-
fi

# Find usr slice on usr disk
mkusrpart=
if [ ! -z "$usr_is_vol" ]
then
	dogi_device_rawpath $usrdisk usrrpath
	$PRTVTOC -f $tmpfile1 $usrrpath
	exec 3<&0 < $tmpfile1
	usrno=
	while read slice tag flags start size
	do
		case $slice in
		[0-9])	sliceno=$slice;;
		'#'*)	continue;;
		esac
		if [ $start -eq $usrstart ] && [ $size -eq $usrlen ]
		then
			usrno=$sliceno
		fi
	done
	exec 0<&3 3<&-
	if [ -z "$usrno" ]
	then
		find_slice usrno "6 7 3 4 5 1" $usrdisk $V_USR
		mkusrpart=yes
	fi
fi

# Find var slice on var disk
mkvarpart=
if [ ! -z "$var_is_vol" ]
then
	dogi_device_rawpath $vardisk varrpath
	$PRTVTOC -f $tmpfile1 $varrpath
	exec 3<&0 < $tmpfile1
	varno=
	while read slice tag flags start size
	do
		case $slice in
		[0-9])	sliceno=$slice;;
		'#'*)	continue;;
		esac
		if [ $start -eq $varstart ] && [ $size -eq $varlen ]
		then
			varno=$sliceno
		fi
	done
	if [ -z "$varno" ]
	then
		find_slice varno "7 3 4 5 1 6" $vardisk $V_VAR
		mkvarpart=yes
	fi
	exec 0<&3 3<&-
fi

# Find opt slice on opt disk
mkoptpart=
if [ ! -z "$opt_is_vol" ]
then
	dogi_device_rawpath $optdisk optrpath
	$PRTVTOC -f $tmpfile1 $optrpath
	exec 3<&0 < $tmpfile1
	optno=
	while read slice tag flags start size
	do
		case $slice in
		[0-9])	sliceno=$slice;;
		'#'*)	continue;;
		esac
		if [ $start -eq $optstart ] && [ $size -eq $optlen ]
		then
			optno=$sliceno
		fi
	done
	if [ -z "$optno" ]
	then
		find_slice optno "7 3 4 5 1 6" $optdisk $V_OPT
		mkoptpart=yes
	fi
	exec 0<&3 3<&-
fi

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

  The vxunroot operation cannot proceed."
	quit 10
fi

unroot_check $rootdisk_dm

if [ ! -z "$swap_is_vol" ] && [ -z "$swapno" ]
then
	export swapdisk; ewritemsg -M vxvmshm:147 \
"Disk $swapdisk does not have a suitable SWAP partition to use.
  Perhaps the SWAPVOL plex is not the original one created by 
  vxrootmir or not the original one created when the rootdisk
  was encapsulated; or perhaps the SWAP partition no longer 
  exists on this disk.

  The vxunroot operation cannot proceed."
	quit 10
fi

unroot_check $swapdisk_dm

if [ ! -z "$usr_is_vol" ] && [ -z "$usrno" ]
then
	export usrdisk; ewritemsg -M vxvmshm:148 \
"Disk $usrdisk does not have a suitable USR partition to use.
  Perhaps the USR plex is not the original one created by 
  vxrootmir or not the original one created when the rootdisk
  was encapsulated; or perhaps the USR partition no longer 
  exists on this disk.

  The vxunroot operation cannot proceed."
	quit 10
fi

[ ! -z "$usr_is_vol" ] &&  unroot_check $usrdisk_dm

if [ ! -z "$var_is_vol" ] && [ -z "$varno" ]
then
	export vardisk; ewritemsg -M vxvmshm:149 \
"Disk $vardisk does not have a suitable VAR partition to use.
  Perhaps the VAR plex is not the original one created by 
  vxrootmir or not the original one created when the rootdisk
  was encapsulated; or perhaps the VAR partition no longer 
  exists on this disk.

  The vxunroot operation cannot proceed."
	quit 10
fi

[ ! -z "$var_is_vol" ] &&  unroot_check $vardisk_dm

if [ ! -z "$opt_is_vol" ] && [ -z "$optno" ]
then
	export optdisk; ewritemsg -M vxvmshm:149 \
"Disk $optdisk does not have a suitable OPT partition to use.
  Perhaps the OPT plex is not the original one created by 
  vxrootmir or not the original one created when the root
  was encapsulated; or perhaps the OPT partition no longer 
  exists on this disk.

  The vxunroot operation cannot proceed."
	quit 10
fi

[ ! -z "$opt_is_vol" ] &&  unroot_check $optdisk_dm

if [ -n "$mkusrpart" ]
then
	dogi_device_rawpath $usrdisk usrpath
	vxpartadd $usrpath $usrno $V_USR 0x200 $usrstart $usrlen
	if [ $? -ne 0 ]
	then
	ewritemsg -M vxvmshm:0 \
"Unable to create partition for usr volume"
		quit 10
	fi
fi

if [ -n "$mkvarpart" ]
then
	dogi_device_rawpath $vardisk varpath
	vxpartadd $varpath $varno $V_VAR 0x200 $varstart $varlen
	if [ $? -ne 0 ]
	then
	ewritemsg -M vxvmshm:0 \
"Unable to create partition for var volume"
		quit 10
	fi
fi
	

if [ -n "$mkoptpart" ]
then
	dogi_device_rawpath $optdisk optpath
	vxpartadd $optpath $optno $V_OPT 0x200 $optstart $optlen
	if [ $? -ne 0 ]
	then
	ewritemsg -M vxvmshm:0 \
"Unable to create partition for opt volume"
		quit 10
	fi
fi
	
dmpdisk_to_subpath $rootdisk tempdisk
dogi_device_slice $tempdisk $rootno rootslice
dogi_slice_rawpath $rootslice rootrpath
dogi_slice_blkpath $rootslice rootbpath

export rootno rootslice swapno rootdisk swapdisk;  ewritemsg -M vxvmshm:278 \
"Replace volume rootvol with $rootslice.

  This operation 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..."

#
# Replace ROOT partition stuff from /etc/vfstab ...
#
doit sed -e "s;/dev/vx/dsk/rootvol\\([	 ]\\);${rootbpath}\\1;" \
	 -e "s;/dev/vx/rdsk/rootvol\\([	 ]\\);${rootrpath}\\1;" \
		< $SYSROOT/etc/vfstab > $tmpfile1 || quit 10

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

#
# 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

echo rootvol >> $rmvols
echo $rootdisk >> $rmvmdisks

#
# Replace SWAP partition stuff from /etc/vfstab ...
#
if [ ! -z "$swap_is_vol" ]
then
	dmpdisk_to_subpath $swapdisk tempdisk
	dogi_device_slice $tempdisk $swapno swapslice
	dogi_slice_blkpath $swapslice swapbpath
	doit sed -e "s;/dev/vx/dsk/swapvol\\([	 ]\\);${swapbpath}\\1;" \
		< $SYSROOT/etc/vfstab > $tmpfile1 || quit 10

	doit mv $tmpfile1 $SYSROOT/etc/vfstab || quit 10
	echo swapvol >> $rmvols
	(grep $swapdisk $rmvmdisks 2>&1 ) > /dev/null
	if [ $? -ne 0 ] ; then
		echo $swapdisk >> $rmvmdisks
	fi
fi

#
# Replace USR partition stuff from /etc/vfstab ...
#
if [ ! -z "$usr_is_vol" ]
then
	dmpdisk_to_subpath $usrdisk tempdisk
	dogi_device_slice $tempdisk $usrno usrslice
	dogi_slice_rawpath $usrslice usrrpath
	dogi_slice_blkpath $usrslice usrbpath
	doit sed -e "s;/dev/vx/dsk/usr\\([	 ]\\);${usrbpath}\\1;" \
	 -e "s;/dev/vx/rdsk/usr\\([	 ]\\);${usrrpath}\\1;" \
		< $SYSROOT/etc/vfstab > $tmpfile1 || quit 10

	doit mv $tmpfile1 $SYSROOT/etc/vfstab || quit 10
	echo usr >> $rmvols
	(grep $usrdisk $rmvmdisks 2>&1 ) > /dev/null
	if [ $? -ne 0 ] ; then
		echo $usrdisk >> $rmvmdisks
	fi
fi

#
# Replace VAR partition stuff from /etc/vfstab ...
#
if [ ! -z "$var_is_vol" ]
then
	dmpdisk_to_subpath $vardisk tempdisk
	dogi_device_slice $tempdisk $varno varslice
	dogi_slice_rawpath $varslice varrpath
	dogi_slice_blkpath $varslice varbpath
	doit sed -e "s;/dev/vx/dsk/var\\([	 ]\\);${varbpath}\\1;" \
	 -e "s;/dev/vx/rdsk/var\\([	 ]\\);${varrpath}\\1;" \
		< $SYSROOT/etc/vfstab > $tmpfile1 || quit 10

	doit mv $tmpfile1 $SYSROOT/etc/vfstab || quit 10
	echo var >> $rmvols
	(grep $vardisk $rmvmdisks 2>&1 ) > /dev/null
	if [ $? -ne 0 ] ; then
		echo $vardisk >> $rmvmdisks
	fi
fi

#
# Replace OPT partition stuff from /etc/vfstab ...
#
if [ ! -z "$opt_is_vol" ]
then
	dmpdisk_to_subpath $optdisk tempdisk
	dogi_device_slice $tempdisk $optno optslice
	dogi_slice_rawpath $optslice optrpath
	dogi_slice_blkpath $optslice optbpath
	doit sed -e "s;/dev/vx/dsk/opt\\([	 ]\\);${optbpath}\\1;" \
	 -e "s;/dev/vx/rdsk/opt\\([	 ]\\);${optrpath}\\1;" \
		< $SYSROOT/etc/vfstab > $tmpfile1 || quit 10

	doit mv $tmpfile1 $SYSROOT/etc/vfstab || quit 10
	echo opt >> $rmvols
	(grep $optdisk $rmvmdisks 2>&1 ) > /dev/null
	if [ $? -ne 0 ] ; then
		echo $optdisk >> $rmvmdisks
	fi
fi


doit rm -f $rootfile $rootsvfile

#
# 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
