#!/usr/bin/ksh ############################################################################### # Copyright (c) 2005, William Favorite # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # Neither the name of iSys nor the names of its contributors may be used to # endorse or promote products derived from this software without specific # prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. ############################################################################### # Constants tempfile=/tmp/mvdev.out # Globals fromdisk=$1 todisk=$2 adisk= W= P= T= S= # Check our parameters if [ "${fromdisk}x" = "x" ] then echo "ERROR: No source disk in command options." exit fi adisk=`echo ${fromdisk} | grep "hdisk[0-9][0-9]*"` if [ "${adisk}" != "${fromdisk}" ] then echo "ERROR: Source disk does not look like a disk to me." exit fi adisk=`echo ${todisk} | grep "hdisk[0-9][0-9]*"` if [ "${adisk}" != "${todisk}" ] then echo "ERROR: Destination disk does not look like a disk to me." exit fi if [ "${todisk}x" = "x" ] then echo "ERROR: No target disk in command options." exit fi # Check to see if the source disk exists if [ 0 -eq `lsdev -l ${fromdisk} | wc -l` ] then echo "ERROR: Source disk does not exist." exit fi # Check to see if the disk is in a volume group. lspv should return 0 lspv -l ${fromdisk} > /dev/null 2>&1 ERR=$? # Uncomment the following line if you want to act on disks that may belong # to a volume group. # ERR=1 if [ ${ERR} -eq 0 ] then echo "ERROR: Existing disk is in a volume group." exit fi # Check to see if the target disk exists if [ 1 -eq `lsdev -l ${todisk} | wc -l` ] then echo "ERROR: New disk already exists." exit fi # Query the source disk from the ODM database odmget -q name=${fromdisk} CuDv > ${tempfile} # Extract the info we are looking for W=`grep connwhere ${tempfile} | sed -e "s/^.* \"//" | sed -e "s/\"$//"` P=`grep parent ${tempfile} | sed -e "s/^.* \"//" | sed -e "s/\"$//"` T=`grep PdDvLn ${tempfile} | sed -e "s|^.*/||" | sed -e "s/\"$//"` S=`grep PdDvLn ${tempfile} | sed -e "s|^.*\"[a-z]*/||" | sed -e "s|/.*\"$||"` if [ -z "$W" ] then echo "ERROR: Unable to determine connection location info." exit fi if [ -z "$P" ] then echo "ERROR: Unable to determine parent info." exit fi if [ -z "$T" ] then echo "ERROR: Unable to determine type info." exit fi if [ -z "$S" ] then echo "ERROR: Unable to determine Subclass info." exit fi # Remove the temp file rm -f ${tempfile} # Now for actual disk operations... Note: It was desired that the destination # disk createion (attempt) be first, so that the source would only be removed # conditionally. AIX would not allow this. # Remove the source disk rmdev -d -l ${fromdisk} ERR=$? if [ $ERR -ne 0 ] then echo "ERROR: Unable to remove device ${fromdisk}." exit fi # Re-create it as the target disk mkdev -c disk -s ${S} -p ${P} -t ${T} -l ${todisk} -w \"${W}\" ERR=$? if [ $ERR -ne 0 ] then echo "ERROR: Unable to create device ${todisk}." echo " Tyring to put things back like they were." mkdev -c disk -s ${S} -p ${P} -t ${T} -l ${fromdisk} -w \"${W}\" exit fi #[root@calcutta fav]# odmget -q name=hdisk11 CuDv # #CuDv: # name = "hdisk11" # status = 1 # chgstatus = 0 # ddins = "scdisk" # location = "10-68-00-6,0" # parent = "scsi2" # connwhere = "6,0" # PdDvLn = "disk/scsi/osdisk"