3 # Copyright (C) 2009 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 use File::Temp qw/tempdir/;
29 eval "use Sys::Virt;";
30 eval "use XML::XPath;";
31 eval "use XML::XPath::XMLParser;";
37 virt-inspector - Display OS version, kernel, drivers, mount points, applications, etc. in a virtual machine
41 virt-inspector [--connect URI] domname
43 virt-inspector guest.img [guest.img ...]
47 B<virt-inspector> examines a virtual machine and tries to determine
48 the version of the OS, the kernel version, what drivers are installed,
49 whether the virtual machine is fully virtualized (FV) or
50 para-virtualized (PV), what applications are installed and more.
52 Virt-inspector can produce output in several formats, including a
53 readable text report, and XML for feeding into other programs.
55 Virt-inspector should only be run on I<inactive> virtual machines.
56 The program tries to determine that the machine is inactive and will
57 refuse to run if it thinks you are trying to inspect a running domain.
59 In the normal usage, use C<virt-inspector domname> where C<domname> is
60 the libvirt domain (see: C<virsh list --all>).
62 You can also run virt-inspector directly on disk images from a single
63 virtual machine. Use C<virt-inspector guest.img>. In rare cases a
64 domain has several block devices, in which case you should list them
65 one after another, with the first corresponding to the guest's
66 C</dev/sda>, the second to the guest's C</dev/sdb> and so on.
68 Virt-inspector can only inspect and report upon I<one domain at a
69 time>. To inspect several virtual machines, you have to run
70 virt-inspector several times (for example, from a shell script
73 Because virt-inspector needs direct access to guest images, it won't
74 normally work over remote libvirt connections.
92 =item B<--connect URI> | B<-c URI>
94 If using libvirt, connect to the given I<URI>. If omitted,
95 then we connect to the default libvirt hypervisor.
97 Libvirt is only used if you specify a C<domname> on the
98 command line. If you specify guest block devices directly,
99 then libvirt is not used at all.
107 Force reading a particular guest even if it appears to be active. In
108 earlier versions of virt-inspector, this could be dangerous (for
109 example, corrupting the guest's disk image). However in more recent
110 versions, it should not cause corruption, but might cause
111 virt-inspector to crash or produce incorrect results.
119 The following options select the output format. Use only one of them.
120 The default is a readable text report.
124 =item B<--text> (default)
130 Produce no output at all.
134 If you select I<--xml> then you get XML output which can be fed
139 If you select I<--perl> then you get Perl structures output which
140 can be used directly in another Perl program.
146 If you select I<--fish> then we print a L<guestfish(1)> command
147 line which will automatically mount up the filesystems on the
148 correct mount points. Try this for example:
150 guestfish $(virt-inspector --fish guest.img)
152 I<--ro-fish> is the same, but the I<--ro> option is passed to
153 guestfish so that the filesystems are mounted read-only.
157 In "query mode" we answer common questions about the guest, such
158 as whether it is fullvirt or needs a Xen hypervisor to run.
160 See section I<QUERY MODE> below.
164 my $windows_registry;
166 =item B<--windows-registry>
168 If this item is passed, I<and> the guest is Windows, I<and> the
169 external program C<reged> is available (see SEE ALSO section), then we
170 attempt to parse the Windows registry. This allows much more
171 information to be gathered for Windows guests.
173 This is quite an expensive and slow operation, so we don't do it by
180 GetOptions ("help|?" => \$help,
181 "connect|c=s" => \$uri,
183 "text" => sub { $output = "text" },
184 "none" => sub { $output = "none" },
185 "xml" => sub { $output = "xml" },
186 "perl" => sub { $output = "perl" },
187 "fish" => sub { $output = "fish" },
188 "guestfish" => sub { $output = "fish" },
189 "ro-fish" => sub { $output = "ro-fish" },
190 "ro-guestfish" => sub { $output = "ro-fish" },
191 "query" => sub { $output = "query" },
192 "windows-registry" => \$windows_registry,
194 pod2usage (1) if $help;
195 pod2usage ("$0: no image or VM names given") if @ARGV == 0;
197 # Domain name or guest image(s)?
205 die "guest image $_ does not exist or is not readable\n"
209 die "virt-inspector: no libvirt support (install Sys::Virt, XML::XPath and XML::XPath::XMLParser)\n"
210 unless exists $INC{"Sys/Virt.pm"} &&
211 exists $INC{"XML/XPath.pm"} &&
212 exists $INC{"XML/XPath/XMLParser.pm"};
214 pod2usage ("$0: too many domains listed on command line") if @ARGV > 1;
218 $vmm = Sys::Virt->new (uri => $uri, readonly => 1);
220 $vmm = Sys::Virt->new (readonly => 1);
222 die "cannot connect to libvirt $uri\n" unless $vmm;
224 my @doms = $vmm->list_defined_domains ();
227 if ($_->get_name () eq $ARGV[0]) {
232 die "$ARGV[0] is not the name of an inactive libvirt domain\n"
235 # Get the names of the image(s).
236 my $xml = $dom->get_xml_description ();
238 my $p = XML::XPath->new (xml => $xml);
239 my @disks = $p->findnodes ('//devices/disk/source/@dev');
240 @images = map { $_->getData } @disks;
243 # We've now got the list of @images, so feed them to libguestfs.
244 my $g = Sys::Guestfs->new ();
245 $g->add_drive_ro ($_) foreach @images;
249 # We want to get the list of LVs and partitions (ie. anything that
250 # could contain a filesystem). Discard any partitions which are PVs.
251 my @partitions = $g->list_partitions ();
252 my @pvs = $g->pvs ();
256 return 1 if $_ eq $t;
260 @partitions = grep { ! is_pv ($_) } @partitions;
262 my @lvs = $g->lvs ();
268 Linux (distro + version)
272 +--- Filesystems ---------- Installed apps --- Kernel & drivers
273 ----------- -------------- ----------------
274 mount point => device List of apps Extra information
275 mount point => device and versions about kernel(s)
278 (plus lots of extra information
279 about each filesystem)
281 The output of virt-inspector is a complex two-level data structure.
283 At the top level is a list of the operating systems installed on the
284 guest. (For the vast majority of guests, only a single OS is
285 installed.) The data returned for the OS includes the name (Linux,
286 Windows), the distribution and version.
288 The diagram above shows what we return for each OS.
290 With the I<--xml> option the output is mapped into an XML document.
291 Unfortunately there is no clear schema for this document
292 (contributions welcome) but you can get an idea of the format by
293 looking at other documents and as a last resort the source for this
296 With the I<--fish> or I<--ro-fish> option the mount points are mapped to
297 L<guestfish(1)> command line parameters, so that you can go in
298 afterwards and inspect the guest with everything mounted in the
299 right place. For example:
301 guestfish $(virt-inspector --ro-fish guest.img)
302 ==> guestfish --ro -a guest.img -m /dev/VG/LV:/ -m /dev/sda1:/boot
306 # List of possible filesystems.
307 my @devices = sort (@lvs, @partitions);
309 # Now query each one to build up a picture of what's in it.
310 my %fses = map { $_ => check_fs ($_) } @devices;
312 # Now the complex checking code itself.
313 # check_fs takes a device name (LV or partition name) and returns
314 # a hashref containing everything we can find out about the device.
317 my $dev = shift; # LV or partition name.
319 my %r; # Result hash.
321 # First try 'file(1)' on it.
322 my $file = $g->file ($dev);
323 if ($file =~ /ext2 filesystem data/) {
326 } elsif ($file =~ /ext3 filesystem data/) {
329 } elsif ($file =~ /ext4 filesystem data/) {
332 } elsif ($file =~ m{Linux/i386 swap file}) {
338 # If it's ext2/3/4, then we want the UUID and label.
339 if (exists $r{fstype} && $r{fstype} =~ /^ext/) {
340 $r{uuid} = $g->get_e2uuid ($dev);
341 $r{label} = $g->get_e2label ($dev);
344 # Try mounting it, fnarrr.
346 $r{is_mountable} = 1;
347 eval { $g->mount_ro ($dev, "/") };
349 # It's not mountable, probably empty or some format
350 # we don't understand.
351 $r{is_mountable} = 0;
356 if ($g->is_file ("/grub/menu.lst") ||
357 $g->is_file ("/grub/grub.conf")) {
358 $r{content} = "linux-grub";
364 if ($g->is_dir ("/etc") && $g->is_dir ("/bin") &&
365 $g->is_file ("/etc/fstab")) {
366 $r{content} = "linux-root";
368 check_linux_root (\%r);
373 if ($g->is_dir ("/etc") && $g->is_dir ("/bin") &&
374 $g->is_dir ("/share") && !$g->exists ("/local") &&
375 !$g->is_file ("/etc/fstab")) {
376 $r{content} = "linux-usrlocal";
381 if ($g->is_dir ("/etc") && $g->is_dir ("/bin") &&
382 $g->is_dir ("/share") && $g->exists ("/local") &&
383 !$g->is_file ("/etc/fstab")) {
384 $r{content} = "linux-usr";
389 if ($g->is_file ("/AUTOEXEC.BAT") ||
390 $g->is_file ("/autoexec.bat") ||
391 $g->is_dir ("/Program Files") ||
392 $g->is_dir ("/WINDOWS") ||
393 $g->is_file ("/boot.ini") ||
394 $g->is_file ("/ntldr")) {
395 $r{fstype} = "ntfs"; # XXX this is a guess
396 $r{fsos} = "windows";
397 $r{content} = "windows-root";
399 check_windows_root (\%r);
414 # Look into /etc to see if we recognise the operating system.
415 if ($g->is_file ("/etc/redhat-release")) {
416 $_ = $g->cat ("/etc/redhat-release");
417 if (/Fedora release (\d+\.\d+)/) {
418 $r->{osdistro} = "fedora";
419 $r->{osversion} = "$1"
420 } elsif (/(Red Hat Enterprise Linux|CentOS|Scientific Linux).*release (\d+).*Update (\d+)/) {
421 $r->{osdistro} = "redhat";
422 $r->{osversion} = "$2.$3";
423 } elsif (/(Red Hat Enterprise Linux|CentOS|Scientific Linux).*release (\d+(?:\.(\d+))?)/) {
424 $r->{osdistro} = "redhat";
425 $r->{osversion} = "$2";
427 $r->{osdistro} = "redhat";
429 } elsif ($g->is_file ("/etc/debian_version")) {
430 $_ = $g->cat ("/etc/debian_version");
432 $r->{osdistro} = "debian";
433 $r->{osversion} = "$1";
435 $r->{osdistro} = "debian";
439 # Parse the contents of /etc/fstab. This is pretty vital so
440 # we can determine where filesystems are supposed to be mounted.
441 eval "\$_ = \$g->cat ('/etc/fstab');";
443 my @lines = split /\n/;
446 my @fields = split /[ \t]+/;
448 my $spec = $fields[0]; # first column (dev/label/uuid)
449 my $file = $fields[1]; # second column (mountpoint)
450 if ($spec =~ m{^/} ||
451 $spec =~ m{^LABEL=} ||
452 $spec =~ m{^UUID=} ||
454 push @fstab, [$spec, $file]
458 $r->{fstab} = \@fstab if @fstab;
462 # We only support NT. The control file /boot.ini contains a list of
463 # Windows installations and their %systemroot%s in a simple text
466 # XXX We could parse this better. This won't work if /boot.ini is on
467 # a different drive from the %systemroot%, and in other unusual cases.
469 sub check_windows_root
474 my $boot_ini = resolve_windows_path ("/", "boot.ini");
475 $r->{boot_ini} = $boot_ini;
477 if (defined $r->{boot_ini}) {
478 $_ = $g->cat ($boot_ini);
479 my @lines = split /\n/;
485 } elsif (m/^default=.*?\\(\w+)$/i) {
488 } elsif (m/\\(\w+)=/) {
494 if (defined $systemroot) {
495 $r->{systemroot} = resolve_windows_path ("/", $systemroot);
496 if (defined $r->{systemroot} && $windows_registry) {
497 check_windows_registry ($r, $r->{systemroot});
503 sub check_windows_registry
507 my $systemroot = shift;
509 # Download the system registry files. Only download the
510 # interesting ones, and we don't bother with user profiles at all.
511 my $system32 = resolve_windows_path ($systemroot, "system32");
512 if (defined $system32) {
513 my $config = resolve_windows_path ($system32, "config");
514 if (defined $config) {
515 my $software = resolve_windows_path ($config, "software");
516 if (defined $software) {
517 load_windows_registry ($r, $software,
518 "HKEY_LOCAL_MACHINE\\SOFTWARE");
520 my $system = resolve_windows_path ($config, "system");
521 if (defined $system) {
522 load_windows_registry ($r, $system,
523 "HKEY_LOCAL_MACHINE\\System");
529 sub load_windows_registry
536 my $dir = tempdir (CLEANUP => 1);
538 $g->download ($regfile, "$dir/reg");
540 # 'reged' command is particularly noisy. Redirect stdout and
541 # stderr to /dev/null temporarily.
542 open SAVEOUT, ">&STDOUT";
543 open SAVEERR, ">&STDERR";
544 open STDOUT, ">/dev/null";
545 open STDERR, ">/dev/null";
547 my @cmd = ("reged", "-x", "$dir/reg", "$prefix", "\\", "$dir/out");
548 my $res = system (@cmd);
552 open STDOUT, ">&SAVEOUT";
553 open STDERR, ">&SAVEERR";
558 warn "reged command failed: $?";
562 # Some versions of reged segfault on inputs. If that happens we
563 # may get no / partial output file. Anyway, if it exists, load
566 unless (open F, "$dir/out") {
567 warn "no output from reged command: $!";
570 { local $/ = undef; $content = <F>; }
574 @registry = @{$r->{registry}} if exists $r->{registry};
575 push @registry, $content;
576 $r->{registry} = \@registry;
579 # Because of case sensitivity, the actual path might have a different
580 # name, and ntfs-3g is always case sensitive. Find out what the real
581 # path is. Returns the correct full path, or undef.
582 sub resolve_windows_path
585 my $parent = shift; # Must exist, with correct case.
588 foreach ($g->ls ($parent)) {
589 if (lc ($_) eq lc ($dir)) {
590 if ($parent eq "/") {
606 # Grub version, if we care.
609 #print Dumper (\%fses);
611 #----------------------------------------------------------------------
612 # Now find out how many operating systems we've got. Usually just one.
616 foreach (sort keys %fses) {
617 if ($fses{$_}->{is_root}) {
622 get_os_version (\%r);
623 assign_mount_points (\%r);
633 $r->{os} = $r->{root}->{fsos} if exists $r->{root}->{fsos};
634 $r->{distro} = $r->{root}->{osdistro} if exists $r->{root}->{osdistro};
635 $r->{version} = $r->{root}->{osversion} if exists $r->{root}->{osversion};
638 sub assign_mount_points
643 $r->{mounts} = { "/" => $r->{root_device} };
644 $r->{filesystems} = { $r->{root_device} => $r->{root} };
646 # Use /etc/fstab if we have it to mount the rest.
647 if (exists $r->{root}->{fstab}) {
648 my @fstab = @{$r->{root}->{fstab}};
650 my ($spec, $file) = @$_;
652 my ($dev, $fs) = find_filesystem ($spec);
654 $r->{mounts}->{$file} = $dev;
655 $r->{filesystems}->{$dev} = $fs;
656 if (exists $fs->{used}) {
666 # Find filesystem by device name, LABEL=.. or UUID=..
673 foreach (sort keys %fses) {
674 if (exists $fses{$_}->{label} &&
675 $fses{$_}->{label} eq $label) {
676 return ($_, $fses{$_});
679 warn "unknown filesystem label $label\n";
681 } elsif (/^UUID=(.*)/) {
683 foreach (sort keys %fses) {
684 if (exists $fses{$_}->{uuid} &&
685 $fses{$_}->{uuid} eq $uuid) {
686 return ($_, $fses{$_});
689 warn "unknown filesystem UUID $uuid\n";
692 return ($_, $fses{$_}) if exists $fses{$_};
694 if (m{^/dev/hd(.*)} && exists $fses{"/dev/sd$1"}) {
695 return ("/dev/sd$1", $fses{"/dev/sd$1"});
697 if (m{^/dev/xvd(.*)} && exists $fses{"/dev/sd$1"}) {
698 return ("/dev/sd$1", $fses{"/dev/sd$1"});
701 return () if m{/dev/cdrom};
703 warn "unknown filesystem $_\n";
708 #print Dumper(\%oses);
710 #----------------------------------------------------------------------
711 # Mount up the disks so we can check for applications
712 # and kernels. Skip this if the output is "*fish" because
713 # we don't need to know.
715 if ($output !~ /.*fish$/) {
716 # Temporary directory for use by check_for_initrd.
717 my $dir = tempdir (CLEANUP => 1);
720 foreach $root_dev (sort keys %oses) {
721 my $mounts = $oses{$root_dev}->{mounts};
722 # Have to mount / first. Luckily '/' is early in the ASCII
723 # character set, so this should be OK.
724 foreach (sort keys %$mounts) {
725 $g->mount_ro ($mounts->{$_}, $_)
726 if $_ ne "swap" && ($_ eq '/' || $g->is_dir ($_));
729 check_for_applications ($root_dev);
730 check_for_kernels ($root_dev);
731 if ($oses{$root_dev}->{os} eq "linux") {
732 check_for_modprobe_aliases ($root_dev);
733 check_for_initrd ($root_dev, $dir);
740 sub check_for_applications
743 my $root_dev = shift;
747 my $os = $oses{$root_dev}->{os};
748 if ($os eq "linux") {
749 my $distro = $oses{$root_dev}->{distro};
750 if (defined $distro && ($distro eq "redhat" || $distro eq "fedora")) {
751 my @lines = $g->command_lines
754 "--qf", "%{name} %{epoch} %{version} %{release} %{arch}\n"]);
756 if (m/^(.*) (.*) (.*) (.*) (.*)$/) {
758 $epoch = "" if $epoch eq "(none)";
770 } elsif ($os eq "windows") {
772 # I worked out a general plan for this, but haven't
773 # implemented it yet. We can iterate over /Program Files
774 # looking for *.EXE files, which we download, then use
775 # i686-pc-mingw32-windres on, to find the VERSIONINFO
776 # section, which has a lot of useful information.
779 $oses{$root_dev}->{apps} = \@apps;
782 sub check_for_kernels
785 my $root_dev = shift;
789 my $os = $oses{$root_dev}->{os};
790 if ($os eq "linux") {
791 # Installed kernels will have a corresponding /lib/modules/<version>
792 # directory, which is the easiest way to find out what kernels
793 # are installed, and what modules are available.
794 foreach ($g->ls ("/lib/modules")) {
795 if ($g->is_dir ("/lib/modules/$_")) {
797 $kernel{version} = $_;
801 foreach ($g->find ("/lib/modules/$_")) {
802 if (m,/([^/]+)\.ko$, || m,([^/]+)\.o$,) {
807 $kernel{modules} = \@modules;
809 push @kernels, \%kernel;
813 } elsif ($os eq "windows") {
817 $oses{$root_dev}->{kernels} = \@kernels;
820 # Check /etc/modprobe.conf to see if there are any specified
821 # drivers associated with network (ethX) or hard drives. Normally
822 # one might find something like:
825 # alias scsi_hostadapter xenblk
827 # XXX This doesn't look beyond /etc/modprobe.conf, eg. in /etc/modprobe.d/
829 sub check_for_modprobe_aliases
832 my $root_dev = shift;
835 eval { @lines = $g->read_lines ("/etc/modprobe.conf"); };
836 return if $@ || !@lines;
838 my %modprobe_aliases;
841 $modprobe_aliases{$1} = $2 if /^\s*alias\s+(\S+)\s+(\S+)/;
844 $oses{$root_dev}->{modprobe_aliases} = \%modprobe_aliases;
847 # Get a listing of device drivers in any initrd corresponding to a
848 # kernel. This is an indication of what can possibly be booted.
853 my $root_dev = shift;
858 foreach my $initrd ($g->ls ("/boot")) {
859 if ($initrd =~ m/^initrd-(.*)\.img$/ && $g->is_file ("/boot/$initrd")) {
862 # We have to download these to a temporary file.
863 $g->download ("/boot/$initrd", "$dir/initrd");
865 my $cmd = "zcat $dir/initrd | file -";
866 open P, "$cmd |" or die "$cmd: $!";
868 { local $/ = undef; $lines = <P>; }
870 if ($lines =~ /ext\d filesystem data/) {
871 # Before initramfs came along, these were compressed
872 # ext2 filesystems. We could run another libguestfs
873 # instance to unpack these, but punt on them for now. (XXX)
874 warn "initrd image is unsupported ext2/3/4 filesystem\n";
876 elsif ($lines =~ /cpio/) {
877 my $cmd = "zcat $dir/initrd | cpio --quiet -it";
878 open P, "$cmd |" or die "$cmd: $!";
881 if m,([^/]+)\.ko$, || m,([^/]+)\.o$,;
884 unlink "$dir/initrd";
885 $initrd_modules{$version} = \@modules;
889 warn "unrecognized initrd image: $lines\n";
894 $oses{$root_dev}->{initrd_modules} = \%initrd_modules;
897 #----------------------------------------------------------------------
900 if ($output eq "fish" || $output eq "ro-fish") {
901 my @osdevs = keys %oses;
902 # This only works if there is a single OS.
903 die "--fish output is only possible with a single OS\n" if @osdevs != 1;
905 my $root_dev = $osdevs[0];
907 if ($output eq "ro-fish") {
911 print "-a $_ " foreach @images;
913 my $mounts = $oses{$root_dev}->{mounts};
914 # Have to mount / first. Luckily '/' is early in the ASCII
915 # character set, so this should be OK.
916 foreach (sort keys %$mounts) {
917 print "-m $mounts->{$_}:$_ " if $_ ne "swap";
923 elsif ($output eq "perl") {
924 print Dumper(\%oses);
927 # Plain text output (the default).
928 elsif ($output eq "text") {
933 elsif ($output eq "xml") {
938 elsif ($output eq "query") {
944 output_text_os ($oses{$_}) foreach sort keys %oses;
951 print $os->{os}, " " if exists $os->{os};
952 print $os->{distro}, " " if exists $os->{distro};
953 print $os->{version}, " " if exists $os->{version};
954 print "on ", $os->{root_device}, ":\n";
956 print " Mountpoints:\n";
957 my $mounts = $os->{mounts};
958 foreach (sort keys %$mounts) {
959 printf " %-30s %s\n", $mounts->{$_}, $_
962 print " Filesystems:\n";
963 my $filesystems = $os->{filesystems};
964 foreach (sort keys %$filesystems) {
966 print " label: $filesystems->{$_}{label}\n"
967 if exists $filesystems->{$_}{label};
968 print " UUID: $filesystems->{$_}{uuid}\n"
969 if exists $filesystems->{$_}{uuid};
970 print " type: $filesystems->{$_}{fstype}\n"
971 if exists $filesystems->{$_}{fstype};
972 print " content: $filesystems->{$_}{content}\n"
973 if exists $filesystems->{$_}{content};
976 if (exists $os->{modprobe_aliases}) {
977 my %aliases = %{$os->{modprobe_aliases}};
978 my @keys = sort keys %aliases;
980 print " Modprobe aliases:\n";
982 printf " %-30s %s\n", $_, $aliases{$_}
987 if (exists $os->{initrd_modules}) {
988 my %modvers = %{$os->{initrd_modules}};
989 my @keys = sort keys %modvers;
991 print " Initrd modules:\n";
993 my @modules = @{$modvers{$_}};
995 print " $_\n" foreach @modules;
1000 print " Applications:\n";
1001 my @apps = @{$os->{apps}};
1003 print " $_->{name} $_->{version}\n"
1006 print " Kernels:\n";
1007 my @kernels = @{$os->{kernels}};
1008 foreach (@kernels) {
1009 print " $_->{version}\n";
1010 my @modules = @{$_->{modules}};
1011 foreach (@modules) {
1016 if (exists $os->{root}->{registry}) {
1017 print " Windows Registry entries:\n";
1018 # These are just lumps of text - dump them out.
1019 foreach (@{$os->{root}->{registry}}) {
1027 print "<operatingsystems>\n";
1028 output_xml_os ($oses{$_}) foreach sort keys %oses;
1029 print "</operatingsystems>\n";
1036 print "<operatingsystem>\n";
1038 print "<os>", $os->{os}, "</os>\n" if exists $os->{os};
1039 print "<distro>", $os->{distro}, "</distro>\n" if exists $os->{distro};
1040 print "<version>", $os->{version}, "</version>\n" if exists $os->{version};
1041 print "<root>", $os->{root_device}, "</root>\n";
1043 print "<mountpoints>\n";
1044 my $mounts = $os->{mounts};
1045 foreach (sort keys %$mounts) {
1046 printf "<mountpoint dev='%s'>%s</mountpoint>\n",
1049 print "</mountpoints>\n";
1051 print "<filesystems>\n";
1052 my $filesystems = $os->{filesystems};
1053 foreach (sort keys %$filesystems) {
1054 print "<filesystem dev='$_'>\n";
1055 print "<label>$filesystems->{$_}{label}</label>\n"
1056 if exists $filesystems->{$_}{label};
1057 print "<uuid>$filesystems->{$_}{uuid}</uuid>\n"
1058 if exists $filesystems->{$_}{uuid};
1059 print "<type>$filesystems->{$_}{fstype}</type>\n"
1060 if exists $filesystems->{$_}{fstype};
1061 print "<content>$filesystems->{$_}{content}</content>\n"
1062 if exists $filesystems->{$_}{content};
1063 print "</filesystem>\n";
1065 print "</filesystems>\n";
1067 if (exists $os->{modprobe_aliases}) {
1068 my %aliases = %{$os->{modprobe_aliases}};
1069 my @keys = sort keys %aliases;
1071 print "<modprobealiases>\n";
1073 printf "<alias device=\"%s\">%s</alias>\n", $_, $aliases{$_}
1075 print "</modprobealiases>\n";
1079 if (exists $os->{initrd_modules}) {
1080 my %modvers = %{$os->{initrd_modules}};
1081 my @keys = sort keys %modvers;
1083 print "<initrds>\n";
1085 my @modules = @{$modvers{$_}};
1086 print "<initrd version=\"$_\">\n";
1087 print "<module>$_</module>\n" foreach @modules;
1088 print "</initrd>\n";
1090 print "</initrds>\n";
1094 print "<applications>\n";
1095 my @apps = @{$os->{apps}};
1097 print "<application>\n";
1098 print "<name>$_->{name}</name><version>$_->{version}</version>\n";
1099 print "</application>\n";
1101 print "</applications>\n";
1103 print "<kernels>\n";
1104 my @kernels = @{$os->{kernels}};
1105 foreach (@kernels) {
1107 print "<version>$_->{version}</version>\n";
1108 print "<modules>\n";
1109 my @modules = @{$_->{modules}};
1110 foreach (@modules) {
1111 print "<module>$_</module>\n";
1113 print "</modules>\n";
1114 print "</kernel>\n";
1116 print "</kernels>\n";
1118 if (exists $os->{root}->{registry}) {
1119 print "<windowsregistryentries>\n";
1120 # These are just lumps of text - dump them out.
1121 foreach (@{$os->{root}->{registry}}) {
1122 print "<windowsregistryentry>\n";
1123 print escape_xml($_), "\n";
1124 print "</windowsregistryentry>\n";
1126 print "</windowsregistryentries>\n";
1129 print "</operatingsystem>\n";
1144 When you use C<virt-inspector --query>, the output is a series of
1152 (each answer is usually C<yes> or C<no>, or the line is completely
1153 missing if we could not determine the answer at all).
1155 If the guest is multiboot, you can get apparently conflicting answers
1156 (eg. C<windows=yes> and C<linux=yes>, or a guest which is both
1157 fullvirt and has a Xen PV kernel). This is normal, and just means
1158 that the guest can do both things, although it might require operator
1159 intervention such as selecting a boot option when the guest is
1162 This section describes the full range of answers possible.
1170 output_query_windows ();
1171 output_query_linux ();
1172 output_query_rhel ();
1173 output_query_fedora ();
1174 output_query_debian ();
1175 output_query_fullvirt ();
1176 output_query_xen_domU_kernel ();
1177 output_query_xen_pv_drivers ();
1178 output_query_virtio_drivers ();
1181 =item windows=(yes|no)
1183 Answer C<yes> if Microsoft Windows is installed in the guest.
1187 sub output_query_windows
1190 foreach my $os (keys %oses) {
1191 $windows="yes" if $oses{$os}->{os} eq "windows";
1193 print "windows=$windows\n";
1196 =item linux=(yes|no)
1198 Answer C<yes> if a Linux kernel is installed in the guest.
1202 sub output_query_linux
1205 foreach my $os (keys %oses) {
1206 $linux="yes" if $oses{$os}->{os} eq "linux";
1208 print "linux=$linux\n";
1213 Answer C<yes> if the guest contains Red Hat Enterprise Linux.
1217 sub output_query_rhel
1220 foreach my $os (keys %oses) {
1221 $rhel="yes" if $oses{$os}->{os} eq "linux" && $oses{$os}->{distro} eq "redhat";
1223 print "rhel=$rhel\n";
1226 =item fedora=(yes|no)
1228 Answer C<yes> if the guest contains the Fedora Linux distribution.
1232 sub output_query_fedora
1235 foreach my $os (keys %oses) {
1236 $fedora="yes" if $oses{$os}->{os} eq "linux" && $oses{$os}->{distro} eq "fedora";
1238 print "fedora=$fedora\n";
1241 =item debian=(yes|no)
1243 Answer C<yes> if the guest contains the Debian Linux distribution.
1247 sub output_query_debian
1250 foreach my $os (keys %oses) {
1251 $debian="yes" if $oses{$os}->{os} eq "linux" && $oses{$os}->{distro} eq "debian";
1253 print "debian=$debian\n";
1256 =item fullvirt=(yes|no)
1258 Answer C<yes> if there is at least one operating system kernel
1259 installed in the guest which runs fully virtualized. Such a guest
1260 would require a hypervisor which supports full system virtualization.
1264 sub output_query_fullvirt
1266 # The assumption is full-virt, unless all installed kernels
1267 # are identified as paravirt.
1268 # XXX Fails on Windows guests.
1269 foreach my $os (keys %oses) {
1270 foreach my $kernel (@{$oses{$os}->{kernels}}) {
1271 my $is_pv = $kernel->{version} =~ m/xen/;
1273 print "fullvirt=yes\n";
1278 print "fullvirt=no\n";
1281 =item xen_domU_kernel=(yes|no)
1283 Answer C<yes> if there is at least one Linux kernel installed in
1284 the guest which is compiled as a Xen DomU (a Xen paravirtualized
1289 sub output_query_xen_domU_kernel
1291 foreach my $os (keys %oses) {
1292 foreach my $kernel (@{$oses{$os}->{kernels}}) {
1293 my $is_xen = $kernel->{version} =~ m/xen/;
1295 print "xen_domU_kernel=yes\n";
1300 print "xen_domU_kernel=no\n";
1303 =item xen_pv_drivers=(yes|no)
1305 Answer C<yes> if the guest has Xen paravirtualized drivers installed
1306 (usually the kernel itself will be fully virtualized, but the PV
1307 drivers have been installed by the administrator for performance
1312 sub output_query_xen_pv_drivers
1314 foreach my $os (keys %oses) {
1315 foreach my $kernel (@{$oses{$os}->{kernels}}) {
1316 foreach my $module (@{$kernel->{modules}}) {
1317 if ($module =~ m/xen-/) {
1318 print "xen_pv_drivers=yes\n";
1324 print "xen_pv_drivers=no\n";
1327 =item virtio_drivers=(yes|no)
1329 Answer C<yes> if the guest has virtio paravirtualized drivers
1330 installed. Virtio drivers are commonly used to improve the
1335 sub output_query_virtio_drivers
1337 foreach my $os (keys %oses) {
1338 foreach my $kernel (@{$oses{$os}->{kernels}}) {
1339 foreach my $module (@{$kernel->{modules}}) {
1340 if ($module =~ m/virtio_/) {
1341 print "virtio_drivers=yes\n";
1347 print "virtio_drivers=no\n";
1358 L<http://libguestfs.org/>.
1360 For Windows registry parsing we require the C<reged> program
1361 from L<http://home.eunet.no/~pnordahl/ntpasswd/>.
1365 Richard W.M. Jones L<http://et.redhat.com/~rjones/>
1369 Copyright (C) 2009 Red Hat Inc.
1371 This program is free software; you can redistribute it and/or modify
1372 it under the terms of the GNU General Public License as published by
1373 the Free Software Foundation; either version 2 of the License, or
1374 (at your option) any later version.
1376 This program is distributed in the hope that it will be useful,
1377 but WITHOUT ANY WARRANTY; without even the implied warranty of
1378 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1379 GNU General Public License for more details.
1381 You should have received a copy of the GNU General Public License
1382 along with this program; if not, write to the Free Software
1383 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.