use warnings;
use Sys::Guestfs;
+use File::Temp qw/tempdir/;
# Optional:
eval "use Sys::Virt;";
sub open_guest
{
+ local $_;
my $first = shift;
my %params = @_;
my $p = XML::XPath->new (xml => $xml);
my @disks = $p->findnodes ('//devices/disk/source/@dev');
+ push (@disks, $p->findnodes ('//devices/disk/source/@file'));
+
+ die "$images[0] seems to have no disk devices\n" unless @disks;
+
@images = map { $_->getData } @disks;
}
my @partitions = $g->list_partitions ();
my @pvs = $g->pvs ();
- @partitions = grep { ! is_pv ($_, @pvs) } @partitions;
+ @partitions = grep { ! _is_pv ($_, @pvs) } @partitions;
my @lvs = $g->lvs ();
return sort (@lvs, @partitions);
}
-sub is_pv {
+sub _is_pv {
local $_;
my $t = shift;
if ($g->is_file ("/grub/menu.lst") ||
$g->is_file ("/grub/grub.conf")) {
$r{content} = "linux-grub";
- check_grub ($g, \%r);
+ _check_grub ($g, \%r);
goto OUT;
}
$g->is_file ("/etc/fstab")) {
$r{content} = "linux-root";
$r{is_root} = 1;
- check_linux_root ($g, \%r);
+ _check_linux_root ($g, \%r);
goto OUT;
}
$r{fsos} = "windows";
$r{content} = "windows-root";
$r{is_root} = 1;
- check_windows_root ($g, \%r, $use_windows_registry);
+ _check_windows_root ($g, \%r, $use_windows_registry);
goto OUT;
}
}
return \%r;
}
-sub check_linux_root
+sub _check_linux_root
{
local $_;
my $g = shift;
# XXX We could parse this better. This won't work if /boot.ini is on
# a different drive from the %systemroot%, and in other unusual cases.
-sub check_windows_root
+sub _check_windows_root
{
local $_;
my $g = shift;
if (defined $systemroot) {
$r->{systemroot} = resolve_windows_path ($g, "/$systemroot");
if (defined $r->{systemroot} && $use_windows_registry) {
- check_windows_registry ($g, $r, $r->{systemroot});
+ _check_windows_registry ($g, $r, $r->{systemroot});
}
}
}
}
-sub check_windows_registry
+sub _check_windows_registry
{
local $_;
my $g = shift;
if (defined $configdir) {
my $softwaredir = resolve_windows_path ($g, "$configdir/software");
if (defined $softwaredir) {
- load_windows_registry ($g, $r, $softwaredir,
- "HKEY_LOCAL_MACHINE\\SOFTWARE");
+ _load_windows_registry ($g, $r, $softwaredir,
+ "HKEY_LOCAL_MACHINE\\SOFTWARE");
}
my $systemdir = resolve_windows_path ($g, "$configdir/system");
if (defined $systemdir) {
- load_windows_registry ($g, $r, $systemdir,
- "HKEY_LOCAL_MACHINE\\System");
+ _load_windows_registry ($g, $r, $systemdir,
+ "HKEY_LOCAL_MACHINE\\System");
}
}
}
-sub load_windows_registry
+sub _load_windows_registry
{
local $_;
my $g = shift;
$r->{registry} = \@registry;
}
-sub check_grub
+sub _check_grub
{
local $_;
my $g = shift;
root => $fses->{$_},
root_device => $_
);
- get_os_version ($g, \%r);
- assign_mount_points ($g, $fses, \%r);
+ _get_os_version ($g, \%r);
+ _assign_mount_points ($g, $fses, \%r);
$oses{$_} = \%r;
}
}
return \%oses;
}
-sub get_os_version
+sub _get_os_version
{
local $_;
my $g = shift;
$r->{version} = $r->{root}->{osversion} if exists $r->{root}->{osversion};
}
-sub assign_mount_points
+sub _assign_mount_points
{
local $_;
my $g = shift;
foreach (@fstab) {
my ($spec, $file) = @$_;
- my ($dev, $fs) = find_filesystem ($g, $fses, $spec);
+ my ($dev, $fs) = _find_filesystem ($g, $fses, $spec);
if ($dev) {
$r->{mounts}->{$file} = $dev;
$r->{filesystems}->{$dev} = $fs;
}
# Find filesystem by device name, LABEL=.. or UUID=..
-sub find_filesystem
+sub _find_filesystem
{
my $g = shift;
my $fses = shift;
my $g = shift;
my $os = shift;
- check_for_applications ($g, $os);
- check_for_kernels ($g, $os);
+ _check_for_applications ($g, $os);
+ _check_for_kernels ($g, $os);
if ($os->{os} eq "linux") {
- check_for_modprobe_aliases ($g, $os);
- check_for_initrd ($g, $os);
+ _check_for_modprobe_aliases ($g, $os);
+ _check_for_initrd ($g, $os);
}
}
-sub check_for_applications
+sub _check_for_applications
{
local $_;
my $g = shift;
$os->{apps} = \@apps;
}
-sub check_for_kernels
+sub _check_for_kernels
{
local $_;
my $g = shift;
#
# XXX This doesn't look beyond /etc/modprobe.conf, eg. in /etc/modprobe.d/
-sub check_for_modprobe_aliases
+sub _check_for_modprobe_aliases
{
local $_;
my $g = shift;
# Get a listing of device drivers in any initrd corresponding to a
# kernel. This is an indication of what can possibly be booted.
-sub check_for_initrd
+sub _check_for_initrd
{
local $_;
my $g = shift;
my $version = $1;
my @modules;
- eval {
- @modules = $g->initrd_list ("/boot/$initrd");
- };
- unless ($@) {
- @modules = grep { m,([^/]+)\.ko$, || m,([^/]+)\.o$, } @modules;
- $initrd_modules{$version} = \@modules
- } else {
- warn "/boot/$initrd: could not read initrd format"
+ # Disregard old-style compressed ext2 files, since cpio
+ # takes ages to (fail to) process these.
+ if ($g->file ("/boot/$initrd") !~ /gzip compressed/ ||
+ $g->zfile ("gzip", "/boot/$initrd") !~ /ext2 filesystem/) {
+ eval {
+ @modules = $g->initrd_list ("/boot/$initrd");
+ };
+ unless ($@) {
+ @modules = grep { m,([^/]+)\.ko$, || m,([^/]+)\.o$, }
+ @modules;
+ $initrd_modules{$version} = \@modules
+ } else {
+ warn "/boot/$initrd: could not read initrd format";
+ }
}
}
}