Add files via upload
pvs.pl: show all PVOLs & option --active added lvs.pl: added lv extents
This commit is contained in:
parent
afecdd0ec0
commit
7a170b92c2
@ -72,8 +72,8 @@ unless ($options{'size'}) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
# print header
|
# print header
|
||||||
printf STDOUT ("\n%-30s %-12s %-17s %-7s %-17s %-7s %-8s %-8s\n",
|
printf STDOUT ("\n%-30s %-12s %-17s %-7s %-7s %-17s %-7s %-8s %-8s\n",
|
||||||
"LV", "VG", "Status", "Size", "Permissions", "Mirrors", "Stripes", "Allocation");
|
"LV", "VG", "Status", "Size", "Extents", "Permissions", "Mirrors", "Stripes", "Allocation");
|
||||||
|
|
||||||
# fetch LVOLs
|
# fetch LVOLs
|
||||||
if ($options{'vg'}) {
|
if ($options{'vg'}) {
|
||||||
@ -95,7 +95,7 @@ foreach my $lvol (@vgdisplay) {
|
|||||||
foreach my $lv_entry (@lvdisplay) {
|
foreach my $lv_entry (@lvdisplay) {
|
||||||
|
|
||||||
my ($vg_name, $lv_status, $lv_perm, $lv_alloc) = ("","","","");
|
my ($vg_name, $lv_status, $lv_perm, $lv_alloc) = ("","","","");
|
||||||
my ($lv_mirrors, $lv_stripes, $lv_size) = (0,0,0);
|
my ($lv_mirrors, $lv_stripes, $lv_size, $lv_extent) = (0,0,0,0);
|
||||||
|
|
||||||
my @lv_data = split (/:/, $lv_entry);
|
my @lv_data = split (/:/, $lv_entry);
|
||||||
|
|
||||||
@ -109,15 +109,17 @@ foreach my $lvol (@vgdisplay) {
|
|||||||
$lv_stripes = $1 if ($lv_field =~ m%^stripes=(.*)%);
|
$lv_stripes = $1 if ($lv_field =~ m%^stripes=(.*)%);
|
||||||
$lv_alloc = $1 if ($lv_field =~ m%^allocation=(.*)%);
|
$lv_alloc = $1 if ($lv_field =~ m%^allocation=(.*)%);
|
||||||
$lv_size = $1 if ($lv_field =~ m%^lv_size=(.*)%);
|
$lv_size = $1 if ($lv_field =~ m%^lv_size=(.*)%);
|
||||||
|
$lv_extent = $1 if ($lv_field =~ m%^current_le=(.*)%);
|
||||||
}
|
}
|
||||||
# convert to GB if needed
|
# convert to GB if needed
|
||||||
$lv_size /= 1024 unless ($options{'size'} =~ /MB/i);
|
$lv_size /= 1024 unless ($options{'size'} =~ /MB/i);
|
||||||
# report data
|
# report data
|
||||||
printf STDOUT ("%-30s %-12s %-17s %-7d %-17s %-7s %-8s %-8s\n",
|
printf STDOUT ("%-30s %-12s %-17s %-7d %-7d %-17s %-7s %-8s %-8s\n",
|
||||||
${lv_name},
|
${lv_name},
|
||||||
${vg_name},
|
${vg_name},
|
||||||
${lv_status},
|
${lv_status},
|
||||||
${lv_size},
|
${lv_size},
|
||||||
|
${lv_extent},
|
||||||
${lv_perm},
|
${lv_perm},
|
||||||
${lv_mirrors},
|
${lv_mirrors},
|
||||||
${lv_stripes},
|
${lv_stripes},
|
||||||
@ -178,4 +180,5 @@ S< >Show logical volume size in MB or GB (default is GB).
|
|||||||
=head1 history
|
=head1 history
|
||||||
|
|
||||||
@(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken]
|
@(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken]
|
||||||
@(#) 2016-04-27: VRF 1.0.1: small fixes [Patrick Van der Veken]
|
@(#) 2016-04-27: VRF 1.0.1: small fixes [Patrick Van der Veken]
|
||||||
|
@(#) 2016-06-27: VRF 1.0.2: added lv extents [Patrick Van der Veken]
|
150
lx-lvm/pvs.pl
150
lx-lvm/pvs.pl
@ -40,7 +40,78 @@ $|++;
|
|||||||
|
|
||||||
my ($os, $version, $footer);
|
my ($os, $version, $footer);
|
||||||
my %options;
|
my %options;
|
||||||
my (@vgdisplay, @pvdisplay);
|
my (@pvol, @vgdisplay);
|
||||||
|
|
||||||
|
|
||||||
|
#******************************************************************************
|
||||||
|
# SUBroutines
|
||||||
|
#******************************************************************************
|
||||||
|
|
||||||
|
sub parse_pvols {
|
||||||
|
|
||||||
|
my @pvol = @_;
|
||||||
|
my @pvdisplay;
|
||||||
|
|
||||||
|
unless (@pvol) {
|
||||||
|
print "-- no disks found --\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach my $pvol (@pvol) {
|
||||||
|
|
||||||
|
my $pv_lvm = 1;
|
||||||
|
|
||||||
|
chomp ($pvol);
|
||||||
|
|
||||||
|
@pvdisplay = `/usr/sbin/pvdisplay -F /dev/disk/${pvol} 2>&1`;
|
||||||
|
$pv_lvm = 0 if ($?) and (grep (/cannot display physical volume/i, @pvdisplay));
|
||||||
|
|
||||||
|
# loop over pvdisplay
|
||||||
|
if ($pv_lvm) {
|
||||||
|
|
||||||
|
foreach my $pv_entry (@pvdisplay) {
|
||||||
|
|
||||||
|
my ($vg_name, $pv_status)= ("","");
|
||||||
|
my ($pv_total_pe, $pv_size_pe, $pv_free_pe, $pv_stale_pe) = (0,0,0,0);
|
||||||
|
my ($pv_size, $pv_free) = (0,0);
|
||||||
|
|
||||||
|
my @pv_data = split (/:/, $pv_entry);
|
||||||
|
|
||||||
|
# loop over PVOL data
|
||||||
|
foreach my $pv_field (@pv_data) {
|
||||||
|
|
||||||
|
$vg_name = $1 if ($pv_field =~ m%^vg_name=/dev/(.*)%);
|
||||||
|
$pv_status = $1 if ($pv_field =~ m%^pv_status=(.*)%);
|
||||||
|
$pv_total_pe = $1 if ($pv_field =~ m%^total_pe=(.*)%);
|
||||||
|
$pv_size_pe = $1 if ($pv_field =~ m%^pe_size=(.*)%);
|
||||||
|
$pv_free_pe = $1 if ($pv_field =~ m%^free_pe=(.*)%);
|
||||||
|
$pv_stale_pe = $1 if ($pv_field =~ m%^stale_pe=(.*)%);
|
||||||
|
}
|
||||||
|
# calculate sizes
|
||||||
|
$pv_size = $pv_total_pe * $pv_size_pe;
|
||||||
|
$pv_size /= 1024 unless ($options{'size'} =~ /MB/i);
|
||||||
|
$pv_free = $pv_free_pe * $pv_size_pe;
|
||||||
|
$pv_free /= 1024 unless ($options{'size'} =~ /MB/i);
|
||||||
|
|
||||||
|
# report data
|
||||||
|
printf STDOUT ("%-20s %-12s %-15s %-7d %-8d %-8d %-8d\n",
|
||||||
|
"/dev/disk/${pvol}",
|
||||||
|
${vg_name},
|
||||||
|
${pv_status},
|
||||||
|
${pv_size_pe},
|
||||||
|
${pv_size},
|
||||||
|
${pv_free},
|
||||||
|
${pv_stale_pe})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unless ($options{'active'}) {
|
||||||
|
printf STDOUT ("%-20s %-12s %-15s\n", "/dev/disk/${pvol}",
|
||||||
|
"n/a",
|
||||||
|
"not active/not LVM");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
@ -60,6 +131,7 @@ if ( @ARGV > 0 ) {
|
|||||||
help|h|?
|
help|h|?
|
||||||
size|s=s
|
size|s=s
|
||||||
vg|g=s
|
vg|g=s
|
||||||
|
active|a
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
# check options
|
# check options
|
||||||
@ -72,66 +144,30 @@ unless ($options{'size'}) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
# print header
|
# print header
|
||||||
printf STDOUT ("\n%-20s %-10s %-15s %-7s %-8s %-8s %-8s\n",
|
printf STDOUT ("\n%-20s %-12s %-15s %-7s %-8s %-8s %-8s\n",
|
||||||
"PV", "VG", "Status", "PE Size", "PV Size", "PV Free", "Stale PE");
|
"PV", "VG", "Status", "PE Size", "PV Size", "PV Free", "Stale PE");
|
||||||
|
|
||||||
# fetch LVOLs
|
# fetch PVOLs (non-boot)
|
||||||
if ($options{'vg'}) {
|
if ($options{'vg'}) {
|
||||||
@vgdisplay = `/usr/sbin/vgdisplay -vF ${options{'vg'}} 2>/dev/null | grep "^pv_name"`;
|
@pvol = `/usr/sbin/vgdisplay -vF "/dev/${options{'vg'}}" 2>/dev/null | grep "^pv_name" | cut -f1 -d':' | cut -f2 -d'=' | cut -f4 -d '/'`;
|
||||||
|
die "failed to execute: $!" if ($?);
|
||||||
|
parse_pvols (@pvol);
|
||||||
} else {
|
} else {
|
||||||
@vgdisplay = `/usr/sbin/vgdisplay -vF 2>/dev/null | grep "^pv_name"`;
|
@pvol = `/usr/sbin/ioscan -kFN -C disk 2>/dev/null | cut -f9,13 -d':' | tr -d ':'`;
|
||||||
}
|
die "failed to execute: $!" if ($?);
|
||||||
die "failed to execute: $!" if ($?);
|
parse_pvols (@pvol);
|
||||||
|
|
||||||
# loop over PVOLs
|
# fetch PVOLs (boot)
|
||||||
foreach my $pvol (@vgdisplay) {
|
print "\n-- Boot disk(s):\n";
|
||||||
|
@pvol = `/usr/sbin/lvlnboot -v 2>/dev/null | grep 'Boot Disk' | awk '{ print \$1 }' | cut -f4 -d '/'`;
|
||||||
my $pv_name = (split (/=/, (split (/:/, $pvol))[0]))[1];
|
die "failed to execute: $!" if ($?);
|
||||||
|
parse_pvols (@pvol);
|
||||||
@pvdisplay = `/usr/sbin/pvdisplay -F ${pv_name} 2>/dev/null`;
|
|
||||||
die "failed to execute: $!" if ($?);
|
|
||||||
|
|
||||||
# loop over pvdisplay
|
|
||||||
foreach my $pv_entry (@pvdisplay) {
|
|
||||||
|
|
||||||
my ($vg_name, $pv_status)= ("","");
|
|
||||||
my ($pv_total_pe, $pv_size_pe, $pv_free_pe, $pv_stale_pe) = (0,0,0,0);
|
|
||||||
my ($pv_size, $pv_free) = (0,0);
|
|
||||||
|
|
||||||
my @pv_data = split (/:/, $pv_entry);
|
|
||||||
|
|
||||||
# loop over PVOL data
|
|
||||||
foreach my $pv_field (@pv_data) {
|
|
||||||
|
|
||||||
$vg_name = $1 if ($pv_field =~ m%^vg_name=/dev/(.*)%);
|
|
||||||
$pv_status = $1 if ($pv_field =~ m%^pv_status=(.*)%);
|
|
||||||
$pv_total_pe = $1 if ($pv_field =~ m%^total_pe=(.*)%);
|
|
||||||
$pv_size_pe = $1 if ($pv_field =~ m%^pe_size=(.*)%);
|
|
||||||
$pv_free_pe = $1 if ($pv_field =~ m%^free_pe=(.*)%);
|
|
||||||
$pv_stale_pe = $1 if ($pv_field =~ m%^stale_pe=(.*)%);
|
|
||||||
}
|
|
||||||
# calculate sizes
|
|
||||||
$pv_size = $pv_total_pe * $pv_size_pe;
|
|
||||||
$pv_size /= 1024 unless ($options{'size'} =~ /MB/i);
|
|
||||||
$pv_free = $pv_free_pe * $pv_size_pe;
|
|
||||||
$pv_free /= 1024 unless ($options{'size'} =~ /MB/i);
|
|
||||||
|
|
||||||
# report data
|
|
||||||
printf STDOUT ("%-20s %-10s %-15s %-7d %-8d %-8d %-8d\n",
|
|
||||||
${pv_name},
|
|
||||||
${vg_name},
|
|
||||||
${pv_status},
|
|
||||||
${pv_size_pe},
|
|
||||||
${pv_size},
|
|
||||||
${pv_free},
|
|
||||||
${pv_stale_pe})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# footer
|
# footer
|
||||||
$footer = qq{
|
$footer = qq{
|
||||||
Note 1: 'PE Size' values are expressed in MB
|
Note 1: 'PE Size' values are expressed in MB
|
||||||
Note 2: 'PV Size' & 'PV FRee' values are expressed in GB by default (see --help)
|
Note 2: 'PV Size' & 'PV Free' values are expressed in GB by default (see --help)
|
||||||
Note 3: more detailed information can be obtained by running the pvdisplay(1M), vgdisplay(1M), lvdisplay(1M) commands
|
Note 3: more detailed information can be obtained by running the pvdisplay(1M), vgdisplay(1M), lvdisplay(1M) commands
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -158,6 +194,7 @@ pvs.pl - Show physical volume information in a terse way (Linux style).
|
|||||||
pvs.pl [-h|--help]
|
pvs.pl [-h|--help]
|
||||||
[(-g|--vg)=<vg_name>]
|
[(-g|--vg)=<vg_name>]
|
||||||
[(-s|--size)=<MB|GB>]
|
[(-s|--size)=<MB|GB>]
|
||||||
|
[(-a|--active)]
|
||||||
|
|
||||||
=head1 OPTIONS
|
=head1 OPTIONS
|
||||||
|
|
||||||
@ -167,9 +204,13 @@ pvs.pl - Show physical volume information in a terse way (Linux style).
|
|||||||
|
|
||||||
S< >Show the help page.
|
S< >Show the help page.
|
||||||
|
|
||||||
|
=item -a | --active
|
||||||
|
|
||||||
|
S< >Hide non-active and non-LVM disks
|
||||||
|
|
||||||
=item -g | --vg
|
=item -g | --vg
|
||||||
|
|
||||||
S< >Display physical volumes for a specific volume group.
|
S< >Display physical volumes for a specific volume group. Volume group name should be specified without the "/dev/" prefix
|
||||||
|
|
||||||
=item -s | --size
|
=item -s | --size
|
||||||
|
|
||||||
@ -182,4 +223,5 @@ S< >Show physical volume size in MB or GB (default is GB).
|
|||||||
=head1 history
|
=head1 history
|
||||||
|
|
||||||
@(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken]
|
@(#) 2016-04-12: VRF 1.0.0: first version [Patrick Van der Veken]
|
||||||
@(#) 2016-04-27: VRF 1.0.1: small fixes [Patrick Van der Veken]
|
@(#) 2016-04-27: VRF 1.0.1: small fixes [Patrick Van der Veken]
|
||||||
|
@(#) 2016-04-27: VRF 1.1.0: show all PVOLs & option --active added [Patrick Van der Veken]
|
Loading…
x
Reference in New Issue
Block a user