LVM helper


 
Thread Tools Search this Thread
Operating Systems HP-UX LVM helper
# 1  
Old 05-30-2012
LVM helper

Have you ever had a need to know which lvols were on which disks? Maybe you needed to expand an index filesystem and wanted to make sure you did not expand onto a disk with a data filesystem. Here is a script to see how each lvol is laid out on each disk. (For VGs with many PVs it may be easier to output to a file and then open in a spreadsheet). It works with both Agile and legacy DSFs.

Enjoy! Let me know what you think. (I really think LVM should include something like this already).



Code:
#!/usr/bin/sh

VG=$1

if [[ -z $VG ]]
then
  echo "Usage: show_vg_layout <vgname>"
  exit
fi

vgdisplay $VG > /dev/null 2>&1

if [[ $? != 0 ]]
then
  echo "****** Error ******"
  echo "${VG} is not active or does not exist on this server\n"
  exit
fi

DSK=`vgdisplay -v $VG | grep "PV Name" | tail -n 1 | awk -F/ '{print $3}'`

PE_SIZE=`vgdisplay $VG | grep "PE Size" | awk '{print $NF}'`
echo "\n PE Size (Mbytes) = ${PE_SIZE}"


set -A DISKS `vgdisplay -v $VG | grep "PV Name" | awk -F/ '{print $NF}' | sort -n`
NUM_DISKS=`vgdisplay $VG | grep "Cur PV" | awk '{print $NF}'`

echo " PE/disk => \c"
let x=0
while (( x < $NUM_DISKS ))
do
  typeset -R8 DISK_SIZE=`pvdisplay /dev/$DSK/${DISKS[$x]} | grep "Total PE" | awk '{print $NF}'`
  echo "${DISK_SIZE}\c"
  let x=x+1
done
echo

echo "LV_Name     \c"
let x=0
while (( x < $NUM_DISKS ))
do
  typeset -R8 DEV=${DISKS[$x]}
  echo "${DEV}\c"
  let x=x+1
done
echo

for LV in `vgdisplay -v $VG | grep "LV Name" | awk -F/ '{print $NF}' | sort `
do

  typeset -L12 LV_NAME=$LV
  echo "${LV_NAME}\c"
  set -A LV_DISKS `lvdisplay -v /dev/$VG/$LV | grep $DSK | grep -v current | awk '{split($1,a,"/"); print a[4]}' | sort -n`
  set -A PE_ON_DISK `lvdisplay -v /dev/$VG/$LV | grep $DSK | grep -v current | awk '{print $2}'`
  let x=0
  while (( x < $NUM_DISKS ))
  do
    let y=0
    NUM=${#LV_DISKS[*]}
    while (( y < $NUM ))
    do
      if [[ ${DISKS[$x]} = ${LV_DISKS[$y]} ]]
      then
        typeset -R8 SIZE=${PE_ON_DISK[$y]}
        let y=$NUM
      else
        typeset -R8 SIZE="-"
      fi
      let y=y+1
    done
    echo "${SIZE}\c"
    let x=x+1
  done
  echo
done

for p in Total Free
do
  typeset -R12 LABEL="${p} PE"
  echo "${LABEL}\c"
  let x=0
  while (( x < $NUM_DISKS ))
    do
      SIZE=`pvdisplay /dev/$DSK/${DISKS[$x]} | grep "${p} PE" | awk '{print $NF}'`
      typeset -R8 TOT=$SIZE
      echo "${TOT}\c"
      let x=x+1
    done
    echo
done


Last edited by vbe; 05-31-2012 at 08:47 AM.. Reason: code tags..
These 2 Users Gave Thanks to keelba For This Post:
# 2  
Old 05-30-2012
Awesome! Thank you very much for the script. I came across this situation couple of times for Linux and HP-UX. I scratched my head, tried to guesstimate, and gave up at last.

Just to let you know, although I can make up what the script is actually doing, it would be very helpful, if you comment it properly so that others can understand and use the similar idea in different platforms. Smilie
# 3  
Old 05-31-2012
Did you test with alternate pathing?

(OK, I do strange configs when I want to optimize throughput... here you have LUNS that are RAID5 luns, I use in PVG and stripe... using 2 HBAs so you see them thruogh the 2 paths (alternate links...))
Code:
ran:/sm/bin $ vgdisplay -v esvg01|more
--- Volume groups ---
VG Name                     /dev/esvg01
VG Write Access             read/write     
VG Status                   available                 
Max LV                      255    
Cur LV                      10     
Open LV                     10     
Max PV                      32     
Cur PV                      6      
Act PV                      6      
Max PE per PV               9500         
VGDA                        12  
PE Size (Mbytes)            4               
Total PE                    22680   
Alloc PE                    20231   
Free PE                     2449    
Total PVG                   1        
Total Spare PVs             0              
Total Spare PVs in use      0                     

   --- Logical volumes ---
   LV Name                     /dev/esvg01/lvol1
   LV Status                   available/syncd           
   LV Size (Mbytes)            34000           
   Current LE                  8500      
   Allocated PE                8500        
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol2
   LV Status                   available/syncd           
   LV Size (Mbytes)            2060            
   Current LE                  515       
   Allocated PE                515         
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol3
   LV Status                   available/syncd           
   LV Size (Mbytes)            30000           
   Current LE                  7500      
   Allocated PE                7500        
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol4
   LV Status                   available/syncd           
   LV Size (Mbytes)            12000           
   Current LE                  3000      
   Allocated PE                3000        
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol5
   LV Status                   available/syncd           
   LV Size (Mbytes)            864             
   Current LE                  216       
   Allocated PE                216         
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol6
   LV Status                   available/syncd           
   LV Size (Mbytes)            948             
   Current LE                  237       
   Allocated PE                237         
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol7
   LV Status                   available/syncd           
   LV Size (Mbytes)            260             
   Current LE                  65        
   Allocated PE                65          
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol8
   LV Status                   available/syncd           
   LV Size (Mbytes)            168             
   Current LE                  42        
   Allocated PE                42          
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol9
   LV Status                   available/syncd           
   LV Size (Mbytes)            96              
   Current LE                  24        
   Allocated PE                24          
   Used PV                     6       

   LV Name                     /dev/esvg01/lvol10
   LV Status                   available/syncd           
   LV Size (Mbytes)            528             
   Current LE                  132       
   Allocated PE                132         
   Used PV                     6       


   --- Physical volumes ---
   PV Name                     /dev/dsk/c19t0d0
   PV Name                     /dev/dsk/c21t0d0 Alternate Link
   PV Status                   available                
   Total PE                    3780    
   Free PE                     404     
   Autoswitch                  On        

   PV Name                     /dev/dsk/c19t0d2
   PV Name                     /dev/dsk/c21t0d2 Alternate Link
   PV Status                   available                
   Total PE                    3780    
   Free PE                     408     
   Autoswitch                  On        

   PV Name                     /dev/dsk/c19t0d4
   PV Name                     /dev/dsk/c21t0d4 Alternate Link
   PV Status                   available                
   Total PE                    3780    
   Free PE                     411     
   Autoswitch                  On        

   PV Name                     /dev/dsk/c21t0d1
   PV Name                     /dev/dsk/c19t0d1 Alternate Link
   PV Status                   available                
   Total PE                    3780    
   Free PE                     404     
   Autoswitch                  Off       

   PV Name                     /dev/dsk/c21t0d3
   PV Name                     /dev/dsk/c19t0d3 Alternate Link
   PV Status                   available                
   Total PE                    3780    
   Free PE                     410     
   Autoswitch                  Off       

   PV Name                     /dev/dsk/c21t0d5
   PV Name                     /dev/dsk/c19t0d5 Alternate Link
   PV Status                   available                
   Total PE                    3780    
   Free PE                     412     
   Autoswitch                  Off       


   --- Physical volume groups ---
   PVG Name                    pvg_es01                   
   PV Name                     /dev/dsk/c19t0d0           
   PV Name                     /dev/dsk/c21t0d1           
   PV Name                     /dev/dsk/c19t0d2           
   PV Name                     /dev/dsk/c21t0d3           
   PV Name                     /dev/dsk/c19t0d4           
   PV Name                     /dev/dsk/c21t0d5           


#---------------------------- lvm_info is the name I gave to your script -----------------------#
ran:/sm/bin $ lvm_info esvg01

 PE Size (Mbytes) = 4
 PE/disk =>     3780    3780    3780pvdisplay: "/dev/dsk/Alternate": No such file or directory
Usage: pvdisplay  
        [-v] 
        [-b BlockList] 
        PhysicalVolumePath... 

        pvdisplay: "/dev/dsk/Link": No such file or directory
Usage: pvdisplay  
        [-v] 
        [-b BlockList] 
        PhysicalVolumePath... 

            3780
LV_Name      c19t0d0 c19t0d0 c19t0d1lternate    Link c19t0d2
lvol1           1418    1418       -       -       -    1416
lvol10            22      22       -       -       -      22
lvol2             87      87       -       -       -      86
lvol3           1250    1250       -       -       -    1250
lvol4            500     500       -       -       -     500
lvol5             36      36       -       -       -      36
lvol6             41      41       -       -       -      40
lvol7             11      11       -       -       -      11
lvol8              7       7       -       -       -       7
lvol9              4       4       -       -       -       4
    Total PE    3780    3780    3780pvdisplay: "/dev/dsk/Alternate": No such file or directory
Usage: pvdisplay  
        [-v] 
        [-b BlockList] 
        PhysicalVolumePath... 

        pvdisplay: "/dev/dsk/Link": No such file or directory
Usage: pvdisplay  
        [-v] 
        [-b BlockList] 
        PhysicalVolumePath... 

            3780
     Free PE     404     404     404pvdisplay: "/dev/dsk/Alternate": No such file or directory
Usage: pvdisplay  
        [-v] 
        [-b BlockList] 
        PhysicalVolumePath... 

        pvdisplay: "/dev/dsk/Link": No such file or directory
Usage: pvdisplay  
        [-v] 
        [-b BlockList] 
        PhysicalVolumePath... 

             408

(HP-UX 11.11 PA-RISC...)
This is not the worst I did... I have a volume group with 3 PVG where I made 3 set of stripes: 2 set of lvols striped over 4 luns and 1 set using 8... Now I sweat when it comes to add extents...
# 4  
Old 06-01-2012
I hope I have not discouraged you with my post...

Good luck!
And yes if the script were correctly documented, I could have looked a bit but now Im stressed by stranges issues and urgent jobs to do and check before monday...
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to convert non LVM root partition to LVM?

Hi Guys, I m using redhat 6, I have installed root partition as non-LVM . Is there any way i can convert it to LVM? (1 Reply)
Discussion started by: pinga123
1 Replies

2. HP-UX

How to reduce LVM to create another LVM

Hi, I'm new to HP-UX. I have LVM on /var with 92Gig. I would like to reduce it to create another LVM for Oracle client with 800 meg or so. How to do it. I'm running 11.iv3 Thanks (4 Replies)
Discussion started by: lamoul
4 Replies

3. AIX

lvm

Hi. can anyone define about VGDA,VGSA,and quorum in aix.. (1 Reply)
Discussion started by: sumathi.k
1 Replies

4. Red Hat

Lvm

Hi, can we create logical volume from 2 different volume groups. (1 Reply)
Discussion started by: gopalredhat
1 Replies
Login or Register to Ask a Question