Visualize the Physical Layout of an AIX Volume Group

From: Brian Smith’s AIX / UNIX / Linux / Open Source blog

9/23/13 Update – See this updated verison of the script as well.  

Here is a script I’ve written to visualize the physical layout of an AIX volume group.   The script visually shows the location of every Physical Partition (PP) on each hdisk (AKA Physical Volume).   The output shows which Logical Volume (LV) is on each of the PP’s (or if it is free space).   The output is color coded so each LV has its own color so that it is very easy to see where each LV physically is across the entire Volume Group.  You can specify the number of columns of output depending on the size of your screen.

The intended use of the script is to show a visual representation of the Volume Group to make using commands which move around LP’s/PP’s such as migratelp easier to use, to make LVM/disk maintenance easier, and also as a learning tool.

Here are a few screenshots:

image

image

 image

  When running the script you specify 2 parameters:  The volume group name, and the number of columns you would like displayed (or it will default to 3 columns if not specified).

Here is the script:

 #!/bin/ksh

#vvg - visualize physical layout of AIX volume group
#Copyright Brian Smith, 2013

index=0
set -A colors 41m 42m 43m 44m 45m 46m 47m 100m 101m 102m 103m 104m 105m 106m
tempfile=”/tmp/`basename $0`_$$”
tempfile2=”/tmp/`basename $0`_2$$”
> $tempfile
> $tempfile2

if [ -n “$1” ]; then
vg=$1
else
echo “Specify VG name as first parameter”
exit 1
fi

if ! lsvg $vg >/dev/null 2>&1; then
echo “Error: VG name not correct or VG not varried on”
exit 2
fi

[ -n “$2” ] && col=$2 || col=3
if ! echo $col | grep “^[0-9]*$” >/dev/null || [ “$col” -eq 0 ]; then
echo “Error: second parameter should be number of columns”
exit 3
fi

count=0
columns=””
while [ “$count” -lt “$col” ]; do
columns=”$columns -”
count=`expr $count + 1`
done

showdisk()
{
. $tempfile
. $tempfile2
[ “$index” -gt 0 ] && index=`expr $index + 1`
pv=$1
lspv -M $pv | while read line; do
if echo $line |  awk ‘NF==1 {print}’ | grep ‘-‘ >/dev/null; then
                    beg=`echo $line | awk -F: ‘{print $2}’ | awk -F ‘-‘ ‘{print $1}’`
                    end=`echo $line | awk -F: ‘{print $2}’ | awk -F ‘-‘ ‘{print $2}’`
                    while [ “$beg” -le “$end” ]; do
                            echo “${pv}:$beg Free”
                            beg=`expr $beg + 1`
                    done
elif echo $line | awk -F: ‘{print $2}’ | grep “^[0-9]*$” >/dev/null ; then
                    echo “$line Free”
else
                    echo “$line”
fi
done | while read line2; do
pp=`echo “$line2” | awk ‘{print $1}’ | awk -F: ‘{print $2}’`
lv=`echo “$line2” | awk ‘{print $2}’ | awk -F: ‘{print $1}’`
lp=`echo “$line2″ | awk ‘{print $2}’ | awk -F: ‘{print $2}’`

eval if ! [ -n \”\$${lv}\” ]\; then \
                    ${lv}=$index\;        \
                    echo ${lv}=$index \>\> $tempfile  \; \
                    index=`expr $index + 1`\;   \
                    [ \”\$index\” -gt \”13\” ] \&\& index=0 \; \
                    echo index=$index \> $tempfile2  \; \
fi
eval printf  \\\\033[\${colors[\$${lv}]}
if [ -n “$lp” ]; then
                    printf “%-7s %-15s %+7s\033[0m ” “PP$pp” “$lv” “LP$lp”
else
                    printf “%-7s %-23s\033[0m ” “PP$pp” “$lv”
fi
echo
done | paste -d ” ” $columns
}

for pv in `lspv | grep ” $vg ” | awk ‘{print $1}’`; do
ppsize=`lspv $pv | grep “^PP SIZE” | awk ‘{print $3 ” ” $4}’`
echo “\033[1;36m******************************* \033[0m”
printf “\033[1;36m* %-8s                    * \n\033[0m” $pv
printf “\033[1;36m* Size   : %-10s         * \n\033[0m” “`getconf DISK_SIZE /dev/$pv` MB”
printf “\033[1;36m* PP Size: %-19s* \n\033[0m” “$ppsize”
echo “\033[1;36m******************************* \033[0m”
showdisk $pv
done
rm $tempfile
rm $tempfile2

Leave a Reply