Sponsored Content
Full Discussion: LVM helper
Operating Systems HP-UX LVM helper Post 302648977 by keelba on Wednesday 30th of May 2012 03:27:39 PM
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:
 

4 More Discussions You Might Find Interesting

1. Red Hat

Lvm

Hi, can we create logical volume from 2 different volume groups. (1 Reply)
Discussion started by: gopalredhat
1 Replies

2. AIX

lvm

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

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

4. 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
All times are GMT -4. The time now is 12:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy