Hey there,
Today's topic, and accompanying script, have to do with a more specific function already described in our series on working with AIX LVM (Actually, that link points to the last entry in the series. It's a strange thing about serialized content; the only way I can hook you up with a link that will get you links from part 4 to parts 3, 2 and 1 is to give you the last link. If only I could predetermine my following day's post URL without having to actually write the post... Actually, it probably can be done... I'll remind myself to work that into a post here soon. Hopefully I'll send myself an email to remind me before I forget ;)
This post has, loosely, to do with work. And I only mention this because I read in the online news that Google just canned some guy for writing about work in his blog! I'm not going to b.s. you and pretend like I read the entire thing, but, hopefully, he was posting company secrets. I'd hate to think what kind of an oppressive environment the corporate world would become if you could get your walking papers for ruminating over your day in an online diary. A lot of people have to work so much, they don't have much else to write about. Especially at Google. Why do you think they advertise all the games and cafeteria's and cots? Because it's a great place to work? They say; but perhaps it's because you're never ever going home again. The circle of madness has to be broken at some point ;)
In any event, working on an old AIX box, I was presented with a problem I hadn't considered for a while (on 5.x, anyway - I've been stuck in 3 and 4.x land for far too long ;) and, as I looked around for answers, I noticed that the information required to complete a pretty basic piece of work (and very useful, as well) just wasn't out there anywhere. Of course, the work involved using 2 (count 'em, 2 ;) separate commands, but... nothing. And that brings us to here.
The situation: Given a number of physical volumes, which have striped volume groups written across them, how can we figure out how much disk space (on how many different physical volumes and altogether) does that take up. I'm being intentionally vague, since the value we arrive at isn't as consequential as just being able to arrive at the value. Let's just say that we need to know because we need to replicate the disk space requirements elsewhere.
The answer: Surprisingly simple, once you get to it (although, perhaps because of my in-and-out AIX experience, confusing from time-to-time along the way). In order to extract this information, we just need to cruise through the following steps:
1. List out all available volume groups with the lsvg command:
host # lsvg
rootvg
number1vg
number2vg
...
2. Find out what physical volumes are associated with those volume groups using the same command and the "-p" switch. This time we'll need to name one of the volume groups. Steps from this point out would repeat for each individual volume group (and, later, physical volume) that comprise the logical and physical disk we're interested in (ellipses will be used to shorten lines for readability's sake):
host # lsvg -p rootvg
rootvg:
PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION
xdisk0 active ...
xdisk1 active ...
3. Then, get the number of physical partitions, and the set physical partition size for each physical volume listed out with the "lsvg -p" command above (The only two lines we really need from this output are the only two that aren't cropped with more ellipses), using the lspv command:
host # lspv xdisk0
PHYSICAL VOLUME: xdisk0...
PV IDENTIFIER: 000...
PV STATE: acti...
STALE PARTITIONS: 0 A...
PP SIZE: 64 megabyte(s) LOGICAL VOLUMES: 11
TOTAL PPs: 542 (34688 megabytes) VG DESCRIPTORS: 2
FREE PPs: 3....
USED PPs: 1....
FREE DISTRIBUTION: 1....
USED DISTRIBUTION: 0....
and we're all set :) Now, we just have a big sloppy mess of output to deal with. Lots and lots of lines of garbage, with the numbers we need sandwiched in, that we can manually add together. So, we'll move on to the natural next phase and script this out. For that volume group "rootvg" (for instance), rather than seeing all the above times 2, 3 or however much it is, this is much nicer to look at:
host # ./pvinfo.sh
Volume Group: rootvg
-----------
Physical Volume: xdisk0
Number of Physical Partitions: 542 Physical Partition Size: 64 Segment Total 34688 Mb
-----------
Physical Volume: hdisk1
Number of Physical Partitions: 542 Physical Partition Size: 64 Segment Total 34688 Mb
-----------
Physical Volume Grand Total : 69376 Mb
...
and so forth for all of our volume groups. Now we'll know how much disk space is allocated to our volume group, in total, and how much is allocated from each physical volume associated with the volume group. Feeling much better now ;)
Hope this helps you out some!
Cheers,
This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License#!/bin/sh
#
# pvinfo.sh - get your AIX physical volume totals here!
#
# 2008 - Mike Golvach - eggi@comcast.net
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#
for x in `lsvg|awk '{print $1}`
do
echo "Volume Group: $x"
echo "-----------"
lsvg -p $x|sed 1d|while read one two three
do
if [ $two == "active" ]
then
echo "Physical Volume: $one"
lspv $one|awk 'BEGIN{sum1=0;sum2=0}{ if ( $1 ~ /TOTAL/ && $2 ~ /PPs/ ){ sum1 += $3 } else if ( $1 ~ /PP/ && $2 ~ /SIZE/ ) { sum2 += $3 }}END{sum3=sum1*sum2; print "Number of Physical Partitions: " sum1 " Physical Partition Size: " sum2 " Segment Total " sum3 " Mb";print "-----------"}'
fi
done
lsvg -p $x|sed 1d|while read one two three
do
if [ $two == "active" ]
then
lspv $one|awk 'BEGIN{sum1=0;sum2=0}{ if ( $1 ~ /TOTAL/ && $2 ~ /PPs/ ){ sum1 += $3 } else if ( $1 ~ /PP/ && $2 ~ /SIZE/ ) { sum2 += $3 }}END{sum3=sum1*sum2;print sum3}'
fi
done|awk '{ sum4 += $1 }END{print "Physical Volume Grand Total : " sum4 " Mb";print "-----------"}'
done
, Mike
Chris Gibson wrote in with this helpful shortcut. He's got quite a wealth of AIX info, and we've posted additional comments from him on our LVM Series page :)
BTW, you can also do the thing same with the lsvg command:
$ lsvg rootvg | grep 'TOTAL PPs'
VG PERMISSION: read/write TOTAL PPs: 1150 (73600 megabytes)
In the example above, we have 73600Mb in rootvg.
Cheers.
Chris
Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.