Está en la página 1de 6

Using AIX Scalable volume groups due to the fact that they are easy to use and have

very few
limitations. In my opinion, every volume group you create should be Scalable unless you have
some kind of requirement to import the volume group in to a super old version of AIX.

Unfortunately there are a lot of "Original" and "Big" volume groups out there. For more inform
ation about limitations of Original and Big volume groups, and a script to show you a report on
your systems volume group status's, check out an earlier post I did: Deciphering AIX Volu
me Group limitations and types

If you have Original and Big volume groups its only a matter of time until you start running in to
their limitations. At that point you are going to probably want to convert your Original to a Big
volume group, or convert your Big volume group to a Scalable volume group. Unfortunately, in
order to convert a volume group you must have some free physical partitions (aka "PP's") on
EVERY hdisk in the volume group. This is usually a problem because you are probably looking
to convert the volume group due to running out of space, so you probably have several hdisks that
are completely full.

In order to free up PP's on every disk you have a couple of options. You can either shrink
filesystems (which may or may not be possible depending on how full they are), or use
"migratelp" or "migratepv" to move things around to free up some space on the volume group.
The migratelp/migratepv is a good option if several of your hdisk's are full in the volume group,
but you still have some hdisk's with free space that things could be shuffled to.

I've written a script that will "migratelp" things around in order to free up a specified amount of
PP's on each disk.
To run the script, you specify the volume group name, and the number of PP's you want free on
every hdisk:
For example: ./vgbalance,pl testvg 3 (This will attempt to free up 3 PP's on every hdisk in
testvg)

Let's suppose we have a server that has "testvg" with the following hdisks that have the specified
amount of free PP's:
# for disk in `lspv | grep testvg | awk '{print $1}'`; do printf "$disk "; lspv $disk | grep "FREE PP";
done
hdisk4 FREE PPs: 0 (0 megabytes) HOT SPARE: no
hdisk5 FREE PPs: 0 (0 megabytes) HOT SPARE: no
hdisk10 FREE PPs: 0 (0 megabytes) HOT SPARE: no
hdisk11 FREE PPs: 0 (0 megabytes) HOT SPARE: no
hdisk12 FREE PPs: 0 (0 megabytes) HOT SPARE: no
hdisk13 FREE PPs: 1 (4 megabytes) HOT SPARE: no
hdisk14 FREE PPs: 2 (8 megabytes) HOT SPARE: no
hdisk15 FREE PPs: 6 (24 megabytes) HOT SPARE: no
hdisk16 FREE PPs: 5 (20 megabytes) HOT SPARE: no
hdisk17 FREE PPs: 13 (52 megabytes) HOT SPARE: no
hdisk18 FREE PPs: 12 (48 megabytes) HOT SPARE: no
hdisk19 FREE PPs: 11 (44 megabytes) HOT SPARE: no
hdisk20 FREE PPs: 14 (56 megabytes) HOT SPARE: no

As you can see several of the hdisks in the testvg volume group have zero free PP's.
If we wanted to free up 3 PP's per hdisk in the testvg volume group we would run the script like
this:
# ./vgbalance.pl testvg 3
migratelp fslv03/6 hdisk15; sleep 1; ###To free up PP's on hdisk4
migratelp fslv03/7 hdisk15; sleep 1; ###To free up PP's on hdisk4
migratelp fslv03/8 hdisk15; sleep 1; ###To free up PP's on hdisk4
migratelp fslv02/4 hdisk17; sleep 1; ###To free up PP's on hdisk5
migratelp fslv02/5 hdisk17; sleep 1; ###To free up PP's on hdisk5
migratelp fslv02/6 hdisk17; sleep 1; ###To free up PP's on hdisk5
migratelp fslv02/68 hdisk17; sleep 1; ###To free up PP's on hdisk10
migratelp fslv02/69 hdisk17; sleep 1; ###To free up PP's on hdisk10
migratelp fslv02/70 hdisk17; sleep 1; ###To free up PP's on hdisk10
migratelp fslv02/116 hdisk17; sleep 1; ###To free up PP's on hdisk11
migratelp fslv02/117 hdisk17; sleep 1; ###To free up PP's on hdisk11
migratelp fslv02/118 hdisk17; sleep 1; ###To free up PP's on hdisk11
migratelp fslv02/130 hdisk18; sleep 1; ###To free up PP's on hdisk12
migratelp fslv02/131 hdisk18; sleep 1; ###To free up PP's on hdisk12
migratelp fslv02/132 hdisk18; sleep 1; ###To free up PP's on hdisk12
migratelp fslv02/144 hdisk16; sleep 1; ###To free up PP's on hdisk13
migratelp fslv02/145 hdisk16; sleep 1; ###To free up PP's on hdisk13
migratelp fslv02/158 hdisk17; sleep 1; ###To free up PP's on hdisk14

The script doesn't make any changes - it just generates the migratelp command lines. Once we
have verified that the command lines look good and are correct, we can actually have the
command lines be run by piping the script to "ksh", for example: ./vgbalance.pl testvg 3 | ksh
# ./vgbalance.pl testvg 3 | ksh
migratelp: Mirror copy 1 of logical partition 6 of logical volume
fslv03 migrated to physical partition 4 of hdisk15.
migratelp: Mirror copy 1 of logical partition 7 of logical volume
fslv03 migrated to physical partition 5 of hdisk15.
0516-1201 lspv: Warning: Volume group testvg is locked. This command
will continue retries until lock is free. If lock is inadvertent
and needs to be removed, execute 'chvg -u testvg'.
migratelp: Mirror copy 1 of logical partition 8 of logical volume
fslv03 migrated to physical partition 6 of hdisk15.
migratelp: Mirror copy 1 of logical partition 4 of logical volume
fslv02 migrated to physical partition 4 of hdisk17.
migratelp: Mirror copy 1 of logical partition 5 of logical volume
fslv02 migrated to physical partition 5 of hdisk17.
migratelp: Mirror copy 1 of logical partition 6 of logical volume
fslv02 migrated to physical partition 6 of hdisk17.
migratelp: Mirror copy 1 of logical partition 68 of logical volume
fslv02 migrated to physical partition 3 of hdisk17.
0516-1201 lspv: Warning: Volume group testvg is locked. This command
will continue retries until lock is free. If lock is inadvertent
and needs to be removed, execute 'chvg -u testvg'.
migratelp: Mirror copy 1 of logical partition 69 of logical volume
fslv02 migrated to physical partition 2 of hdisk17.
migratelp: Mirror copy 1 of logical partition 70 of logical volume
fslv02 migrated to physical partition 7 of hdisk17.
migratelp: Mirror copy 1 of logical partition 116 of logical volume
fslv02 migrated to physical partition 8 of hdisk17.
migratelp: Mirror copy 1 of logical partition 117 of logical volume
fslv02 migrated to physical partition 9 of hdisk17.
migratelp: Mirror copy 1 of logical partition 118 of logical volume
fslv02 migrated to physical partition 10 of hdisk17.
0516-1201 lspv: Warning: Volume group testvg is locked. This command
will continue retries until lock is free. If lock is inadvertent
and needs to be removed, execute 'chvg -u testvg'.
migratelp: Mirror copy 1 of logical partition 130 of logical volume
fslv02 migrated to physical partition 4 of hdisk18.
migratelp: Mirror copy 1 of logical partition 131 of logical volume
fslv02 migrated to physical partition 5 of hdisk18.
migratelp: Mirror copy 1 of logical partition 132 of logical volume
fslv02 migrated to physical partition 6 of hdisk18.
migratelp: Mirror copy 1 of logical partition 144 of logical volume
fslv02 migrated to physical partition 10 of hdisk16.
migratelp: Mirror copy 1 of logical partition 145 of logical volume
fslv02 migrated to physical partition 11 of hdisk16.
migratelp: Mirror copy 1 of logical partition 158 of logical volume
fslv02 migrated to physical partition 11 of hdisk17.

That time, the script actually made the changes and migrates the LP's. If we check to see how man
y free PP's there are on each disk, you can now see that they all have at least 3 free PP's as we had
wanted:
# for disk in `lspv | grep testvg | awk '{print $1}'`; do printf "$disk "; lspv $disk | grep "FREE PP";
done
hdisk4 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk5 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk10 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk11 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk12 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk13 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk14 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk15 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk16 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk17 FREE PPs: 3 (12 megabytes) HOT SPARE: no
hdisk18 FREE PPs: 9 (36 megabytes) HOT SPARE: no
hdisk19 FREE PPs: 11 (44 megabytes) HOT SPARE: no
hdisk20 FREE PPs: 14 (56 megabytes) HOT SPARE: no

Below is the script. Note that this is ALPHA and has only been tested in my limited home environ
ment. Use the script at your own risk. Note that this script was written to work on unmirrored
LV's, and unstripped LV's - I haven't done any testing on mirrored LV's and the script would
probably need modification to work with them. If you find any issues please let me know so that I
can improve the script.
#!/usr/bin/perl
use strict;
use warnings;

my ($vg,$pps,%hdisk,$disk,$disk2,@output,$freepp,$match);
my (@output2,$lv,$line,$lvsize,$match2,$count,@output3,$lp);

if ($#ARGV == 1){
$vg = $ARGV[0];
$pps = $ARGV[1];
}else{
printf "Specify volume group name and number of desired free PP's\n";
exit 1;
}

@output = `lsvg -p $vg | grep active | awk '{print \$1}'`;

for $disk (@output){


chomp($disk);
$freepp = `lspv $disk | grep "FREE PPs:" | awk '{print \$3}'`;
chomp($freepp);
$hdisk{$disk} = $freepp;
}

for $disk (@output){


if ($hdisk{$disk} >= $pps) { next; }
$match = "false";
for $disk2 (@output){
if ($hdisk{$disk2} - ($pps - $hdisk{$disk}) - $pps >= 0){
@output2 = `lspv -l $disk`;
$match2 = "false";
for $line (@output2){
if ($line =~ /(\S+)\s+(\d+)\s+.*/){
$lv = $1;
$lvsize = $2;
if ($lvsize >= ($pps - $hdisk{$disk})){
$match2 = "true";
$count = 0;
@output3 = `lslv -m $lv | grep " $disk " | awk '{print \$1}'`;
for $lp (@output3){
chomp($lp);
$lp += 0; #This removes leading zeros
if ($count < ($pps - $hdisk{$disk})){
printf "migratelp ${lv}/${lp} $disk2; sleep 1; ###To free up PP's on $disk\n";
}
$count++;
}
last;
}
}
}
if ($match2 eq "false") {
print "**ERROR** - Couldn't find any LV's on $disk that are $pps PP's\n";
exit 2;
}
$hdisk{$disk2} = $hdisk{$disk2} - ($pps - $hdisk{$disk});
$match = "true";
last;
}
}
if ($match eq "false") {
print "**ERROR** - Couldn't find $pps free PP's on any remaining disks \n";
exit 2;
}
}

$ cat migratelp.sh
VGNAME=testvg ## Set your VG name here
DEST=hdiskpower100 ## Set destination PV for the migrated LP's
PPt=2 ## Set Total number of free PP's needed.
#
for i in $(lsvg -p $VGNAME|egrep -v ":|PV_NAME"| \
awk -v P=$PPt '($4 < P) {print $1}')
do
PPf=$(lsvg -p $VGNAME|grep "$i "|awk '{print $4}')
let PPn="PPt - $PPf"
echo "print migrate $i $PPn New PPs needed for total of $PPt"
lspv -M $i |awk '($2 != "") {print $0}'| head -$PPn |sed "s/:/ /g"| \
awk -v L=$DEST '{print "migratelp "$3"/"$4, L }'
done

También podría gustarte