{p06701csmp03}/software/scripts/IDD$ cat lvm.ksh
#!/usr/bin/ksh
######################################################################################################
#
# Name: lvm.ksh
#
# Purpose: To Create VG, LV, FS for both standalone and HACMP systems (excluding raw LV & ASM disks)
#
# Authors: Prakash Rajendran
#
# Change history
#
# Date | Author | Version| Reason
# ----------+--------------+--------+--------------------------
# 01/04/11 | PR | 1.0 | Initial Version
#
# More information can be found in the documentation as per below link:
#
#
# NOTES:
# This script is used to create VG, LV, FS on both standalone & HA systems with LBG standards
#
#
#######################################################################################################
# Common Variables
HOST=$(hostname)
MAP_FILE=/tmp/${HOST}.map
LOG_FILE=/tmp/lvm.log.`date +"%d%h%y-%H:%M"`
ERROR="ERROR: $(hostname) : `date +"%H:%M:%S"` :"
INFO="INFO : $(hostname) : `date +"%H:%M:%S"` :"
DEBUG=$2
# Variables for HA nodes
if [ -s /usr/es/sbin/cluster/clstat ] ; then
cl_util=/usr/es/sbin/cluster/utilities
cl_spoc=/usr/es/sbin/cluster/sbin
NODE_A=$($cl_util/cllsnode |grep NODE |awk '{print $2}' |cut -d: -f1 |head -1)
NODE_B=$($cl_util/cllsnode |grep NODE |awk '{print $2}' |cut -d: -f1 |tail -1)
fi
echo "$INFO Running script lvm.ksh" |tee $LOG_FILE
function vg_create
{
# Debugging check
if [ ! -z $DEBUG ] && [ $DEBUG = -d ] ; then
set -x
fi
echo "$INFO Calling Module vg" |tee $LOG_FILE
if [ -s $MAP_FILE ]; then
vg_cnt=`grep -p ^vg $MAP_FILE |sed 's/^$/d/' |grep -v ^vg |wc -l`
if [ $vg_cnt -gt 0 ] ; then
grep -v "#" $MAP_FILE |grep -p ^vg |sed '$d' |grep -v ^vg |while read line
do
rm /tmp/asm_disks > /dev/null 2>&1 ; rm /tmp/hdisks > /dev/null 2>&1 ; rm /tmp/active_hdisks > /dev/null 2>&1
touch /tmp/asm_disks ; touch /tmp/active_hdisks
echo $line |awk -F":" '{print $1}' |read VG_NAME
echo $line |awk -F":" '{print $2}' |read MGR_NUM
echo $line |awk -F":" '{print $3}' |read MIRROR
echo $line |awk -F":" '{print $4}' |read HDISK
echo $line |awk -F":" '{print $4}' |tr ' ' '\n' >> /tmp/hdisks
print "$INFO Processing line '$line'" |tee $LOG_FILE
for PV in `cat /tmp/hdisks`
do
MAJ=`ls -ltr /dev |sed 's/,/ /'|grep -w $PV|awk '{print $5}'`
MIN=`ls -ltr /dev |sed 's/,/ /'|grep -w $PV|awk '{print $6}'`
ASM=`ls -ltr /dev |sed 's/,/ /'|awk -v MJ="$MAJ" '($5 == MJ) {print $0}'|awk -v MN="$MIN" '($6 == MN) {print $10}'`
ASM_NEW=`echo "$ASM"|sed -e "s/^$PV//" -e "s/^r$PV//"`
if [ ! -z $ASM_NEW ] ; then
echo $ASM_NEW >> /tmp/asm_disks
fi
lspv |grep -v None |grep -w $PV >> /tmp/active_hdisks
if lspv |grep -w $PV > /dev/null 2>&1 ; then
hcheck=`lsattr -El $PV |grep hcheck_interval |awk '{print $2}'`
if [ $hcheck -ne 60 ] ; then
print "\033[1;31m$ERROR Attribute hcheck_interval is not set to 60 for $PV\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR $PV does not exist in the system\033[m" |tee -a $LOG_FILE
return
fi
done
if lsvg |grep -w $VG_NAME > /dev/null 2>&1 ; then
print "\033[1;31m$ERROR $VG_NAME already present & will be ignored\033[m" |tee -a $LOG_FILE
else
if ls -lrt /dev |awk '{print $5}' |cut -d, -f1 |sort -u |grep $MGR_NUM > /dev/null 2>&1 ; then
print "\033[1;31m$ERROR Major Number $MGR_NUM already used. Select another major number for $VG_NAME and try again\033[m" |tee -a $LOG_FILE
else
if [ -s /tmp/active_hdisks ] || [ -s /tmp/asm_disks ] ; then
print "\033[1;31m$ERROR Some of the hdisks are part of existing VG or used as ASM disks. Correct them and retry\033[m" |tee -a $LOG_FILE
else
if echo $line |awk -F":" '{print $1}' |grep ^lo_ > /dev/null 2>&1; then
print "$INFO Creating Volume Group $VG_NAME" |tee -a $LOG_FILE
print "$INFO mkvg -B -s 256 -y $VG_NAME -V $MGR_NUM $HDISK" |tee -a $LOG_FILE
mkvg -B -s 256 -y $VG_NAME -V $MGR_NUM $HDISK > /dev/null 2>&1
if [ $? = 0 ] ; then
print "\033[1;32m$INFO Successfully created $VG_NAME\033[m" |tee -a $LOG_FILE
if [ $MIRROR = y ] ; then
print "$INFO Changing Quorum Settings for $VG_NAME" |tee -a $LOG_FILE
chvg -Qn $VG_NAME > /dev/null 2>&1
fi
else
print "\033[1;31m$ERROR VG Creation failed\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR $VG_NAME is not starting with lo_ as this is local VG\033[m" |tee -a $LOG_FILE
fi
fi
fi
fi
done
else
print "\033[1;31m$ERROR VG details not found on $MAP_FILE\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR Input file $MAP_FILE does not exist\033[m" |tee -a $LOG_FILE
fi
}
function lv_create
{
# Debugging check
if [ ! -z $DEBUG ] && [ $DEBUG = -d ] ; then
set -x
fi
echo "$INFO Calling Module lv" |tee $LOG_FILE
if [ -s $MAP_FILE ]; then
lv_cnt=`grep -p ^lv $MAP_FILE |sed '/^$/d' |grep -v ^lv |wc -l`
if [ $lv_cnt -gt 0 ] ; then
grep -v "#" $MAP_FILE |grep -p ^lv |sed '/^$/d' |grep -v ^lv |while read lv_line
do
rm /tmp/lv_hdisks > /dev/null 2>&1
echo $lv_line |awk -F":" '{print $1}' |read LV_VG_NAME
echo $lv_line |awk -F":" '{print $2}' |read LV_NAME
echo $lv_line |awk -F":" '{print $3}' |read NO_LVS
echo $lv_line |awk -F":" '{print $4}' |read NO_COPIES
echo $lv_line |awk -F":" '{print $5}' |read MNT_PT
echo $lv_line |awk -F":" '{print $6}' |read SITE_A
echo $lv_line |awk -F":" '{print $7}' |read SITE_B
echo $lv_line |awk -F":" '{print $6}' |tr ' ' '\n' |sort -u >> /tmp/lv_hdisks ; cp -p /tmp/lv_hdisks /tmp/lv_hdisks_sitea
echo $lv_line |awk -F":" '{print $7}' |tr ' ' '\n' |sort -u |tee /tmp/lv_hdisks_siteb >> /tmp/lv_hdisks
print "$INFO Processing line '$lv_line' " |tee -a $LOG_FILE
for PV in `cat /tmp/lv_hdisks`
do
if lsvg |grep $LV_VG_NAME > /dev/null 2>&1 ; then
lsvg -o |grep $LV_VG_NAME > /dev/null 2>&1
if [ $? -ne 0 ] ; then
print "\033[1;31m$ERROR The volume group $LV_VG_NAME is not varied on\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR The volume group $LV_VG_NAME does not exist\033[m" |tee -a $LOG_FILE
return
fi
if lspv |grep -w $PV > /dev/null 2>&1 ; then
lsvg -Lp $LV_VG_NAME |grep -w $PV > /dev/null 2>&1
if [ $? -ne 0 ] ; then
print "\033[1;31m$ERROR $PV does not belong to $LV_VG_NAME\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR $PV does not exist in the system\033[m" |tee -a $LOG_FILE
return
fi
done
CNT_A=0
for A_ in `cat /tmp/lv_hdisks_sitea`
do
lsvg -Lp $LV_VG_NAME |grep $A_ |awk '{print $4}' |read SIZE
CNT_A=`expr $CNT_A + $SIZE`
done
CNT_B=0
for B_ in `cat /tmp/lv_hdisks_siteb`
do
lsvg -Lp $LV_VG_NAME |grep $B_ |awk '{print $4}' |read SIZE
CNT_B=`expr $CNT_B + $SIZE`
done
if [ $NO_COPIES -eq 2 ] ; then
INT=1
PVLIST=" "
ADISKS=`cat /tmp/lv_hdisks_sitea|wc -l`
BDISKS=`cat /tmp/lv_hdisks_siteb|wc -l`
[ "$ADISKS" -ge "$BDISKS" ] && CHECK=$ADISKS || CHECK=$BDISKS
until [ "$INT" -gt "$CHECK" ];
do
PV=`cat -n /tmp/lv_hdisks_sitea|grep -w $INT|awk '{print $2}'`
PV1=`cat -n /tmp/lv_hdisks_siteb|grep -w $INT|awk '{print $2}'`
PVLIST="$PVLIST $PV $PV1"
INT=`expr $INT + 1`
done
CMD="mklv -y $LV_NAME -t jfs2 -c$NO_COPIES -ss $LV_VG_NAME $NO_LVS $PVLIST"
if [ $CNT_A -gt $NO_LVS ] ; then
if [ $CNT_B -lt $NO_LVS ] ; then
print "\033[1;31m$ERROR There are not enough space in SITE B\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR There are not enough space in SITE A\033[m" |tee -a $LOG_FILE
return
fi
else
CMD="mklv -y $LV_NAME -t jfs2 -c$NO_COPIES $LV_VG_NAME $NO_LVS $SITE_A"
if [ $CNT_A -lt $NO_LVS ] ; then
print "\033[1;31m$ERROR There are not enough space to create the Filesystem $MNT_PT\033[m" |tee -a $LOG_FILE
return
fi
fi
LV_COUNT=`echo $LV_NAME |wc -c`
LV_COUNT=`expr $LV_COUNT - 1`
if [ $LV_VG_NAME == rootvg ] ; then
if [ $LV_COUNT -gt 11 ] ; then
print "\033[1;31m$ERROR The LV $LV_NAME is exceeding 11 characters limit. Reduce no.of characters and try again\033[m" |tee -a $LOG_FILE
return
fi
fi
lsvg -o |lsvg -iLl |grep -w $LV_NAME > /dev/null 2>&1
if [[ $? -eq 0 ]] ; then
print "\033[1;31m$ERROR The LV $LV_NAME is already present. Give another LV name\033[m" |tee -a $LOG_FILE
else
cat /etc/filesystems |grep -w $MNT_PT":" >/dev/null 2>&1
if [[ $? -eq 0 ]] ; then
print "\033[1;31m$ERROR The mount point $MNT_PT is already in use. Try another mount point\033[m" |tee -a $LOG_FILE
else
print "$INFO Creating Logical Volume $LV_NAME" |tee -a $LOG_FILE
$CMD > /dev/null 2>&1
if [ $? = 0 ] ; then
print "$INFO Creating File system $MNT_PT" |tee -a $LOG_FILE
crfs -v jfs2 -d $LV_NAME -a logname=INLINE -m $MNT_PT -Ay -t yes > /dev/null 2>&1
if [ $? = 0 ] ; then
print "$INFO Mounting file system $MNT_PT" |tee -a $LOG_FILE
mount $MNT_PT > /dev/null 2>&1
if [ $? = 0 ] ; then
print "\033[1;32m$INFO Successfully created file system $MNT_PT\033[m" |tee -a $LOG_FILE
print "\033[1;32m$INFO Please make sure to set the permission:ownership for $MNT_PT\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR File system creation failed for $MNT_PT\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR LV creation failed for $LV_NAME\033[m" |tee -a $LOG_FILE
fi
fi
fi
done
else
print "\033[1;31m$ERROR LV details not found on $MAP_FILE\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR Input file $MAP_FILE does not exist\033[m" |tee -a $LOG_FILE
fi
}
function havg_create
{
# Debugging check
if [ ! -z $DEBUG ] && [ $DEBUG = -d ] ; then
set -x
fi
echo "\033[1;31mAre you sure newly assigned LUNs are having PVID & added them to specific sites in HA config & synced ? [y/n] :\033[m"
until [ "$rep" == "y" -o "$rep" == "n" ];do
echo "Reply: \c"
read rep
done
echo "$INFO Calling Module havg" |tee $LOG_FILE
if [ "$rep" == "y" ] ; then
if [ -s /usr/es/sbin/cluster/clstat ] ; then
if [ -s $MAP_FILE ]; then
havg_cnt=`grep -p ^havg $MAP_FILE |sed 's/^$/d/' |grep -v ^havg |wc -l`
if [ $havg_cnt -gt 0 ] ; then
grep -v "#" $MAP_FILE |grep -p ^havg |sed '$d' |grep -v ^havg |while read line
do
rm /tmp/asm_disks > /dev/null 2>&1 ; rm /tmp/hdisks > /dev/null 2>&1 ; rm /tmp/active_hdisks > /dev/null 2>&1
touch /tmp/asm_disks ; touch /tmp/active_hdisks
echo $line |awk -F":" '{print $1}' |read VG_NAME
echo $line |awk -F":" '{print $2}' |read MGR_NUM
echo $line |awk -F":" '{print $4}' |read HDISK
echo $line |awk -F":" '{print $4}' |tr ' ' '\n' >> /tmp/hdisks
echo $line |awk -F":" '{print $3}' |read MIRROR
print "$INFO Processing line '$line'" |tee -a $LOG_FILE
for PV in `cat /tmp/hdisks`
do
MAJ=`ls -ltr /dev |sed 's/,/ /'|grep -w $PV|awk '{print $5}'`
MIN=`ls -ltr /dev |sed 's/,/ /'|grep -w $PV|awk '{print $6}'`
ASM=`ls -ltr /dev |sed 's/,/ /'|awk -v MJ="$MAJ" '($5 == MJ) {print $0}'|awk -v MN="$MIN" '($6 == MN) {print $10}'`
ASM_NEW=`echo "$ASM"|sed -e "s/^$PV//" -e "s/^r$PV//"`
if [ ! -z $ASM_NEW ] ; then
echo $ASM_NEW >> /tmp/asm_disks
fi
lspv |grep -v None |grep -w $PV >> /tmp/active_hdisks
if lspv |grep -w $PV > /dev/null 2>&1 ; then
hcheck=`lsattr -El $PV |grep hcheck_interval |awk '{print $2}'`
if [ $hcheck -ne 60 ] ; then
print "\033[1;31m$ERROR Attribute hcheck_interval is not set to 60 for $PV\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR $PV does not exist in the system\033[m" |tee -a $LOG_FILE
return
fi
done
if lsvg |grep -w $VG_NAME > /dev/null 2>&1 ; then
print "$INFO $VG_NAME already present & will be ignored" |tee -a $LOG_FILE
else
if ls -lrt /dev |awk '{print $5}' |cut -d, -f1 |sort -u |grep $MGR_NUM > /dev/null 2>&1 ; then
print "\033[1;31m$ERROR Major Number $MGR_NUM already used. Select another major number for $VG_NAME and try again\033[m" |tee -a $LOG_FILE
else
if [ -s /tmp/active_hdisks ] || [ -s /tmp/asm_disks ] ; then
print "\033[1;31m$ERROR Some of the hdisks are part of existing VG or used as ASM disks. Correct them and retry\033[m" |tee -a $LOG_FILE
else
if echo $line |awk -F":" '{print $1}' |grep ^sh_ > /dev/null 2>&1; then
print "$INFO Creating Volume Group $VG_NAME" |tee -a $LOG_FILE
$cl_spoc/cl_mkvg -cspoc "-n$NODE_A,$NODE_B" -C -B -s 256 -l true -V $MGR_NUM -y $VG_NAME $HDISK > /dev/null 2>&1
if [ $? = 0 ] ; then
print "\033[1;32m$INFO Successfully created $VG_NAME\033[m" |tee -a $LOG_FILE
print "\033[1;32m$INFO Please make sure to add VG $VG_NAME into HACMP RG configuration and sync\033[m" |tee -a $LOG_FILE
if [ $MIRROR = y ] ; then
$cl_spoc/cl_chvg -cspoc "-n$NODE_A,$NODE_B" -Qn $VG_NAME > /dev/null 2>&1
fi
else
print "\033[1;31m$ERROR VG creation failed for $VG_NAME\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR $VG_NAME is not starting with sh_ as this is shared VG\033[m" |tee -a $LOG_FILE
fi
fi
fi
fi
done
else
print "\033[1;31m$ERROR VG details not found on $MAP_FILE\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR Input file $MAP_FILE does not exist\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR This is not a HACMP node\033[m" |tee -a $LOG_FILE
fi
else
continue
fi
}
function halv_create
{
# Debugging check
if [ ! -z $DEBUG ] && [ $DEBUG = -d ] ; then
set -x
fi
echo "\033[1;31mAre you sure newly assigned LUNs are having PVID & added them to specific sites in HA config & synced ? [y/n] :\033[m"
rep=0
until [ "$rep" == "y" -o "$rep" == "n" ];do
echo "Reply: \c"
read rep
done
echo "$INFO Calling Module halv" |tee $LOG_FILE
if [ "$rep" == "y" ] ; then
if [ -s /usr/es/sbin/cluster/clstat ] ; then
if [ -s $MAP_FILE ]; then
halv_cnt=`grep -p ^halv $MAP_FILE |sed '/^$/d' |grep -v ^halv |wc -l`
if [ $halv_cnt -gt 0 ] ; then
grep -v "#" $MAP_FILE |grep -p ^halv |sed '/^$/d' |grep -v ^halv |while read halv_line
do
rm /tmp/halv_hdisks > /dev/null 2>&1
echo $halv_line |awk -F":" '{print $1}' |read LV_VG_NAME
echo $halv_line |awk -F":" '{print $2}' |read LV_NAME
echo $halv_line |awk -F":" '{print $3}' |read NO_LVS
echo $halv_line |awk -F":" '{print $4}' |read NO_COPIES
echo $halv_line |awk -F":" '{print $5}' |read MNT_PT
echo $halv_line |awk -F":" '{print $6}' |read SITE_A
echo $halv_line |awk -F":" '{print $7}' |read SITE_B
echo $halv_line |awk -F":" '{print $6}' |tr ' ' '\n' |sort -u >> /tmp/halv_hdisks ; cp -p /tmp/halv_hdisks /tmp/halv_hdisks_sitea
echo $halv_line |awk -F":" '{print $7}' |tr ' ' '\n' |sort -u |tee /tmp/halv_hdisks_siteb >> /tmp/halv_hdisks
print "$INFO Processing line '$halv_line' " |tee -a $LOG_FILE
for PV in `cat /tmp/halv_hdisks`
do
if lsvg |grep $LV_VG_NAME > /dev/null 2>&1 ; then
lsvg -o |grep $LV_VG_NAME > /dev/null 2>&1
if [ $? -ne 0 ] ; then
print "\033[1;31m$ERROR The volume group $LV_VG_NAME is not varied on as active\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR The volume group $LV_VG_NAME does not exist\033[m" |tee -a $LOG_FILE
return
fi
if lspv |grep -w $PV > /dev/null 2>&1 ; then
lsvg -Lp $LV_VG_NAME |grep -w $PV > /dev/null 2>&1
if [ $? -ne 0 ] ; then
print "\033[1;31m$ERROR $PV does not belong to $LV_VG_NAME\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR $PV does not exist in the system\033[m" |tee -a $LOG_FILE
return
fi
done
CNT_A=0
for A_ in `cat /tmp/halv_hdisks_sitea`
do
lsvg -Lp $LV_VG_NAME |grep $A_ |awk '{print $4}' |read SIZE
CNT_A=`expr $CNT_A + $SIZE`
done
CNT_B=0
for B_ in `cat /tmp/halv_hdisks_siteb`
do
lsvg -Lp $LV_VG_NAME |grep $B_ |awk '{print $4}' |read SIZE
CNT_B=`expr $CNT_B + $SIZE`
done
if [ $NO_COPIES -eq 2 ] ; then
INT=1
PVLIST=" "
ADISKS=`cat /tmp/halv_hdisks_sitea|wc -l`
BDISKS=`cat /tmp/halv_hdisks_siteb|wc -l`
[ "$ADISKS" -ge "$BDISKS" ] && CHECK=$ADISKS || CHECK=$BDISKS
until [ "$INT" -gt "$CHECK" ];
do
PV=`cat -n /tmp/halv_hdisks_sitea|grep -w $INT|awk '{print $2}'`
PV1=`cat -n /tmp/halv_hdisks_siteb|grep -w $INT|awk '{print $2}'`
PVLIST="$PVLIST $PV $PV1"
INT=`expr $INT + 1`
done
CMD="$cl_spoc/cl_mklv -cspoc "-n$NODE_A,$NODE_B" -R$HOST -tjfs2 -c$NO_COPIES -ss -y$LV_NAME $LV_VG_NAME $NO_LVS $PVLIST"
if [ $CNT_A -gt $NO_LVS ] ; then
if [ $CNT_B -lt $NO_LVS ] ; then
print "\033[1;31m$ERROR There are not enough space in SITE B\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR There are not enough space in SITE A\033[m" |tee -a $LOG_FILE
return
fi
else
CMD="$cl_spoc/cl_mklv -cspoc "-n$NODE_A,$NODE_B" -R$HOST -tjfs2 -c$NO_COPIES -y$LV_NAME $LV_VG_NAME $NO_LVS $SITE_A"
if [ $CNT_A -lt $NO_LVS ] ; then
print "\033[1;31m$ERROR There are not enough space to create the Filesystem $MNT_PT\033[m" |tee -a $LOG_FILE
return
fi
fi
LV_COUNT=`echo $LV_NAME |wc -c`
LV_COUNT=`expr $LV_COUNT - 1`
if [ $LV_VG_NAME == rootvg ] ; then
if [ $LV_COUNT -gt 11 ] ; then
print "\033[1;31m$ERROR LV $LV_NAME is exceeding 11 characters limit. Reduce no.of characters and try again\033[m" |tee -a $LOG_FILE
return
fi
fi
lsvg -o |lsvg -iLl |grep -w $LV_NAME > /dev/null 2>&1
if [[ $? -eq 0 ]] ; then
print "\033[1;31m$ERROR The LV $LV_NAME is already present. Give another LV name\033[m" |tee -a $LOG_FILE
else
cat /etc/filesystems |grep -w $MNT_PT":" >/dev/null 2>&1
if [[ $? -eq 0 ]] ; then
print "\033[1;31m$ERROR The mount point $MNT_PT is already in use. Try another mount point\033[m" |tee -a $LOG_FILE
else
print "$INFO Creating Logical Volume $LV_NAME" |tee -a $LOG_FILE
$CMD > /dev/null 2>&1
if [ $? = 0 ] ; then
print "$INFO Creating File system $MNT_PT" |tee -a $LOG_FILE
$cl_spoc/cl_crfs -cspoc "-n$NODE_A,$NODE_B" -v jfs2 -d $LV_NAME -a logname=INLINE -m $MNT_PT -t yesstr > /dev/null 2>&1
if [ $? = 0 ] ; then
print "\033[1;32m$INFO Successfully created file system $MNT_PT\033[m" |tee -a $LOG_FILE
print "\033[1;32m$INFO Please make sure to set the permission:ownership for $MNT_PT\033[m" |tee -a $LOG_FILE
else
print "\033[1;31m$ERROR Shared FS creation failed for $MNT_PT\033[m" |tee -a $LOG_FILE
fi
else
print "$\033[1;31m$ERROR Shared LV creation failed for $LV_NAME\033[m" |tee -a $LOG_FILE
fi
fi
fi
done
else
print "\033[1;31m$ERROR LV details not found on $MAP_FILE\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR Input file $MAP_FILE does not exist\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR This is not a HACMP node\033[m" |tee -a $LOG_FILE
fi
else
continue
fi
}
function syntax
{
echo "Usage: lvm.ksh <argument>"
Echo "Valid arguments : vg, lv, havg, halv, ALL"
}
case $1 in
vg)
vg_create
;;
lv)
lv_create
;;
havg)
havg_create
;;
halv)
halv_create
;;
ALL)
vg_create; lv_create; havg_create; halv_create
;;
*)
syntax
;;
esac
#!/usr/bin/ksh
######################################################################################################
#
# Name: lvm.ksh
#
# Purpose: To Create VG, LV, FS for both standalone and HACMP systems (excluding raw LV & ASM disks)
#
# Authors: Prakash Rajendran
#
# Change history
#
# Date | Author | Version| Reason
# ----------+--------------+--------+--------------------------
# 01/04/11 | PR | 1.0 | Initial Version
#
# More information can be found in the documentation as per below link:
#
#
# NOTES:
# This script is used to create VG, LV, FS on both standalone & HA systems with LBG standards
#
#
#######################################################################################################
# Common Variables
HOST=$(hostname)
MAP_FILE=/tmp/${HOST}.map
LOG_FILE=/tmp/lvm.log.`date +"%d%h%y-%H:%M"`
ERROR="ERROR: $(hostname) : `date +"%H:%M:%S"` :"
INFO="INFO : $(hostname) : `date +"%H:%M:%S"` :"
DEBUG=$2
# Variables for HA nodes
if [ -s /usr/es/sbin/cluster/clstat ] ; then
cl_util=/usr/es/sbin/cluster/utilities
cl_spoc=/usr/es/sbin/cluster/sbin
NODE_A=$($cl_util/cllsnode |grep NODE |awk '{print $2}' |cut -d: -f1 |head -1)
NODE_B=$($cl_util/cllsnode |grep NODE |awk '{print $2}' |cut -d: -f1 |tail -1)
fi
echo "$INFO Running script lvm.ksh" |tee $LOG_FILE
function vg_create
{
# Debugging check
if [ ! -z $DEBUG ] && [ $DEBUG = -d ] ; then
set -x
fi
echo "$INFO Calling Module vg" |tee $LOG_FILE
if [ -s $MAP_FILE ]; then
vg_cnt=`grep -p ^vg $MAP_FILE |sed 's/^$/d/' |grep -v ^vg |wc -l`
if [ $vg_cnt -gt 0 ] ; then
grep -v "#" $MAP_FILE |grep -p ^vg |sed '$d' |grep -v ^vg |while read line
do
rm /tmp/asm_disks > /dev/null 2>&1 ; rm /tmp/hdisks > /dev/null 2>&1 ; rm /tmp/active_hdisks > /dev/null 2>&1
touch /tmp/asm_disks ; touch /tmp/active_hdisks
echo $line |awk -F":" '{print $1}' |read VG_NAME
echo $line |awk -F":" '{print $2}' |read MGR_NUM
echo $line |awk -F":" '{print $3}' |read MIRROR
echo $line |awk -F":" '{print $4}' |read HDISK
echo $line |awk -F":" '{print $4}' |tr ' ' '\n' >> /tmp/hdisks
print "$INFO Processing line '$line'" |tee $LOG_FILE
for PV in `cat /tmp/hdisks`
do
MAJ=`ls -ltr /dev |sed 's/,/ /'|grep -w $PV|awk '{print $5}'`
MIN=`ls -ltr /dev |sed 's/,/ /'|grep -w $PV|awk '{print $6}'`
ASM=`ls -ltr /dev |sed 's/,/ /'|awk -v MJ="$MAJ" '($5 == MJ) {print $0}'|awk -v MN="$MIN" '($6 == MN) {print $10}'`
ASM_NEW=`echo "$ASM"|sed -e "s/^$PV//" -e "s/^r$PV//"`
if [ ! -z $ASM_NEW ] ; then
echo $ASM_NEW >> /tmp/asm_disks
fi
lspv |grep -v None |grep -w $PV >> /tmp/active_hdisks
if lspv |grep -w $PV > /dev/null 2>&1 ; then
hcheck=`lsattr -El $PV |grep hcheck_interval |awk '{print $2}'`
if [ $hcheck -ne 60 ] ; then
print "\033[1;31m$ERROR Attribute hcheck_interval is not set to 60 for $PV\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR $PV does not exist in the system\033[m" |tee -a $LOG_FILE
return
fi
done
if lsvg |grep -w $VG_NAME > /dev/null 2>&1 ; then
print "\033[1;31m$ERROR $VG_NAME already present & will be ignored\033[m" |tee -a $LOG_FILE
else
if ls -lrt /dev |awk '{print $5}' |cut -d, -f1 |sort -u |grep $MGR_NUM > /dev/null 2>&1 ; then
print "\033[1;31m$ERROR Major Number $MGR_NUM already used. Select another major number for $VG_NAME and try again\033[m" |tee -a $LOG_FILE
else
if [ -s /tmp/active_hdisks ] || [ -s /tmp/asm_disks ] ; then
print "\033[1;31m$ERROR Some of the hdisks are part of existing VG or used as ASM disks. Correct them and retry\033[m" |tee -a $LOG_FILE
else
if echo $line |awk -F":" '{print $1}' |grep ^lo_ > /dev/null 2>&1; then
print "$INFO Creating Volume Group $VG_NAME" |tee -a $LOG_FILE
print "$INFO mkvg -B -s 256 -y $VG_NAME -V $MGR_NUM $HDISK" |tee -a $LOG_FILE
mkvg -B -s 256 -y $VG_NAME -V $MGR_NUM $HDISK > /dev/null 2>&1
if [ $? = 0 ] ; then
print "\033[1;32m$INFO Successfully created $VG_NAME\033[m" |tee -a $LOG_FILE
if [ $MIRROR = y ] ; then
print "$INFO Changing Quorum Settings for $VG_NAME" |tee -a $LOG_FILE
chvg -Qn $VG_NAME > /dev/null 2>&1
fi
else
print "\033[1;31m$ERROR VG Creation failed\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR $VG_NAME is not starting with lo_ as this is local VG\033[m" |tee -a $LOG_FILE
fi
fi
fi
fi
done
else
print "\033[1;31m$ERROR VG details not found on $MAP_FILE\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR Input file $MAP_FILE does not exist\033[m" |tee -a $LOG_FILE
fi
}
function lv_create
{
# Debugging check
if [ ! -z $DEBUG ] && [ $DEBUG = -d ] ; then
set -x
fi
echo "$INFO Calling Module lv" |tee $LOG_FILE
if [ -s $MAP_FILE ]; then
lv_cnt=`grep -p ^lv $MAP_FILE |sed '/^$/d' |grep -v ^lv |wc -l`
if [ $lv_cnt -gt 0 ] ; then
grep -v "#" $MAP_FILE |grep -p ^lv |sed '/^$/d' |grep -v ^lv |while read lv_line
do
rm /tmp/lv_hdisks > /dev/null 2>&1
echo $lv_line |awk -F":" '{print $1}' |read LV_VG_NAME
echo $lv_line |awk -F":" '{print $2}' |read LV_NAME
echo $lv_line |awk -F":" '{print $3}' |read NO_LVS
echo $lv_line |awk -F":" '{print $4}' |read NO_COPIES
echo $lv_line |awk -F":" '{print $5}' |read MNT_PT
echo $lv_line |awk -F":" '{print $6}' |read SITE_A
echo $lv_line |awk -F":" '{print $7}' |read SITE_B
echo $lv_line |awk -F":" '{print $6}' |tr ' ' '\n' |sort -u >> /tmp/lv_hdisks ; cp -p /tmp/lv_hdisks /tmp/lv_hdisks_sitea
echo $lv_line |awk -F":" '{print $7}' |tr ' ' '\n' |sort -u |tee /tmp/lv_hdisks_siteb >> /tmp/lv_hdisks
print "$INFO Processing line '$lv_line' " |tee -a $LOG_FILE
for PV in `cat /tmp/lv_hdisks`
do
if lsvg |grep $LV_VG_NAME > /dev/null 2>&1 ; then
lsvg -o |grep $LV_VG_NAME > /dev/null 2>&1
if [ $? -ne 0 ] ; then
print "\033[1;31m$ERROR The volume group $LV_VG_NAME is not varied on\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR The volume group $LV_VG_NAME does not exist\033[m" |tee -a $LOG_FILE
return
fi
if lspv |grep -w $PV > /dev/null 2>&1 ; then
lsvg -Lp $LV_VG_NAME |grep -w $PV > /dev/null 2>&1
if [ $? -ne 0 ] ; then
print "\033[1;31m$ERROR $PV does not belong to $LV_VG_NAME\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR $PV does not exist in the system\033[m" |tee -a $LOG_FILE
return
fi
done
CNT_A=0
for A_ in `cat /tmp/lv_hdisks_sitea`
do
lsvg -Lp $LV_VG_NAME |grep $A_ |awk '{print $4}' |read SIZE
CNT_A=`expr $CNT_A + $SIZE`
done
CNT_B=0
for B_ in `cat /tmp/lv_hdisks_siteb`
do
lsvg -Lp $LV_VG_NAME |grep $B_ |awk '{print $4}' |read SIZE
CNT_B=`expr $CNT_B + $SIZE`
done
if [ $NO_COPIES -eq 2 ] ; then
INT=1
PVLIST=" "
ADISKS=`cat /tmp/lv_hdisks_sitea|wc -l`
BDISKS=`cat /tmp/lv_hdisks_siteb|wc -l`
[ "$ADISKS" -ge "$BDISKS" ] && CHECK=$ADISKS || CHECK=$BDISKS
until [ "$INT" -gt "$CHECK" ];
do
PV=`cat -n /tmp/lv_hdisks_sitea|grep -w $INT|awk '{print $2}'`
PV1=`cat -n /tmp/lv_hdisks_siteb|grep -w $INT|awk '{print $2}'`
PVLIST="$PVLIST $PV $PV1"
INT=`expr $INT + 1`
done
CMD="mklv -y $LV_NAME -t jfs2 -c$NO_COPIES -ss $LV_VG_NAME $NO_LVS $PVLIST"
if [ $CNT_A -gt $NO_LVS ] ; then
if [ $CNT_B -lt $NO_LVS ] ; then
print "\033[1;31m$ERROR There are not enough space in SITE B\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR There are not enough space in SITE A\033[m" |tee -a $LOG_FILE
return
fi
else
CMD="mklv -y $LV_NAME -t jfs2 -c$NO_COPIES $LV_VG_NAME $NO_LVS $SITE_A"
if [ $CNT_A -lt $NO_LVS ] ; then
print "\033[1;31m$ERROR There are not enough space to create the Filesystem $MNT_PT\033[m" |tee -a $LOG_FILE
return
fi
fi
LV_COUNT=`echo $LV_NAME |wc -c`
LV_COUNT=`expr $LV_COUNT - 1`
if [ $LV_VG_NAME == rootvg ] ; then
if [ $LV_COUNT -gt 11 ] ; then
print "\033[1;31m$ERROR The LV $LV_NAME is exceeding 11 characters limit. Reduce no.of characters and try again\033[m" |tee -a $LOG_FILE
return
fi
fi
lsvg -o |lsvg -iLl |grep -w $LV_NAME > /dev/null 2>&1
if [[ $? -eq 0 ]] ; then
print "\033[1;31m$ERROR The LV $LV_NAME is already present. Give another LV name\033[m" |tee -a $LOG_FILE
else
cat /etc/filesystems |grep -w $MNT_PT":" >/dev/null 2>&1
if [[ $? -eq 0 ]] ; then
print "\033[1;31m$ERROR The mount point $MNT_PT is already in use. Try another mount point\033[m" |tee -a $LOG_FILE
else
print "$INFO Creating Logical Volume $LV_NAME" |tee -a $LOG_FILE
$CMD > /dev/null 2>&1
if [ $? = 0 ] ; then
print "$INFO Creating File system $MNT_PT" |tee -a $LOG_FILE
crfs -v jfs2 -d $LV_NAME -a logname=INLINE -m $MNT_PT -Ay -t yes > /dev/null 2>&1
if [ $? = 0 ] ; then
print "$INFO Mounting file system $MNT_PT" |tee -a $LOG_FILE
mount $MNT_PT > /dev/null 2>&1
if [ $? = 0 ] ; then
print "\033[1;32m$INFO Successfully created file system $MNT_PT\033[m" |tee -a $LOG_FILE
print "\033[1;32m$INFO Please make sure to set the permission:ownership for $MNT_PT\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR File system creation failed for $MNT_PT\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR LV creation failed for $LV_NAME\033[m" |tee -a $LOG_FILE
fi
fi
fi
done
else
print "\033[1;31m$ERROR LV details not found on $MAP_FILE\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR Input file $MAP_FILE does not exist\033[m" |tee -a $LOG_FILE
fi
}
function havg_create
{
# Debugging check
if [ ! -z $DEBUG ] && [ $DEBUG = -d ] ; then
set -x
fi
echo "\033[1;31mAre you sure newly assigned LUNs are having PVID & added them to specific sites in HA config & synced ? [y/n] :\033[m"
until [ "$rep" == "y" -o "$rep" == "n" ];do
echo "Reply: \c"
read rep
done
echo "$INFO Calling Module havg" |tee $LOG_FILE
if [ "$rep" == "y" ] ; then
if [ -s /usr/es/sbin/cluster/clstat ] ; then
if [ -s $MAP_FILE ]; then
havg_cnt=`grep -p ^havg $MAP_FILE |sed 's/^$/d/' |grep -v ^havg |wc -l`
if [ $havg_cnt -gt 0 ] ; then
grep -v "#" $MAP_FILE |grep -p ^havg |sed '$d' |grep -v ^havg |while read line
do
rm /tmp/asm_disks > /dev/null 2>&1 ; rm /tmp/hdisks > /dev/null 2>&1 ; rm /tmp/active_hdisks > /dev/null 2>&1
touch /tmp/asm_disks ; touch /tmp/active_hdisks
echo $line |awk -F":" '{print $1}' |read VG_NAME
echo $line |awk -F":" '{print $2}' |read MGR_NUM
echo $line |awk -F":" '{print $4}' |read HDISK
echo $line |awk -F":" '{print $4}' |tr ' ' '\n' >> /tmp/hdisks
echo $line |awk -F":" '{print $3}' |read MIRROR
print "$INFO Processing line '$line'" |tee -a $LOG_FILE
for PV in `cat /tmp/hdisks`
do
MAJ=`ls -ltr /dev |sed 's/,/ /'|grep -w $PV|awk '{print $5}'`
MIN=`ls -ltr /dev |sed 's/,/ /'|grep -w $PV|awk '{print $6}'`
ASM=`ls -ltr /dev |sed 's/,/ /'|awk -v MJ="$MAJ" '($5 == MJ) {print $0}'|awk -v MN="$MIN" '($6 == MN) {print $10}'`
ASM_NEW=`echo "$ASM"|sed -e "s/^$PV//" -e "s/^r$PV//"`
if [ ! -z $ASM_NEW ] ; then
echo $ASM_NEW >> /tmp/asm_disks
fi
lspv |grep -v None |grep -w $PV >> /tmp/active_hdisks
if lspv |grep -w $PV > /dev/null 2>&1 ; then
hcheck=`lsattr -El $PV |grep hcheck_interval |awk '{print $2}'`
if [ $hcheck -ne 60 ] ; then
print "\033[1;31m$ERROR Attribute hcheck_interval is not set to 60 for $PV\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR $PV does not exist in the system\033[m" |tee -a $LOG_FILE
return
fi
done
if lsvg |grep -w $VG_NAME > /dev/null 2>&1 ; then
print "$INFO $VG_NAME already present & will be ignored" |tee -a $LOG_FILE
else
if ls -lrt /dev |awk '{print $5}' |cut -d, -f1 |sort -u |grep $MGR_NUM > /dev/null 2>&1 ; then
print "\033[1;31m$ERROR Major Number $MGR_NUM already used. Select another major number for $VG_NAME and try again\033[m" |tee -a $LOG_FILE
else
if [ -s /tmp/active_hdisks ] || [ -s /tmp/asm_disks ] ; then
print "\033[1;31m$ERROR Some of the hdisks are part of existing VG or used as ASM disks. Correct them and retry\033[m" |tee -a $LOG_FILE
else
if echo $line |awk -F":" '{print $1}' |grep ^sh_ > /dev/null 2>&1; then
print "$INFO Creating Volume Group $VG_NAME" |tee -a $LOG_FILE
$cl_spoc/cl_mkvg -cspoc "-n$NODE_A,$NODE_B" -C -B -s 256 -l true -V $MGR_NUM -y $VG_NAME $HDISK > /dev/null 2>&1
if [ $? = 0 ] ; then
print "\033[1;32m$INFO Successfully created $VG_NAME\033[m" |tee -a $LOG_FILE
print "\033[1;32m$INFO Please make sure to add VG $VG_NAME into HACMP RG configuration and sync\033[m" |tee -a $LOG_FILE
if [ $MIRROR = y ] ; then
$cl_spoc/cl_chvg -cspoc "-n$NODE_A,$NODE_B" -Qn $VG_NAME > /dev/null 2>&1
fi
else
print "\033[1;31m$ERROR VG creation failed for $VG_NAME\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR $VG_NAME is not starting with sh_ as this is shared VG\033[m" |tee -a $LOG_FILE
fi
fi
fi
fi
done
else
print "\033[1;31m$ERROR VG details not found on $MAP_FILE\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR Input file $MAP_FILE does not exist\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR This is not a HACMP node\033[m" |tee -a $LOG_FILE
fi
else
continue
fi
}
function halv_create
{
# Debugging check
if [ ! -z $DEBUG ] && [ $DEBUG = -d ] ; then
set -x
fi
echo "\033[1;31mAre you sure newly assigned LUNs are having PVID & added them to specific sites in HA config & synced ? [y/n] :\033[m"
rep=0
until [ "$rep" == "y" -o "$rep" == "n" ];do
echo "Reply: \c"
read rep
done
echo "$INFO Calling Module halv" |tee $LOG_FILE
if [ "$rep" == "y" ] ; then
if [ -s /usr/es/sbin/cluster/clstat ] ; then
if [ -s $MAP_FILE ]; then
halv_cnt=`grep -p ^halv $MAP_FILE |sed '/^$/d' |grep -v ^halv |wc -l`
if [ $halv_cnt -gt 0 ] ; then
grep -v "#" $MAP_FILE |grep -p ^halv |sed '/^$/d' |grep -v ^halv |while read halv_line
do
rm /tmp/halv_hdisks > /dev/null 2>&1
echo $halv_line |awk -F":" '{print $1}' |read LV_VG_NAME
echo $halv_line |awk -F":" '{print $2}' |read LV_NAME
echo $halv_line |awk -F":" '{print $3}' |read NO_LVS
echo $halv_line |awk -F":" '{print $4}' |read NO_COPIES
echo $halv_line |awk -F":" '{print $5}' |read MNT_PT
echo $halv_line |awk -F":" '{print $6}' |read SITE_A
echo $halv_line |awk -F":" '{print $7}' |read SITE_B
echo $halv_line |awk -F":" '{print $6}' |tr ' ' '\n' |sort -u >> /tmp/halv_hdisks ; cp -p /tmp/halv_hdisks /tmp/halv_hdisks_sitea
echo $halv_line |awk -F":" '{print $7}' |tr ' ' '\n' |sort -u |tee /tmp/halv_hdisks_siteb >> /tmp/halv_hdisks
print "$INFO Processing line '$halv_line' " |tee -a $LOG_FILE
for PV in `cat /tmp/halv_hdisks`
do
if lsvg |grep $LV_VG_NAME > /dev/null 2>&1 ; then
lsvg -o |grep $LV_VG_NAME > /dev/null 2>&1
if [ $? -ne 0 ] ; then
print "\033[1;31m$ERROR The volume group $LV_VG_NAME is not varied on as active\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR The volume group $LV_VG_NAME does not exist\033[m" |tee -a $LOG_FILE
return
fi
if lspv |grep -w $PV > /dev/null 2>&1 ; then
lsvg -Lp $LV_VG_NAME |grep -w $PV > /dev/null 2>&1
if [ $? -ne 0 ] ; then
print "\033[1;31m$ERROR $PV does not belong to $LV_VG_NAME\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR $PV does not exist in the system\033[m" |tee -a $LOG_FILE
return
fi
done
CNT_A=0
for A_ in `cat /tmp/halv_hdisks_sitea`
do
lsvg -Lp $LV_VG_NAME |grep $A_ |awk '{print $4}' |read SIZE
CNT_A=`expr $CNT_A + $SIZE`
done
CNT_B=0
for B_ in `cat /tmp/halv_hdisks_siteb`
do
lsvg -Lp $LV_VG_NAME |grep $B_ |awk '{print $4}' |read SIZE
CNT_B=`expr $CNT_B + $SIZE`
done
if [ $NO_COPIES -eq 2 ] ; then
INT=1
PVLIST=" "
ADISKS=`cat /tmp/halv_hdisks_sitea|wc -l`
BDISKS=`cat /tmp/halv_hdisks_siteb|wc -l`
[ "$ADISKS" -ge "$BDISKS" ] && CHECK=$ADISKS || CHECK=$BDISKS
until [ "$INT" -gt "$CHECK" ];
do
PV=`cat -n /tmp/halv_hdisks_sitea|grep -w $INT|awk '{print $2}'`
PV1=`cat -n /tmp/halv_hdisks_siteb|grep -w $INT|awk '{print $2}'`
PVLIST="$PVLIST $PV $PV1"
INT=`expr $INT + 1`
done
CMD="$cl_spoc/cl_mklv -cspoc "-n$NODE_A,$NODE_B" -R$HOST -tjfs2 -c$NO_COPIES -ss -y$LV_NAME $LV_VG_NAME $NO_LVS $PVLIST"
if [ $CNT_A -gt $NO_LVS ] ; then
if [ $CNT_B -lt $NO_LVS ] ; then
print "\033[1;31m$ERROR There are not enough space in SITE B\033[m" |tee -a $LOG_FILE
return
fi
else
print "\033[1;31m$ERROR There are not enough space in SITE A\033[m" |tee -a $LOG_FILE
return
fi
else
CMD="$cl_spoc/cl_mklv -cspoc "-n$NODE_A,$NODE_B" -R$HOST -tjfs2 -c$NO_COPIES -y$LV_NAME $LV_VG_NAME $NO_LVS $SITE_A"
if [ $CNT_A -lt $NO_LVS ] ; then
print "\033[1;31m$ERROR There are not enough space to create the Filesystem $MNT_PT\033[m" |tee -a $LOG_FILE
return
fi
fi
LV_COUNT=`echo $LV_NAME |wc -c`
LV_COUNT=`expr $LV_COUNT - 1`
if [ $LV_VG_NAME == rootvg ] ; then
if [ $LV_COUNT -gt 11 ] ; then
print "\033[1;31m$ERROR LV $LV_NAME is exceeding 11 characters limit. Reduce no.of characters and try again\033[m" |tee -a $LOG_FILE
return
fi
fi
lsvg -o |lsvg -iLl |grep -w $LV_NAME > /dev/null 2>&1
if [[ $? -eq 0 ]] ; then
print "\033[1;31m$ERROR The LV $LV_NAME is already present. Give another LV name\033[m" |tee -a $LOG_FILE
else
cat /etc/filesystems |grep -w $MNT_PT":" >/dev/null 2>&1
if [[ $? -eq 0 ]] ; then
print "\033[1;31m$ERROR The mount point $MNT_PT is already in use. Try another mount point\033[m" |tee -a $LOG_FILE
else
print "$INFO Creating Logical Volume $LV_NAME" |tee -a $LOG_FILE
$CMD > /dev/null 2>&1
if [ $? = 0 ] ; then
print "$INFO Creating File system $MNT_PT" |tee -a $LOG_FILE
$cl_spoc/cl_crfs -cspoc "-n$NODE_A,$NODE_B" -v jfs2 -d $LV_NAME -a logname=INLINE -m $MNT_PT -t yesstr > /dev/null 2>&1
if [ $? = 0 ] ; then
print "\033[1;32m$INFO Successfully created file system $MNT_PT\033[m" |tee -a $LOG_FILE
print "\033[1;32m$INFO Please make sure to set the permission:ownership for $MNT_PT\033[m" |tee -a $LOG_FILE
else
print "\033[1;31m$ERROR Shared FS creation failed for $MNT_PT\033[m" |tee -a $LOG_FILE
fi
else
print "$\033[1;31m$ERROR Shared LV creation failed for $LV_NAME\033[m" |tee -a $LOG_FILE
fi
fi
fi
done
else
print "\033[1;31m$ERROR LV details not found on $MAP_FILE\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR Input file $MAP_FILE does not exist\033[m" |tee -a $LOG_FILE
fi
else
print "\033[1;31m$ERROR This is not a HACMP node\033[m" |tee -a $LOG_FILE
fi
else
continue
fi
}
function syntax
{
echo "Usage: lvm.ksh <argument>"
Echo "Valid arguments : vg, lv, havg, halv, ALL"
}
case $1 in
vg)
vg_create
;;
lv)
lv_create
;;
havg)
havg_create
;;
halv)
halv_create
;;
ALL)
vg_create; lv_create; havg_create; halv_create
;;
*)
syntax
;;
esac