Tag Archives: virt-inspector

libguestfs: Live CD inspection

New in libguestfs 1.9.4, you can now run virt-inspector on some types of installer CD and live CD. The output tells you what type of operating system is on the CD:

$ virt-inspector cd.iso
<?xml version="1.0"?>
    <product_name>Windows Server 2003 Enterprise x64 Edition</product_name>
      <mountpoint dev="/dev/sda">/</mountpoint>
      <filesystem dev="/dev/sda">


On IRC someone asked me how long this takes. Here is the time to run the above command on my laptop:

real	0m4.736s
user	0m1.134s
sys	0m2.897s

The use case is in tools like virt-manager where we would like to detect what sort of ISO a user is installing from so that we can set the OS hints correctly. 5 seconds is just about acceptable as long as this happens in the background and doesn’t disturb the UI.

Leave a comment

Filed under Uncategorized

What is guest inspection

[This article expands on what I wrote here.]

I’ve been asked a few times if there is a standard for describing or inspecting virtual machines. Or conversely, should virt-inspector produce Enterprise Standard XML and not the ad-hoc XML that it produces right now?

Consider first what does “operating system version” mean? “Fedora 14” — what does that mean? It could mean a “class” of operating systems, waiting to be installed. Or perhaps it means a particular installed instance, together with all the configuration tweaks made by the administrator? Or perhaps you mean a bare installation before configuration (what the cool kids are now calling “JEOS”).

For a class of operating systems, before installation, what you would like to know includes:

  1. kernel type (“linux”)
  2. operating system name (“Fedora”)
  3. operating system version (“14”)
  4. architecture
  5. install location
  6. how to download and install it
  7. do installed versions need licensing, like Windows Activation or RHN subs?
  8. what preferred devices should we expose to new instances? (eg. does this have drivers for virtio, or should we expose some legacy devices?)
  9. minimum and recommended resources (RAM, disk space etc)

There is no comprehensive store of this data at the moment, although virt-install hard-codes some of it. So does VMware.

An installed instance of an OS is quite different. You’d like to know:

  1. what configuration changes were made?
  2. what applications are installed?
  3. what device drivers does it expect?
  4. what’s the state of critical security fixes?

and more. virt-inspector covers some of this. It also crosses over with inventory management standards like the impenetrable CIM. It also enters configuration management territory, so tools like puppet, kickstart and cfengine are applicable.

A running OS contains even more information beyond what is in the disk image:

  1. how many vCPUs?
  2. how much RAM
  3. what actual devices and resources?

Here we overlap with OVF, libvirt XML and more.

So there you have it: a difficult, multi-faceted, ill-defined problem with no easy answers.

Leave a comment

Filed under Uncategorized

Changes ahead for libguestfs RHEL 6.1 package

I previously said that libguestfs in RHEL 6.1 would be based on the recent upstream 1.6 release.

This plans have had to change slightly. It looks like we’ll rebase to 1.7.16 (a development version).

The reason is simply that to get into the next release of RHEV we had to remove the Perl dependencies on a number of key programs, because the tiny RHEV-H hypervisor [PDF] doesn’t have space to include Perl. Several programs like virt-inspector and virt-df had to be rewritten in C. We could backport all of the changes but they amount to nearly every change since 1.6 anyway.

What I do have to do is to meticulously check each C program precisely matches the old Perl version, in terms of output, command line arguments and so on, so that scripts written against RHEL 6.0 won’t break. But that’s what you pay Red Hat for.

Preview packages will be available here.


Filed under Uncategorized

libguestfs inspection now lists Windows apps

In version ≥ 1.7.8 Windows apps can be listed from virt-inspector:

$ virt-inspector Win7.img
        <name>Mozilla Firefox (3.6.12)</name>
        <display_name>Mozilla Firefox (3.6.12)</display_name>
        <version>3.6.12 (en-GB)</version>
        <install_path>C:\Program Files\Mozilla Firefox</install_path>

or from guestfish:

$ guestfish -a Win7.img --ro -i
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.

Type: 'help' for help on commands
      'man' to read the manual
      'quit' to quit the shell

Operating system: Windows 7 Enterprise
/dev/vda2 mounted on /

><fs> inspect-list-applications /dev/vda2
[0] = {
  app_name: Mozilla Firefox (3.6.12)
  app_display_name: Mozilla Firefox (3.6.12)
  app_epoch: 0
  app_version: 3.6.12 (en-GB)
  app_install_path: C:\Program Files\Mozilla Firefox
  app_publisher: Mozilla
  app_url: http://www.mozilla.com/en-GB/
[1] = {
  app_name: VLC media player
  app_display_name: VLC media player 1.1.5
  app_epoch: 0
  app_version: 1.1.5
  app_install_path: C:\Program Files\VideoLAN\VLC
  app_publisher: VideoLAN
  app_url: http://www.videolan.org/

The same API also works for Fedora, RHEL, Debian and Ubuntu guests, where it lists installed packages instead of “applications”.

Leave a comment

Filed under Uncategorized

Tip: Use Augeas to get the default boot kernel for a VM

Note: This requires libguestfs ≥ 1.5.23

The example below demonstrates a couple of new features of libguestfs 1.5: the core inspection API, and add_drive_opts with optional arguments. Along with the use of Augeas to parse configuration files with ease.

You can use this as a template for getting almost any information from a guest or disk image. Examples include:

  • list the user accounts in the guest
  • what repositories is it configured to use
  • what NTP servers does it connect to
  • what were the boot messages last time it booted
  • list who was logged in recently
#!/usr/bin/perl -w

use Sys::Guestfs;

die "Usage: whichboot.pl linuxdisk.img\n" if @ARGV == 0;

# Add the disk image.
my $g = Sys::Guestfs->new ();
foreach (@ARGV) {
    $g->add_drive_opts ($_, readonly => 1);
$g->launch ();

# Inspect the operating system and mount disks correctly.
my @roots = $g->inspect_os ();
die "no operating system detected, or OS is multi-boot" unless @roots == 1;
my %fses = $g->inspect_get_mountpoints ($roots[0]);
my @fses = sort { length $a <=> length $b } keys %fses;
foreach (@fses) {
    $g->mount_ro ($fses{$_}, $_);

# Use Augeas to parse configuration files.
$g->aug_init ("/", 16);

# Get GRUB default boot option.
my $grub_conf = "//files/boot/grub/menu.lst";
my $default = $g->aug_get ("$grub_conf/default");

# Add 1 because GRUB counts from 0, Augeas counts from 1.

# Get the kernel from GRUB.
my $kernel = $g->aug_get ("$grub_conf/title[$default]/kernel");

print "default boot kernel: $kernel\n"

Leave a comment

Filed under Uncategorized

New features in libguestfs 1.6: Inspect disk images from any programming language

In this series of posts I want to cover some of the upcoming features in libguestfs 1.6. Of course you don’t need to wait for 1.6 to be released, you can try them out now from the development branch (source) or in these Fedora 14 testing builds

If I give you a virtual machine (or its disk image — almost the same thing), how do you know what’s in it? Is it a copy of Windows or Linux? In libguestfs you can use virt-inspector to give you a report. But in older versions what you couldn’t do was the same thing from the API. Virt-inspector is written as a Perl library, so that information is only available to Perl tools.

In libguestfs 1.6 we have rewritten this code in C and made it available to all the language bindings.

The example below is an OCaml program that inspects a disk image to reveal the product name. You can just save it to a file, chmod +x the file, and run it from the command line like this:

$ ./inspect.ml disk.img
Fedora release 13 (Goddard)
$ sudo ./inspect.ml /dev/vg_pin/Win7x32
Windows 7 Enterprise
#!/usr/bin/ocamlrun /usr/bin/ocaml
#use "topfind";;
#require "guestfs";;
module G = Guestfs
let () =
  let filename = Sys.argv.(1) in
  let g = G.create () in
  G.add_drive_ro g filename;
  G.launch g;
  let roots = G.inspect_os g in
  print_endline (G.inspect_get_product_name g roots.(0))

Leave a comment

Filed under Uncategorized

Tip: Pack files into a new disk image

Note: This requires libguestfs ≥ 1.4

If files/ is a directory containing some files, you can create a new disk image populated with those files using the command below (virt-make-fs can also be used for this):

$ guestfish -N fs:ext2:400M -m /dev/sda1 tar-in <(tar -C files/ -cf - .) /


  1. guestfish -N fs:ext2:400M creates a prepared disk image which is 400MB in size with a single partition formatted as ext2. The new disk image is called test1.img.
  2. -m /dev/sda1 mounts the new filesystem when guestfish starts up.
  3. tar-in [...] / uploads and unpacks the tar file into the root directory of the mounted disk image.
  4. <(tar -C files/ -cf - .) is a bash process substitution which runs the tar command and supplies the output (ie. the tar file) as the input on the command line.

This is a quick way to create “appliances” using febootstrap and libguestfs, although you should note that I don’t think these appliances would really work, I just use them for testing our virtualization management tools, like the ability to detect and manage disk images:

$ febootstrap -i fedora-release -i bash -i setup -i coreutils fedora-13 f13
$ echo '/dev/sda1 / ext2 defaults 1 1' > fstab
$ febootstrap-install f13 fstab /etc 0644 root.root
$ febootstrap-minimize f13
$ guestfish -N fs:ext2:40M -m /dev/sda1 tar-in <(tar -C f13 -cf - .) /
$ guestfish --ro -i -a test1.img

Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.

Type: 'help' for a list of commands
      'man' to read the manual
      'quit' to quit the shell

Operating system: Fedora release 13 (Goddard)
/dev/vda1 mounted on /
><fs> cat /etc/fstab
/dev/sda1 / ext2 defaults 1 1


Filed under Uncategorized