Unix/Linux Go Back    


HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

LVM helper

HP-UX


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-30-2012
keelba keelba is offline
Registered User
 
Join Date: Apr 2002
Last Activity: 1 March 2017, 8:23 PM EST
Location: Dallas, TX
Posts: 76
Thanks: 0
Thanked 2 Times in 1 Post
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 07:47 AM.. Reason: code tags..
The Following 2 Users Say Thank You to keelba For This Useful Post:
admin_xor (05-30-2012), vbe (06-01-2012)
Sponsored Links
    #2  
Old Unix and Linux 05-30-2012
admin_xor's Unix or Linux Image
admin_xor admin_xor is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 3 May 2015, 12:12 PM EDT
Posts: 452
Thanks: 13
Thanked 80 Times in 76 Posts
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. Linux
Sponsored Links
    #3  
Old Unix and Linux 05-31-2012
vbe's Unix or Linux Image
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 24 September 2017, 6:32 AM EDT
Location: Switzerland - GE
Posts: 6,455
Thanks: 283
Thanked 549 Times in 511 Posts
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 Unix and Linux 06-01-2012
vbe's Unix or Linux Image
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 24 September 2017, 6:32 AM EDT
Location: Switzerland - GE
Posts: 6,455
Thanks: 283
Thanked 549 Times in 511 Posts
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...
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -4. The time now is 03:24 PM.