You can now use Perl to examine and modify virtual machine disk images through libguestfs, as in this example:
#!/usr/bin/perl -w
use strict;
use Sys::Guestfs;
# Look for LVM LVs, VGs and PVs in a guest image.
die "Usage: lvs.pl guest.img\n" if @ARGV != 1 || ! -f $ARGV[0];
my $h = Sys::Guestfs->new ();
$h->add_drive ($ARGV[0]);
print "Launching, this can take a few seconds\n";
$h->launch ();
$h->wait_ready ();
print "Looking for PVs on the disk image\n";
my @pvs = $h->pvs ();
print "PVs found: (", join (", ", @pvs), ")\n";
print "Looking for VGs on the disk image\n";
my @vgs = $h->vgs ();
print "VGs found: (", join (", ", @vgs), ")\n";
print "Looking for LVs on the disk image\n";
my @lvs = $h->lvs ();
print "LVs found: (", join (", ", @lvs), ")\n";
Which produces this output:
$ ./lvs.pl RHEL52PV32.img Creating the libguestfs handle Launching, this can take a few seconds Looking for PVs on the disk image PVs found: (/dev/sda2) Looking for VGs on the disk image VGs found: (VolGroup00) Looking for LVs on the disk image LVs found: (/dev/VolGroup00/LogVol00, /dev/VolGroup00/LogVol01)

Pingback: libguestfs ocaml bindings « Richard WM Jones