Tag Archives: augeas

5 minute introduction to Augeas (config file editing library)

Dominic Cleal’s short introduction to the Augeas configuration API.

We use Augeas a lot in libguestfs and virt-v2v, and it’s been very effective for us.

I asked Dominic how he made this video.

He uses gtk-recordmydesktop, max 100/100 audio/video quality, 30fps, 2 channel audio at 48kHz.

Sound and video are recorded at the same time, with a Sennheiser headset.

Editing is done in kdenlive.

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