disk_size.sh – Quick look at disk details

I’ve been doing many AIX server migrations lately. Some which involve taking a mksysb and restoring, others which involve presenting LUN’s from a SVC and then doing a migratepv. The latter can result in a large number of disks presented on the host, so I wrote a quick basic script which gives me the details that I need – hdisk name, size, vg, pvid and serial number.

Maybe someone out there will find it useful.

#!/bin/ksh
 
while getopts "g" OPTION
  do
        case ${OPTION} in
          g) BLOCK_SIZE="GB";;
        esac
  done
 
set -A hdisk `lspv | awk '{ print $1 }'`
set -A pvid `lspv | awk '{ print $2 }'`
set -A vg `lspv | awk '{ print $3 }'`
 
count=0
if [ "$BLOCK_SIZE" = "GB" ]; then
 while (( $count < ${#hdisk[*]} )); do
           hdisk_size_mb=`getconf DISK_SIZE /dev/${hdisk[$count]}`
           hdisk_size_gb=`expr $hdisk_size_mb / 1024`
           size[$count]=$hdisk_size_gb
        let count="count + 1"
 done
else
 while (( $count < ${#hdisk[*]} )); do
           size[$count]=`getconf DISK_SIZE /dev/${hdisk[$count]}`
        let count="count + 1"
 done
fi
 
count=0
while (( $count < ${#hdisk[*]} )); do
           serial[$count]=`lscfg -vl ${hdisk[$count]} | grep "Serial Number" | awk -F. '{print $NF}'`
        let count="count + 1"
 done
 
 
count=0
printf "%-10s %-10s %-15s %-20s %s\n" Disk Size VG PVID Serial
printf "%-10s %-10s %-15s %-20s %s\n" ---- ---- -- ---- ------
while (( $count < ${#hdisk[*]} )); do
           printf "%-10s %-10s %-15s %-20s %s\n" ${hdisk[$count]} ${size[$count]} ${vg[$count]} ${pvid[$count]} ${serial[$count]}
        let count="count + 1"
done
exit
root@AIX #> ./disk_size.sh
Disk       Size       VG              PVID                 Serial
----       ----       --              ----                 ------
hdisk0     286102     None            00c67a84bb96c0ac	   JZW4SL9C
hdisk1     286102     None            00c67a84bbc2fec7     JZVLZJ2C
hdisk2     286102     None            00c67a84d41ba824     JZVLK4BC
hdisk3     286102     None            00c67a84d436cdd3     JZVMUG2C
hdisk4     52224      None            00c67a8433f75e56     75LZ7211200
hdisk5     52224      None            00c67a849f0e70ba     75M17911163
hdisk6     52224      None            none                 75LZ7211201
hdisk7     52224      None            00c67a849f0f2453     75LZ7211202
hdisk8     204800     None            00c67a849ee59661     75LZ7211012
hdisk9     307200     rootvg          00c67a84a67c6b56     600507680180867BB00000000000000B
hdisk10    307200     datavg          00c67a84a67c87b3     600507680180867BB00000000000000C
hdisk11    46080      wpar1           00c67a84a67d4860     600507680180867BB00000000000000D
hdisk12    40960      wpar2           00c67a84a67cb55b     600507680180867BB00000000000000E
hdisk13    51200      wpar3           00c67a84a67cccc9     600507680180867CC00000000000000F
hdisk14    51200      wpar4           00c67a84a67ce357     600507680180867CC000000000000010
hdisk15    51200      wpar5           00c67a84a67cf6ae     600507680180867CC000000000000011

You can use the -g switch to make the size output in GB blocks.

2 thoughts on “disk_size.sh – Quick look at disk details


  1. #!/usr/bin/ksh -p

    #
    # Author: Andrey Klyachkin

    PATH=/usr/bin:/usr/sbin
    iflag=0
    lflag=0
    sep=" "

    PROG=${0##*/}

    usage() {
    echo "$PROG [-x | -c] [-l] [-i] [hdisk | vg]"
    echo "\t-x\toutput in CSV format"
    echo "\t-c\toutput in colon-separated format"
    echo "\t-l\tshow LUN sizes"
    echo "\t-i\tshow PVIDs"
    exit 1
    }

    printInfo() {
    if [ "x$1" == "x" ] ; then
    return
    fi
    hdisk=$1
    vg=$(lspv $hdisk 2>/dev/null | head -1 | awk '{print $NF}')
    mtm=$(odmget -q name=$hdisk CuDv | grep PdDvLn | awk '{print $NF}')
    if [ "$mtm" == "\"disk/node/dlmfdrv\"" ] ; then
    m=$(odmget -q "name=$hdisk and attribute=PathInfo" CuAt | grep "value =" | awk '{print $NF}' | awk -F, '{print $1}' | sed -e 's/^"//')
    if [ "$m" == "1072" ] ; then
    mtm="XP12000"
    else
    mtm="$m"
    fi
    serial=$(odmget -q "name=$hdisk and attribute=PathInfo" CuAt | grep "value =" | awk -F, '{print $2}')
    ldev=$(odmget -q "name=$hdisk and attribute=PathInfo" CuAt | grep "value =" | awk -F, '{print $NF}' | sed -e 's/"$//')
    else
    uniqueid=$(odmget -q "name=$hdisk and attribute=unique_id" CuAt | grep "value =" | awk -F= '{print $NF}' | cut -f2 -d\")
    if [ "$mtm" == "\"disk/vscsi/vdisk\"" ] ; then
    slen=$(echo "$uniqueid" | cut -c3-4)
    slen=$(printf "%d" "0x$slen")
    slen=$((slen + 4))
    uniqueid=$(echo "$uniqueid" | cut -c5-$slen)
    fi
    slen=$(echo "$uniqueid" | cut -c1-2)
    slen=$(printf "%d" "0x$slen" 2>/dev/null)
    if [ $slen -ne 0 ] ; then
    slen=$(echo "$uniqueid" | cut -c3-4)
    slen=$(printf "%d" "0x$slen")
    slen=$((slen + 4))
    serial=$(echo "$uniqueid" | cut -c5-$slen)
    slen=$((slen + 1))
    mlen=$((slen + 1))
    mlen=$(echo "$uniqueid" | cut -c$slen-$mlen)
    mlen=$(printf "%d" "0x$mlen")
    slen=$((slen + 2))
    mlen=$((mlen + slen - 1))
    mtm=$(echo "$uniqueid" | cut -c$slen-$mlen)
    mlen=$((mlen + 1))
    slen=$((mlen + 1))
    slen=$(echo "$uniqueid" | cut -c$mlen-$slen)
    slen=$(printf "%d" "0x$slen")
    mlen=$((mlen + 2))
    slen=$((slen + mlen - 1))
    vendor=$(echo "$uniqueid" | cut -c$mlen-$slen)
    ldev="N/A"
    else
    if [ -z "$uniqueid" ] ; then
    ldev="N/A"
    vendor="N/A"
    mtm="N/A"
    serial="N/A"
    lscfg -vl $hdisk | awk -F. '/Manufacturer./ {vendor=$NF} /Machine Type and Model./ {mtm=$NF} /Serial Number./ {sub(" ",":",$NF);serial=$NF} /Device Specific.\(Z1\)./ {z1=$10} END { print vendor" "mtm" "serial" "z1 }' | read vendor mtm serial z1
    if [ "$vendor" == "HP" ] ; then
    ldev=$z1
    fi
    else
    ldev="N/A"
    mtm="LVM"
    vendor="VIOS"
    serial=$(echo "$uniqueid" | cut -c1-34)
    fi
    fi
    if [ "$vendor" == "IBM" ] ; then
    if [ "$mtm" == "2107900" ] ; then
    c=$(echo "$serial" | cut -c1)
    if [ "$c" == "3" ] ; then
    ldev=$(echo $serial | cut -c9-12)
    serial=$(echo $serial | cut -c2-8)
    else
    ldev=$(echo $serial | cut -c8-11)
    serial=$(echo $serial | cut -c1-7)
    fi
    mtm="IBM DS8K $mtm"
    elif [ "$mtm" == "2145" ] ; then
    c=$(echo "$serial" | cut -c2-)
    ldev="N/A"
    else
    mtm="$vendor $mtm"
    fi
    elif [ "$vendor" == "HP" ] ; then
    ldev=$(echo "$serial" | cut -c9-12)
    serial=$(echo "$serial" | cut -c4-8)
    serial=$(printf "%d" "0x$serial")
    if [ "$mtm" == "OPEN-V" ] ; then
    mtm="HP XP24000 ($mtm)"
    else
    mtm="$vendor $mtm"
    fi
    elif [ "$vendor" == "HITACHI" ] ; then
    if [ "$mtm" == "DF600F" ] ; then
    ldev=$(echo "$serial" | cut -c9-12)
    ldev=$(printf "%04d" "0x$ldev")
    serial=$(echo "$serial" | cut -c1-8)
    mtm="Hitachi AMS ($mtm)"
    else
    ldev=$(echo "$serial" | cut -c9-12)
    serial=$(echo "$serial" | cut -c4-8)
    serial=$(printf "%d" "0x$serial")
    mtm="$vendor $mtm"
    fi
    else
    mtm="$vendor $mtm"
    fi
    fi
    pvid=$(odmget -q "name=$hdisk and attribute=pvid" CuAt | grep "value =" | cut -f2 -d\" | cut -c1-16)
    size="$(($(bootinfo -s $hdisk) / 1024))G"
    c=$(odmget -q "name=$hdisk and attribute=node_name" CuPathAt | grep -c "value =")
    if [ $c -ne 0 ] ; then
    for port in $(odmget -q "name=$hdisk and attribute=node_name" CuPathAt | grep "value =" | cut -f2 -d\") ; do
    p=$port
    port=$(echo $port | cut -c3- | tr '[a-z]' '[A-Z]')
    for pathid in $(odmget -q "name=$hdisk and attribute=node_name and value=$p" CuPathAt | grep "path_id =" | awk '{print $NF}') ; do
    scsiid=$(odmget -q "name=$hdisk and attribute=scsi_id and path_id=$pathid" CuPathAt | grep "value =" | cut -f2 -d\" | cut -c3- | tr '[a-z]' '[A-Z]')
    parent=$(odmget -q "name=$hdisk and path_id=$pathid" CuPath | grep "parent =" | cut -f2 -d\" )
    printf "%-10s$sep%-15s" "$hdisk" "$vg"
    [ $iflag -eq 1 ] && printf "$sep%-16s" "$pvid"
    printf "$sep%-10s" "$ldev"
    [ $lflag -eq 1 ] && printf "$sep%-10s" "$size"
    printf "$sep%-20s$sep%-10s$sep%-10s$sep%-10s$sep%-20s\n" "$mtm" "$serial" "$parent" "$scsiid" "$port"
    done
    done
    else
    printf "%-10s$sep%-15s" "$hdisk" "$vg"
    [ $iflag -eq 1 ] && printf "$sep%-16s" "$pvid"
    printf "$sep%-10s" "$ldev"
    [ $lflag -eq 1 ] && printf "$sep%-10s" "$size"
    printf "$sep%-20s$sep%-10s$sep%-10s$sep%-10s$sep%-20s\n" "$mtm" "$serial" "" "" ""
    fi
    }

    set -- $(getopt "xclih" $*)
    [ $? -ne 0 ] && exit 1

    while [ "x$1" != "x--" ] ; do
    case "$1" in
    "-x")
    sep=";"
    ;;
    "-c")
    sep=":"
    ;;
    "-l")
    lflag=1
    ;;
    "-i")
    iflag=1
    ;;
    "-h")
    usage
    ;;
    *)
    break
    ;;
    esac
    shift
    done
    shift

    printf "%-10s$sep%-15s" "hdisk" "VG"
    [ $iflag -eq 1 ] && printf "$sep%-16s" "PVID"
    printf "$sep%-10s" "LDEV"
    [ $lflag -eq 1 ] && printf "$sep%-10s" "LUN Size"
    printf "$sep%-20s$sep%-10s$sep%-10s$sep%-10s$sep%-20s" "Device" "Serial" "Parent" "SCSI ID" "Port"
    echo
    if [ $cflag -ne 1 -a $xflag -ne 1 ] ; then
    printf "%-10s$sep%-15s" "==========" "==============="
    [ $iflag -eq 1 ] && printf "$sep%-16s" "================"
    printf "$sep%-10s" "=========="
    [ $lflag -eq 1 ] && printf "$sep%-10s" "=========="
    printf "$sep%-20s$sep%-10s$sep%-10s$sep%-10s$sep%-20s" "====================" "==========" "==========" "==========" "===================="
    echo
    fi

    if [ "x$1" != "x" ] ; then
    while [ "x$1" != "x" ] ; do
    t=$(lsdev -l $1 -F type)
    if [ "x$t" == "xvgtype" ] ; then
    for h in $(lsvg -p $1 | tail +3 | awk '{print $1}') ; do
    printInfo $h
    done
    else
    printInfo $1
    fi
    shift
    done
    else
    for hdisk in $(lsdev -Cc disk -F name) ; do
    printInfo $hdisk
    done
    fi

Leave a Reply

Your email address will not be published. Required fields are marked *


*