Allow swap space from the guest to be used. Is it a good idea?
-Query guest architecture
-------------------------
-
-Need a way to query a binary or library file for its architecture.
-Using objdump or readelf?
-What about non-ELF files (eg. Windows, BSD).
-
-To do this properly requires some serious logic, eg. to cover Linux
-and Windows we'd need objdump and i686-pc-mingw32-objdump, and more to
-cover a.out, COFF and 64 bit Windows. Therefore this cannot be done
-inside the daemon, and should be done by a separate, external program
-similar to virt-inspector.
-
-Probably we should go all the way and have virt-inspector able to
-determine kernel and userspace architectures of guests.
-
Other initrd-* commands
-----------------------
print $os->{os}, " " if exists $os->{os};
print $os->{distro}, " " if exists $os->{distro};
+ print $os->{arch}, " " if exists $os->{arch};
print $os->{major_version} if exists $os->{major_version};
print ".", $os->{minor_version} if exists $os->{minor_version};
print " ";
print __" Kernels:\n";
my @kernels = @{$os->{kernels}};
foreach (@kernels) {
- print " $_->{version}\n";
+ print " $_->{version} ($_->{arch})\n";
my @modules = @{$_->{modules}};
foreach (@modules) {
print " $_\n";
foreach ( [ "name" => "os" ],
[ "distro" => "distro" ],
+ [ "arch" => "arch" ],
[ "major_version" => "major_version" ],
[ "minor_version" => "minor_version" ],
[ "package_format" => "package_format" ],
$xml->startTag("kernels");
my @kernels = @{$os->{kernels}};
foreach (@kernels) {
- $xml->startTag("kernel", "version" => $_->{version});
+ $xml->startTag("kernel",
+ "version" => $_->{version},
+ "arch" => $_->{arch});
$xml->startTag("modules");
my @modules = @{$_->{modules}};
foreach (@modules) {
output_query_xen_domU_kernel ();
output_query_xen_pv_drivers ();
output_query_virtio_drivers ();
+ output_query_kernel_arch ();
+ output_query_userspace_arch ();
}
=item windows=(yes|no)
print "virtio_drivers=no\n";
}
+=item userspace_arch=(x86_64|...)
+
+Print the architecture of userspace.
+
+NB. For multi-boot VMs this can print several lines.
+
+=cut
+
+sub output_query_userspace_arch
+{
+ my %arches;
+
+ foreach my $os (keys %$oses) {
+ $arches{$oses->{$os}->{arch}} = 1 if exists $oses->{$os}->{arch};
+ }
+
+ foreach (sort keys %arches) {
+ print "userspace_arch=$_\n";
+ }
+}
+
+=item kernel_arch=(x86_64|...)
+
+Print the architecture of the kernel.
+
+NB. For multi-boot VMs this can print several lines.
+
+=cut
+
+sub output_query_kernel_arch
+{
+ my %arches;
+
+ foreach my $os (keys %$oses) {
+ foreach my $kernel (@{$oses->{$os}->{kernels}}) {
+ $arches{$kernel->{arch}} = 1 if exists $kernel->{arch};
+ }
+ }
+
+ foreach (sort keys %arches) {
+ print "kernel_arch=$_\n";
+ }
+}
+
=back
=head1 SEE ALSO
}
$r->{fstab} = \@fstab if @fstab;
}
+
+ # Determine the architecture of this root.
+ my $arch;
+ foreach ("/bin/bash", "/bin/ls", "/bin/echo", "/bin/rm", "/bin/sh") {
+ if ($g->is_file ($_)) {
+ $arch = file_architecture ($g, $_);
+ last;
+ }
+ }
+
+ $r->{arch} = $arch if defined $arch;
}
# We only support NT. The control file /boot.ini contains a list of
if (defined $systemroot) {
$r->{systemroot} = resolve_windows_path ($g, "/$systemroot");
- if (defined $r->{systemroot} && $use_windows_registry) {
- _check_windows_registry ($g, $r, $r->{systemroot});
+ if (defined $r->{systemroot}) {
+ _check_windows_arch ($g, $r, $r->{systemroot});
+ if ($use_windows_registry) {
+ _check_windows_registry ($g, $r, $r->{systemroot});
+ }
}
}
}
}
+# Find Windows userspace arch.
+
+sub _check_windows_arch
+{
+ local $_;
+ my $g = shift;
+ my $r = shift;
+ my $systemroot = shift;
+
+ my $cmd_exe =
+ resolve_windows_path ($g, $r->{systemroot} . "/system32/cmd.exe");
+ $r->{arch} = file_architecture ($g, $cmd_exe) if $cmd_exe;
+}
+
sub _check_windows_registry
{
local $_;
Operating system type, eg. "linux", "windows".
+=item arch
+
+Operating system userspace architecture, eg. "i386", "x86_64".
+
=item distro
Operating system distribution, eg. "debian".
if exists $r->{root}->{package_format};
$r->{package_management} = $r->{root}->{package_management}
if exists $r->{root}->{package_management};
+ $r->{arch} = $r->{root}->{arch} if exists $r->{root}->{arch};
}
sub _assign_mount_points
List of kernels.
+This is a hash of kernel version =E<gt> a hash with the following keys:
+
+=over 4
+
+=item version
+
+Kernel version.
+
+=item arch
+
+Kernel architecture (eg. C<x86-64>).
+
+=item modules
+
+List of modules.
+
+=back
+
=item modprobe_aliases
(For Linux VMs).
# List modules.
my @modules;
- foreach ($g->find ("/lib/modules/$_")) {
+ my $any_module;
+ my $prefix = "/lib/modules/$_";
+ foreach ($g->find ($prefix)) {
if (m,/([^/]+)\.ko$, || m,([^/]+)\.o$,) {
+ $any_module = "$prefix$_" unless defined $any_module;
push @modules, $1;
}
}
$kernel{modules} = \@modules;
+ # Determine kernel architecture by looking at the arch
+ # of any kernel module.
+ $kernel{arch} = file_architecture ($g, $any_module);
+
push @kernels, \%kernel;
}
}