Tag Archives: virt-tools

New in virt-sparsify: In place sparsification

New in virt-sparsify ≥ 1.25.44, you can now sparsify disk images without copying them, so-called in-place sparsification.

It’s easy to use:

$ virt-sparsify --in-place fedora.img
Trimming /dev/sda1 ...
Clearing Linux swap on /dev/sda2 ...
Trimming /dev/sda3 ...

Sparsify in-place operation completed with no errors.

… and much faster. However it does require very recent kernel and qemu support.

Thanks: Paolo Bonzini, Eric Sandeen & Kevin Wolf for implementing discard support and patiently helping out when we started to test and use it.


Filed under Uncategorized

Tip: Old supermin, new libguestfs and v.v.


You want to compile libguestfs ≥ 1.25.38, but your distro only has old supermin 4.


Compile supermin from source. Note do not install it!

git clone https://github.com/libguestfs/supermin supermin5
cd supermin5

Create a file called localenv in the libguestfs build directory with the following content:

export SUPERMIN=/path/to/supermin5/src/supermin

and a file localconfigure containing:

source localenv
./configure "$@"
chmod +x localconfigure

Rebuild libguestfs as normal, except you use ./localconfigure instead of ./configure


You want to compile libguestfs ≤ 1.24, but you’ve installed new supermin 5.


Compile supermin 4 from source. Note do not install it!

git clone -b supermin-4.x \
    https://github.com/libguestfs/supermin supermin4
cd supermin4

Create a file called localenv in the libguestfs build directory with the following content:

export SUPERMIN=/path/to/supermin4/src/supermin
export SUPERMIN_HELPER=/path/to/supermin4/helper/supermin-helper

and a file localconfigure containing:

source localenv
./configure "$@"
chmod +x localconfigure

Rebuild libguestfs as normal, except you use ./localconfigure instead of ./configure

Leave a comment

Filed under Uncategorized

Supermin version 5

Recently myself with help from Pino Toscano and Hilko Bengen rewrote supermin [git repo] to make it more featureful and robust. Supermin is a clever tool that lets you distribute very tiny (< 100K) Linux appliances, which are reconstituted to full appliances just before they run.


There’s an Adam West-era Batman film where the UN Security Council is dehydrated by The Penguin, leaving little piles of powder. Batman (sorry to reveal the ending here!) saves the day by adding water and rehydrating the UN. Supermin works in much the same way — by observing that you don’t need to store (eg) /bin/bash in the appliance, since /bin/bash already exists on the host. By just storing a pointer to /bin/bash instead, you get the amazing compression ratios. Just add water.


Supermin 4 (the previous version) stored a list of filenames that would be copied into the full appliance. This was somewhat fragile if the host distro changed, eg. moving files around.

Supermin 5 stores the list of package names, and it resolves the dependencies and filenames using the RPM/dpkg/other package manager database just before reconstituting the full appliance. This solves the fragility problem completely. It also means we are now able to split libguestfs dependencies as described here.

Locking and caching

The other part of supermin which made it difficult to use in practice was locking, or rather the absence of locking. If you wanted to use supermin 4 from multiple threads, or multiple processes, you had the problem that they could race to build the full appliance potentially overwriting each other’s output. So you had to implement some sort of locking in the higher layers. And you also had to work out yourself if the full appliance needed to be rebuilt at all or if you could use a cached copy.

In supermin 5, locking and caching is now managed entirely by supermin itself and all the caller has to do is to pass two simple command line arguments:

supermin --build \
    --if-newer \
    --lock /run/lock/supermin.lock \

and supply the location of a lock file. This also works if the application is multithreaded, and if the application wants to build multiple appliances (you supply a different lock file per appliance).


Supermin used to be called “febootstrap”. That was a bad, confusing name. However one feature that febootstrap had was the ability to build chroots, which we dropped in supermin. It turns out that lots of people liked building chroots for containers — indeed it is even the recommended way to build RHEL/CentOS 6 chroots for Docker.

Supermin 5 can build chroots again by selecting the --format chroot output format. Here’s how you could build a chroot from scratch:

$ supermin --prepare -o /tmp/supermin.d \
    bash coreutils
$ supermin --build --format chroot \
    -o /tmp/appliance.d /tmp/supermin.d

Tarballs, hostfiles, excludefiles

Supermin has always allowed you to customize the full appliance by specifying extra static files or host-copied files in the supermin appliance. However in supermin 4 you had to use a specially formatted cpio file to do this.

In supermin 5 you just use a regular tarball, eg:

$ tar zcf /tmp/supermin.d/init.tar.gz ./init

Supermin 5 also lets you specify files to be copied from the host. Just create a list of wildcards, one per line:

$ cat > /tmp/supermin.d/hostfiles <<EOF

Additionally you can specify a list of files to be excluded from the full appliance, which is useful for dropping documentation and other irrelevant stuff:

$ cat > /tmp/supermin.d/excludefiles <<EOF

More information

For more information about supermin, read the supermin(1) manual page online. You can also build it from the git repository, and it is available in Fedora Rawhide and Debian/experimental.

Supermin 5 will be required for libguestfs ≥ 1.26 when it is released shortly.


Filed under Uncategorized

libguestfs is 5 years old today

As we’re hard at work on the 1.26 release of libguestfs which is going to be a blockbuster, with massive improvements to virt-builder, a rewritten and much more flexible and robust appliance, a new guest customization tool, loads of new virt-sysprep features, rewritten virt-make-fs, and lots more .. it’s worth mentioning that libguestfs is 5 years old today.

The first commit was:

commit 28d760
Author: rjones <rjones>
Date:   Tue Mar 3 08:58:37 2009 +0000

    Build environment set up for libguestfs.


Filed under Uncategorized

New in libguestfs 1.25.38

Libguestfs is under intensive development upstream to get ready for the blockbuster 1.26 release.

At the moment Pino is working on making virt-builder configuration super-flexible, so it can pull cloud images from multiple distro sources. And also making virt-builder able to install non-x86-64 guests.

I’m working on supermin. Using new features of supermin, libguestfs ≥ 1.25.38 lets you install only those filesystem features that you need support for, with more obscure filesystems & features shuffled off into subpackages that you can install optionally:

  • libguestfs — the base library
  • libguestfs-xfs — XFS support
  • libguestfs-gfs2 — GFS2 support
  • libguestfs-nilfs — NILFS v2 support
  • libguestfs-jfs — JFS support
  • libguestfs-hfsplus — HFS+ support
  • libguestfs-rsync — rsync upload/download support

This should make a few people who use libguestfs but didn’t like the number of dependencies it pulls in happy.


Filed under Uncategorized

Use guestfish and nbdkit to examine physical disk locations

This question came up: LVM makes sure that the logical volumes it creates are properly aligned to a generous block size, to ensure most efficient access. However what happens if the partition underneath an LVM physical volume isn’t aligned? Is LVM smart enough to move the LV around so it is still aligned, relative to the physical disk underneath?

This is easily answered using guestfish and captive ndkit. (Since captive nbdkit is a new feature, you’ll need Rawhide this Fedora 20 update, or to compile nbdkit from source if you want to run the commands below.)

First we create a badly aligned partition, and put an LVM physical volume inside it, and an LVM logical volume in the physical volume. This kind of disk construction is trivial with guestfish:

$ guestfish -N disk <<EOF
  part-init /dev/sda mbr
  # Unaligned partition, starts on sector 63
  part-add /dev/sda p 63 -100

  pvcreate /dev/sda1
  vgcreate VG /dev/sda1
  lvcreate LV VG 32

  # You could also create a filesystem here:
  #mkfs ext2 /dev/VG/LV

Use virt-filesystems to verify the layout of the disk:

$ virt-filesystems -a test1.img --all --long -h
Name        Type        VFS      Label  MBR  Size  Parent
/dev/VG/LV  filesystem  unknown  -      -    32M   -
/dev/VG/LV  lv          -        -      -    32M   /dev/VG
/dev/VG     vg          -        -      -    96M   /dev/sda1
/dev/sda1   pv          -        -      -    96M   -
/dev/sda1   partition   -        -      83   100M  /dev/sda
/dev/sda    device      -        -      -    100M  -

Now using nbdkit we can try writing to the logical volume, while observing the actual read and write operations that happen on the underlying file:

$ nbdkit -f -v file file=test1.img \
  --run '
    guestfish -x --format=raw -a $nbd \
      run : \
      pwrite-device /dev/VG/LV " " 0

This command prints out a lot of debugging. At the end we see:

libguestfs: trace: pwrite_device "/dev/VG/LV" " " 0
nbdkit: file[1]: debug: acquire per-connection request lock
nbdkit: file[1]: debug: pread count=4096 offset=1080832
nbdkit: file[1]: debug: release per-connection request lock
nbdkit: file[1]: debug: acquire per-connection request lock
nbdkit: file[1]: debug: pwrite count=4096 offset=1080832
nbdkit: file[1]: debug: release per-connection request lock
libguestfs: trace: pwrite_device = 1

It looks like writing to the first few bytes of /dev/VG/LV resulted in a read and a write of a 4K block starting at byte offset 1080832 (relative to the start of the physical disk).

1080832 = 0x107E00 which is 512 byte aligned. That is not aligned for performance, showing that LVM does not do any magic to adjust LVs relative to the underlying disk when the partition it is on is not aligned properly.

Notice that I created the partition starting on sector 63. If you add 1 sector (512 bytes, 0x200) to 0x107E00 you get 0x108000 which is aligned to 32K.

Leave a comment

Filed under Uncategorized

New in nbdkit: Write plugins in Python

nbdkit is a permissively licensed Network Block Device server that lets you export “unusual” disk sources to qemu and libguestfs.

New in nbdkit 1.1.5, you can write plugins using Python. Here is an example.

1 Comment

Filed under Uncategorized

virt-builder: Installing cloud-init in a Debian 7 guest

The virt-builder templates that we ship just have core packages from each Linux distro. You can install more packages yourself using the --install option or by writing scripts.

Debian 7 doesn’t have cloud-init in the base distro, but it is in wheezy-backports so we have to write a short script that enables wheezy-backports and installs cloud-init from there:

set -e

# Install wheezy backports.
echo 'deb http://ftp.uk.debian.org/debian wheezy-backports main' \
  >> /etc/apt/sources.list
apt-get -y update

# Install cloud-init.
apt-get -y install cloud-init

Then we can run virt-builder, telling it to run the script during the build so that cloud-init will be available in the final image:

virt-builder debian-7 \
  --edit '/etc/inittab: s,^#([1-9].*respawn.*/sbin/getty.*),$1,' \
  --run install-cloud-init.sh

If you boot this guest, you will see cloud-init messages as it downloads the metadata and continues the customization.

(The complicated --edit option there is necessary to enable virtual consoles, so you can actually see messages being printed during boot. It will work without that option, but you won’t be able to see any messages.)

Leave a comment

Filed under Uncategorized

devconf.cz in Brno

I’ll be at devconf.cz this weekend in Brno (7th-9th Feb 2014).

I’m going to submit a lightning talk (10 mins) about virt-builder.

However lightning talks don’t happen unless you vote for me to speak! On Friday and Saturday there will be a board in the foyer where you see the talks listed and can vote for the talk(s) you want to hear. The talks themselves happen from 5.30pm on the same days.

The devconf schedule is here (needs Javascript).

Leave a comment

Filed under Uncategorized

FOSDEM lightning talk is at 16.00 today


Edit: Thanks everyone for turning up. There was a video recording which will probably be available within two weeks. Unfortunately there were some technical problems with the microphone, but I’ll try and add subtitles once the video is available.

Leave a comment

February 2, 2014 · 10:15 am