# LVM helper

**URL:** <https://community.unix.com/t/lvm-helper/311073>\
**Category:** HP-UX\
**Created:** [May 30, 2012, 3:27pm UTC](https://community.unix.com/t/lvm-helper/311073 "2012-05-30T15:27:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![keelba](https://community.unix.com/letter_avatar/keelba/32/6_22734026db12803ebb3e059622ac3534.png) [@keelba](https://community.unix.com/u/keelba)\
**Post date:** [May 30, 2012, 3:27pm UTC](https://community.unix.com/t/lvm-helper/311073/1 "2012-05-30T15:27:39Z")

</div>

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).

```nohighlight
#!/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

```

---

<div class="post-metadata">

**Author:** ![admin\_xor](https://community.unix.com/user_avatar/community.unix.com/admin_xor/32/2337_2.png) [@admin\_xor](https://community.unix.com/u/admin_xor)\
**Post date:** [May 30, 2012, 3:46pm UTC](https://community.unix.com/t/lvm-helper/311073/2 "2012-05-30T15:46:18Z")

</div>

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. 😃

---

<div class="post-metadata">

**Author:** ![vbe](https://community.unix.com/user_avatar/community.unix.com/vbe/32/266_2.png) [@vbe](https://community.unix.com/u/vbe)\
**Post date:** [May 31, 2012, 8:23am UTC](https://community.unix.com/t/lvm-helper/311073/3 "2012-05-31T08:23:04Z")

</div>

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...))

```nohighlight
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...

---

<div class="post-metadata">

**Author:** ![vbe](https://community.unix.com/user_avatar/community.unix.com/vbe/32/266_2.png) [@vbe](https://community.unix.com/u/vbe)\
**Post date:** [June 1, 2012, 3:18pm UTC](https://community.unix.com/t/lvm-helper/311073/4 "2012-06-01T15:18:22Z")

</div>

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...
