How do I work out what DASD’s my LV is using?

From a linux admin’s perspective, it is sometime difficult and time-consuming to try and work out what DASD is used for what LV in which VG. With the job of auditing such relationships in mind I write the following script to give me the information I needed.

I wanted to know what VG’s are defined, the LV’s under each VG and the linux device name, VM device name and volser for each DASD used by each LV.

progname=${0##*/}               # The name of this program
hostname=hostname             # The name of the host running the program
logdir=/mnt/nfs/scripts/logs
logfile=${logdir}/${progname%%.*}_${hostname}.log
srcdir=/mnt/nfs/scripts/etc
environment=${hostname:2:2}
servertype=${hostname:5:2}</code>
 
#exec &gt; ${logfile} 2&gt;&amp;1
 
# Define functions
 
print_msg()
{
message=$1
echo "${progname} : date : $message" | tee -a ${logfile}
}
 
get_volser()
{
local_device=lsdasd | grep "$dasd " | awk '{print $1}'
volser=${local_device##0.0.}
volser2=echo ${volser} | awk -F "(" '{print $1}'
volser3=hcp q dasd | grep -i $volser2 | awk '{print $4}'
volser4=${volser3##???}
echo "$dasd is ${volser2} : ${volser3} : 1${volser4}"
}
 
# Script starts here
print_msg "-----------------------------------------"
print_msg "Started.."
 
print_msg "LVM Audit for $hostname"
print_msg "Root disk (151)"
zvm_device=/mnt/nfs/scripts/get_volser.sh dasdb | awk '{print $7}'
guest_device=/mnt/nfs/scripts/get_volser.sh dasdb | awk '{print $3}'
print_msg "        $guest_device : dasdb1 : $zvm_device"
 
for vg in vgdisplay | grep "VG Name" | awk '{print $3}'
do
print_msg "Volume Group : $vg"
for lv in vgdisplay -v $vg 2&gt;&amp;1 | grep "LV Name" | awk '{print $3}'
do
print_msg "    Logical Volume : $lv"
print_msg "    LV Mount : grep $lv /etc/fstab | awk '{print $2}'"
for pv in lvdisplay -m $lv | grep "Physical volume" | awk '{print $3}'
do
linux_device=${pv##*/}
linux_device2=${linux_device%%1}
zvm_device=get_volser $linux_device2 | awk '{print $7}'
guest_device=get_volser $linux_device2 | awk '{print $3}'
print_msg "        $guest_device : $linux_device : $zvm_device"
done
done
done
 
#       print_msg "\tlinux device : $linux_device"
print_msg "Finished.."
exit 0

The output is something like (the names have been changed to protect the innocent) : –

audit_lvm.sh : Fri Feb  2 11:25:55 GMT 2007 : -----------------------------------------
audit_lvm.sh : Fri Feb  2 11:25:55 GMT 2007 : Started..
audit_lvm.sh : Fri Feb  2 11:25:55 GMT 2007 : LVM Audit for xxxxxx
audit_lvm.sh : Fri Feb  2 11:25:55 GMT 2007 : Root disk (151)
audit_lvm.sh : Fri Feb  2 11:25:57 GMT 2007 :         0151 : dasdb1 : 1481
audit_lvm.sh : Fri Feb  2 11:25:58 GMT 2007 : Volume Group : homevg
audit_lvm.sh : Fri Feb  2 11:25:59 GMT 2007 :     Logical Volume : /dev/homevg/homelv
audit_lvm.sh : Fri Feb  2 11:25:59 GMT 2007 :     LV Mount : /home
audit_lvm.sh : Fri Feb  2 11:26:01 GMT 2007 :         0185 : dasdbb1 : 1640
audit_lvm.sh : Fri Feb  2 11:26:01 GMT 2007 : Volume Group : datavg
audit_lvm.sh : Fri Feb  2 11:26:02 GMT 2007 :     Logical Volume : /dev/datavg/dataloadlv
audit_lvm.sh : Fri Feb  2 11:26:02 GMT 2007 :     LV Mount : /nfs/dataload
audit_lvm.sh : Fri Feb  2 11:26:04 GMT 2007 :         0160 : dasdq1 : 14E8
audit_lvm.sh : Fri Feb  2 11:26:06 GMT 2007 :         0161 : dasdr1 : 14E9
audit_lvm.sh : Fri Feb  2 11:26:08 GMT 2007 :         0162 : dasds1 : 14ED
audit_lvm.sh : Fri Feb  2 11:26:10 GMT 2007 :         0163 : dasdt1 : 14EE
audit_lvm.sh : Fri Feb  2 11:26:12 GMT 2007 :         0164 : dasdu1 : 1500
audit_lvm.sh : Fri Feb  2 11:26:14 GMT 2007 :         0165 : dasdv1 : 1501
audit_lvm.sh : Fri Feb  2 11:26:16 GMT 2007 :         0166 : dasdw1 : 1502
audit_lvm.sh : Fri Feb  2 11:26:17 GMT 2007 :         0167 : dasdx1 : 1503
audit_lvm.sh : Fri Feb  2 11:26:19 GMT 2007 :         0168 : dasdy1 : 1504
audit_lvm.sh : Fri Feb  2 11:26:21 GMT 2007 :         0169 : dasdz1 : 1505
audit_lvm.sh : Fri Feb  2 11:26:23 GMT 2007 :         0170 : dasdag1 : 1506
audit_lvm.sh : Fri Feb  2 11:26:25 GMT 2007 :         0171 : dasdah1 : 1507
audit_lvm.sh : Fri Feb  2 11:26:27 GMT 2007 :         0172 : dasdai1 : 1508
audit_lvm.sh : Fri Feb  2 11:26:29 GMT 2007 :         0173 : dasdaj1 : 1509
audit_lvm.sh : Fri Feb  2 11:26:31 GMT 2007 :         0174 : dasdak1 : 150A
audit_lvm.sh : Fri Feb  2 11:26:31 GMT 2007 : Volume Group : nfsvg
audit_lvm.sh : Fri Feb  2 11:26:32 GMT 2007 :     Logical Volume : /dev/nfsvg/nfslv
audit_lvm.sh : Fri Feb  2 11:26:32 GMT 2007 :     LV Mount : /nfs
audit_lvm.sh : Fri Feb  2 11:26:35 GMT 2007 :         0152 : dasdc1 : 1482
audit_lvm.sh : Fri Feb  2 11:26:37 GMT 2007 :         0153 : dasdd1 : 1483
audit_lvm.sh : Fri Feb  2 11:26:39 GMT 2007 :         0154 : dasde1 : 14CA
audit_lvm.sh : Fri Feb  2 11:26:41 GMT 2007 :         0155 : dasdf1 : 14CB
audit_lvm.sh : Fri Feb  2 11:26:43 GMT 2007 :         0156 : dasdg1 : 14CC
audit_lvm.sh : Fri Feb  2 11:26:45 GMT 2007 :         0157 : dasdh1 : 14CD
audit_lvm.sh : Fri Feb  2 11:26:47 GMT 2007 :         0158 : dasdi1 : 14CE
audit_lvm.sh : Fri Feb  2 11:26:49 GMT 2007 :         0159 : dasdj1 : 138E
audit_lvm.sh : Fri Feb  2 11:26:51 GMT 2007 :         0175 : dasdal1 : 14EA
audit_lvm.sh : Fri Feb  2 11:26:52 GMT 2007 :         0176 : dasdam1 : 15E5
audit_lvm.sh : Fri Feb  2 11:26:54 GMT 2007 :         0177 : dasdan1 : 15E6
audit_lvm.sh : Fri Feb  2 11:26:56 GMT 2007 :         0184 : dasdba1 : 1277
audit_lvm.sh : Fri Feb  2 11:26:56 GMT 2007 :     Logical Volume : /dev/nfsvg/nfshomelv
audit_lvm.sh : Fri Feb  2 11:26:56 GMT 2007 :     LV Mount : /ldaphome
audit_lvm.sh : Fri Feb  2 11:26:59 GMT 2007 :         0178 : dasdao1 : 15A0
audit_lvm.sh : Fri Feb  2 11:27:01 GMT 2007 :         0179 : dasdap1 : 15A3
audit_lvm.sh : Fri Feb  2 11:27:03 GMT 2007 :         0180 : dasdaw1 : 15A8
audit_lvm.sh : Fri Feb  2 11:27:05 GMT 2007 :         0181 : dasdax1 : 15BA
audit_lvm.sh : Fri Feb  2 11:27:07 GMT 2007 :         0182 : dasday1 : 15BB
audit_lvm.sh : Fri Feb  2 11:27:09 GMT 2007 :         0183 : dasdaz1 : 1268
audit_lvm.sh : Fri Feb  2 11:27:11 GMT 2007 :         0184 : dasdba1 : 1277
audit_lvm.sh : Fri Feb  2 11:27:13 GMT 2007 :         0186 : dasdbc1 : 1691
audit_lvm.sh : Fri Feb  2 11:27:15 GMT 2007 :         0187 : dasdbd1 : 168F
audit_lvm.sh : Fri Feb  2 11:27:17 GMT 2007 :         0188 : dasdbe1 : 168D
audit_lvm.sh : Fri Feb  2 11:27:18 GMT 2007 :         0189 : dasdbf1 : 168B
audit_lvm.sh : Fri Feb  2 11:27:18 GMT 2007 : Finished..

About

I'm a freelance UNIX engineer working in the UK. I'm married to Tina and between us we have six children. I'm a bit of an Apple fan boy, and all the Windows machines in the house are a thing of the past now.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: