Tag Archives: virtualization

Fedora 15 virtualization test day on Thursday

You can help out with Fedora 15 virtualization by joining the Fedora 15 virtualization test day this Thursday 14th April.

Leave a comment

Filed under Uncategorized

Connecting libguestfs to a running VM – updated

I posted some very experimental patches that let you connect libguestfs programs to a running virtual machine (running the guestfsd daemon).

This lets you list out and edit files on a live virtual machine. Below is an example, but note that in the final version it won’t be this complex — you will just use guestfish -i -d GuestName and some libvirt magic will know how to attach to the guest.

# guestfish -n \
    set-attach-method unix:/tmp/f14socket : \
    run : \
    ll / : \
    cat /etc/redhat-release
total 114
dr-xr-xr-x.  24 root root  4096 Jan 27 16:09 .
dr-xr-xr-x.  24 root root  4096 Jan 27 16:09 ..
-rw-r--r--.   1 root root     0 Jan 27 16:09 .autofsck
drwx------.   3 root root  4096 Sep 16 18:15 .dbus
dr-xr-xr-x.   2 root root  4096 Jan 27 15:28 bin
dr-xr-xr-x.   5 root root  1024 Jan 27 15:11 boot

Fedora release 14 (Laughlin)

Inside the guest, I’m running guestfsd by hand. This is what it looks like:

# guestfsd -fvr
verbose daemon enabled
linux commmand line: ro root=/dev/mapper/vg_f13x64-lv_root rd_LVM_LV=vg_f13x64/lv_root rd_LVM_LV=vg_f13x64/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=uk rhgb quiet

ls -la /
proc 5 (ll) took 0.00 seconds
proc 4 (cat) took 0.00 seconds
read: unexpected end of file on fd 3

Update See the updated patch series.

Leave a comment

Filed under Uncategorized

virt-what 1.7, now supports Linux VServer, IBM SystemZ, Citrix Xen, EC2

Thanks for everyone who responded to my call for testing virt-what. As a result we’ve been able to add support for Linux VServer, IBM SystemZ (LPAR and z/VM) for people with large wallets and strong floors, and more.

Thank especially to Barış Metin, Dan Horák, Bhavna Sarathy, Matthew Booth, Don Dutile, Justin Clift, Marek Goldmann.

Source tarballs, and manual page.

Leave a comment

Filed under Uncategorized

Virt preview: Try Rawhide virt packages on Fedora 14

Justin Forbes has compiled several virt-related Rawhide packages on Fedora 14. This means you can use the latest libvirt, libguestfs, virt-manager, SPICE and more on Fedora 14, and see what’s coming in Fedora 15.


Filed under Uncategorized

How are Linux drives named beyond drive 26 (/dev/sdz, ..)?

[Edit: Thanks to adrianmonk for correcting my math]

It’s surprisingly hard to find a definitive answer to the question of what happens with Linux block device names when you get past drive 26 (ie. counting from one, the first disk is /dev/sda and the 26th disk is /dev/sdz, what comes next?) I need to find out because libguestfs is currently limited to 25 disks, and this really needs to be fixed.

Anyhow, looking at the code we can see that it depends on which driver is in use.

For virtio-blk (/dev/vd*) the answer is:

Drive # — Name
1 vda
26 vdz
27 vdaa
28 vdab
52 vdaz
53 vdba
54 vdbb
702 vdzz
703 vdaaa
704 vdaab
18278 vdzzz

Beyond 18278 drives the virtio-blk code would fail, but that’s not currently an issue.

For SATA and SCSI drives under a modern Linux kernel, the same as above applies except that the code to derive names works properly beyond sdzzz up to (in theory) sd followed by 29 z‘s! [Edit: or maybe not?]

As you can see virtio and SCSI/SATA don’t use common code to name disks. In fact there are also many other block devices in the kernel, all using their own naming scheme. Most of these use numbers instead of letters: eg: /dev/loop0, /dev/ram0, /dev/mmcblk0 and so on.

If disks are partitioned, then the partitions are named by adding the partition number on the end (counting from 1). But if the drive name already ends with a number then a letter p is added between the drive name and the partition number, thus: /dev/mmcblk0p1.


Filed under Uncategorized

What’s the maximum number of virtio-blk disks?

It depends on the number of other PCI devices that you are exporting to the guest. In the current implementation each virtio-blk disk is a separate PCI device (although Anthony pointed out that you can create multifunction PCI devices which let you break this limit in some narrow circumstances).

How many other PCI devices are you likely to have? Run lspci in a guest to see. Probably you have a host bridge, an ISA bridge for all your legacy devices, a network card, a VGA adapter, a USB controller, an emulated PIIX4 and a memory balloon. That’s 7 devices, and we haven’t even got to disks yet.

PCI is limited to 32 devices in total. So 25 or so virtio block devices is the maximum you would be able to add to a real guest without accepting limitations on things like hotplugging which you would get if you used multifunction devices. (libguestfs is limited to 25 disks but for other reasons to do with limits in febootstrap).

Work is proceeding to remove this limit.

Leave a comment

Filed under Uncategorized

Tip: Creating throwaway appliances with febootstrap

This is an update to a previous posting, but using the new febootstrap 3.x cross-distro toolchain to make building supermin appliances even simpler.

Firstly we create a supermin appliance containing a few packages and their dependencies. Note that I’m not minimizing this appliance so it’s a bit bigger (3.1MB!) than the ones we would generate in reality:

$ mkdir supermin.d
$ febootstrap --names 'bash' 'coreutils' -o supermin.d
febootstrap: warning: some host files are unreadable by non-root
febootstrap: warning: get your distro to fix these files:
$ ls -lh supermin.d/
total 3.1M
-rw-rw-r--. 1 rjones rjones 2.7M Dec 10 18:23 base.img
-rw-rw-r--. 1 rjones rjones 462K Dec 10 18:23 hostfiles

The purpose of these two files is explained in the febootstrap documentation.

This won’t boot without a /init script, and we can easily provide one:

$ cat init
#!/bin/bash -
echo Welcome to my world
bash -i
$ chmod +x init
$ echo init | cpio -o -H newc --quiet > supermin.d/init.img

The 3 files in supermin.d/ are a supermin appliance, and could be packaged up in a Fedora, Debian or Ubuntu package.

When you actually want to come and launch this appliance, you use febootstrap-supermin-helper to reconstruct the appliance:

$ febootstrap-supermin-helper -f ext2 supermin.d x86_64 \
    kernel initrd root

(Note that “kernel”, “initrd” and “root” are output files in that command)

You’d usually arrange for those files to be cached, since febootstrap-supermin-helper takes a few seconds to run (8 seconds on my laptop) and by caching it you can get reconstruction time down to a fraction of a second.

Now to boot, run qemu or qemu-kvm like this:

$ qemu-kvm -kernel kernel -initrd initrd -hda root

After a few seconds you’ll get to the shell:


Filed under Uncategorized

Round-up of research on virtualization-aware disk image formats

IBM Mirage. Replaces standard formats with their own image format (“MIF”), which is a tar-like format. Advantages are you can easily see into and modify the disk image. Also supports sharing common data between VMs. Disadvantage is that it’s entirely unlike the disk image formats that are already out there, so it seems unlikely to gain traction. Also claim to be doing package upgrades on offline guests which is something libguestfs users have been doing for well over a year.

The paper above mentions the following related work:

Ventana (Stanford). Paper is undated, but latest reference is to 2006. A virtualization-aware filesystem (not block device) which offers lightweight snapshots and branches. Concept seems to be similar to wandering-tree filesystems (most notable modern example being btrfs, but these have been around for a long time).

Machine Bank (Microsoft). Microsoft’s VHD (virtual disk format) with support for sending these around a network, partial caching and so on.

Moka5 engine. Some sort of VDI thing. No information on the website.

VMWare Lab Manager.


Filed under Uncategorized

Customizing a Windows 7 install ISO

I’m told that if you want to pass additional files to Windows when it is installing, you have to put them on the actual install CD/ISO. However modifying ISOs is a palaver: they are write-once filesystems. The recommended way to modify them — using multisession support — doesn’t work for virtualization because the virtual CD drives don’t support it (nor do quite a few real CD drives).

You can unpack and repack an ISO file like this (and because we’re using libguestfs, root is not required):

$ mkdir /tmp/cd
$ cd /tmp/cd
$ guestfish --ro -a ../win.iso -m /dev/sda tar-out / - | tar xf -
$ mkisofs -o ../new-win.iso [...options...] .

If you add your own files into the /tmp/cd directory between the third and fourth steps then they will appear on the new ISO.

That’s the easy bit. The problem is that the new ISO will not be bootable, so you won’t be able to use it to install Windows from. Making it bootable involves an exploration of the command line options to “mkisofs” and a quick excursion into the ISO format.

It’s a good idea first to find out what format the existing Windows 7 ISO is in. Firstly I mount it up in guestfish to take a look around:

$ guestfish --ro -a ../en_windows_7_enterprise_x64_dvd_x15-70749.iso 

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

><fs> run
><fs> list-filesystems
/dev/vda: udf
><fs> mount-ro /dev/vda /
><fs> ll /
total 1164
dr-xr-xr-x  7 4294967295 4294967295    548 Jul 14  2009 .
drwxr-xr-x 20        500        500   4096 Nov  4 14:16 ..
-r-xr-xr-x  1 4294967295 4294967295    122 Jul 14  2009 autorun.inf
dr-xr-xr-x  4 4294967295 4294967295    568 Jul 14  2009 boot
-r-xr-xr-x  1 4294967295 4294967295 383562 Jul 14  2009 bootmgr
-r-xr-xr-x  1 4294967295 4294967295 667712 Jul 14  2009 bootmgr.efi
dr-xr-xr-x  3 4294967295 4294967295    100 Jul 14  2009 efi
-r-xr-xr-x  1 4294967295 4294967295 106760 Jul 14  2009 setup.exe
dr-xr-xr-x 10 4294967295 4294967295  10940 Jul 14  2009 sources
dr-xr-xr-x  5 4294967295 4294967295    200 Jul 14  2009 support
dr-xr-xr-x  3 4294967295 4294967295     92 Jul 14  2009 upgrade
><fs> exit

The format is UDF, the DVD replacement for ISO 9660. There is no obvious “cdboot.img” file which is what we will need in order to boot this thing.

Now look at the same disk with isoinfo:

$ isoinfo -d -i ../en_windows_7_enterprise_x64_dvd_x15-70749.iso
[lots of stuff]
Eltorito validation header:
    Hid 1
    Arch 0 (x86)
    ID 'Microsoft Corporation'
    Key 55 AA
    Eltorito defaultboot header:
        Bootid 88 (bootable)
        Boot media 0 (No Emulation Boot)
        Load segment 0
        Sys type 0
        Nsect 8
        Bootoff 2DE 734

What is interesting is that it’s an El Torito no-emulation bootable disk. The boot image required to boot it is 8 sectors long (“Nsect 8″) starting at sector number 734 (“Bootoff” in decimal).

CD sectors are 2048 bytes, so we can grab the boot image directly:

$ dd if=../en_windows_7_enterprise_x64_dvd_x15-70749.iso \
    of=boot.img bs=2048 count=8 skip=734

Now with all the information collected above, we can (with a great deal of experimentation) come up with a mkisofs command line that makes a bootable image:

$ mkisofs -o ../new-win.iso -b boot.img -no-emul-boot -c BOOT.CAT \
    -iso-level 2 -udf \
    -J -l -D -N -joliet-long -relaxed-filenames .


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