Tag Archives: guestfish

(Not) getting Fedora 19 on the ODROID XU

Not buying the eMMC module turned out to be a mistake. You can’t buy them from regular suppliers, and I’m not even sure they come in standard sizes. So I’m using a micro SD card instead.

You can download a Fedora 19 image from the ODROID forums here, but I preferred to start with the official Fedora 19 ARM image:

$ xzcat Fedora-XFCE-armhfp-19-1-sda.raw.xz > /dev/mmcblk0

In the wonderful world of ARM there’s of course no chance that this would just work (and it doesn’t). Instead I copied the /boot files from the forum image:

$ virt-copy-out -a fedora19_armhf_odroidxu_20130927.img /boot .

To make the card bootable, it requires that the first partition is VFAT and contains the /boot files extracted from the forum image. This is pretty straightforward with guestfish:

$ guestfish -a /dev/mmcblk0
><fs> run
><fs> list-filesystems
/dev/sda1: ext3
/dev/sda2: swap
/dev/sda3: ext4
><fs> mkfs vfat /dev/sda1
><fs> mount /dev/sda1 /
><fs> copy-in /tmp/boot /
><fs> ll /
total 12868
drwxr-xr-x  3 0 0   16384 Oct 19 13:43 .
drwxr-xr-x 20 0 0    4096 Oct 19 13:42 ..
-rwxr-xr-x  1 0 0     169 Oct 19 12:14 .vmlinuz-3.10.10-200.fc19.armv7hl.hmac
-rwxr-xr-x  1 0 0     174 Oct 19 12:14 .vmlinuz-3.10.10-200.fc19.armv7hl.lpae.hmac
-rwxr-xr-x  1 0 0   88811 Oct 19 12:15 config-3.4.5
-rwxr-xr-x  1 0 0 6518534 Oct 19 12:14 initramfs-3.4.5
-rwxr-xr-x  1 0 0 6518598 Oct 19 12:14 uInitrd-3.4.5
drwxr-xr-x  2 0 0    8192 Oct 19 12:41 uboot
><fs> umount-all
><fs> exit

Note that /dev/sda1 inside libguestfs corresponds to the host /dev/mmcblk0p1, and / above is the boot partition. If you prefer you could make this clearer by using disk labels and filesystem labels.

As a general tip, the large DisplayPort is apparently useless, or at least, I couldn’t get it to do anything. (Edit: Apparently you have to edit boot.ini in a manner reminiscent of modelines from x86 circa 1995. Go ARM!)

So you have to have a micro HDMI (type D) connector and be able to plug that into a digital monitor.

The boot process is a bit complex, but explained to some degree here. I copied the bootloader from the forum image to the micro SD card I was using like this:

$ xzcat fedora19_armhf_odroidxu_20130927.img.xz |
  dd bs=512 skip=1 count=1263 of=bootloader
$ dd if=bootloader bs=512 seek=1 of=/dev/mmcblk0

Also you have to flip some seriously tiny dip switches on the motherboard in order to get it to boot from the SD card.

The result anyway is: (a) Green light (b) Fan spins around (c) No ethernet lights (d) Nothing on any display (well, of course this is ARM so what did I expect?)

4 Comments

Filed under Uncategorized

Experimental User-Mode Linux backend for libguestfs

I have just pushed an experimental User-Mode Linux (UML) backend for libguestfs ≥ 1.23.15. What this means is you can now try using UML instead of KVM, which may be more lightweight and/or faster for you.

Update: The User Mode Linux book is available as a free PDF download from the publisher here.

If your distro doesn’t ship UML, you will need to compile UML from source. This was very straightforward and took me only 5 minutes following these instructions.

You will also need to install uml_utilities (specifically we need the uml_mkcow program to work around a bug in UML).

Set LIBGUESTFS_BACKEND=uml and LIBGUESTFS_QEMU to point to the UML “linux” or “vmlinux” program that you compiled. (Note that we’re just reusing the “qemu” variable name for convenience; when using UML, qemu/KVM is not involved).

You can try using guestfish or other virt tools as normal (being an experimental backend, they may not work quite right …)

$ export LIBGUESTFS_BACKEND=uml
$ export LIBGUESTFS_QEMU=/home/rjones/d/linux/vmlinux
$ guestfish -a /tmp/test1.img

Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.

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

><fs> run
><fs> list-filesystems
/dev/ubda1: ext2
><fs> mount /dev/ubda1 /
><fs> ll /
total 17
drwxr-xr-x  3 root root  1024 Aug 11 20:46 .
drwxr-xr-x 23 1000 1000  4096 Aug 11 20:54 ..
-rw-r--r--  1 root root     0 Aug 11 18:31 foobar
-rw-r--r--  1 root root     0 Aug 11 18:35 foobarbar
-rw-r--r--  1 root root     0 Aug 11 20:46 foobarbarbar
drwx------  2 root root 12288 Aug  9 22:47 lost+found

The main restriction of the UML backend is that only raw format disks are supported, no qcow2, no NBD or other remote storage.

Leave a comment

Filed under Uncategorized

Journal support in libguestfs

New in libguestfs ≥ 1.23.11 is support for reading the systemd journal from a guest.

The support is rudimentary at the moment. It would be nice to have a guestfish journal command for easy browsing of the journal (somewhat like journalctl), but we’re not there yet.

You can use journalctl from guestfish (this is true even without the journal APIs that I just added), but it involves downloading the whole journal first so it’s rather slow:

><fs> copy-out /var/log/journal /tmp
><fs> ! journalctl -D /tmp/journal

Leave a comment

Filed under Uncategorized

Recent libguestfs improvements

Nothing earth-shattering …

Support for setting UUIDs on filesystems. In particular, virt-sysprep will now choose random UUIDs for each filesystem in the guest (previously it only did this for LVM2 objects).

There’s a new add-drive-scratch API (and equivalent scratch in guestfish) which creates a temporary drive which is automatically discarded when the libguestfs handle closes.

You can now use:

guestfish -N filename=fs

to select an alternate name for the prepared disk image instead of the old test1.img, test2.img etc.

And lots of bug fixes

Leave a comment

Filed under Uncategorized

xz plugin for nbdkit

I’ve now written an xz plugin for nbdkit (previous discussion on this blog).

This is useful if you’re building up a library of xz-compressed disk images using virt-sparsify and xz, and you want to access them without having to uncompress them.

I certainly learned a lot about the xz file format and liblzma this weekend …

The xz file format consists of multiple streams (but usually one). Each stream contains zero or more blocks of compressed data, followed by an “index”. Like zip, everything in an xz file happens from the end, so the block index is at the end of the stream (this allows xz files to be streamed when writing without needing any reverse seeks).

Crucially the index contains the offset of each block both in the actual xz file and in the uncompressed data, so once you’ve read the index from a file you can find the position of any uncompressed byte and seek to the beginning of that block and read the data. Random access!

Preparing xz files correctly is important in order to be able to get good random access performance with low memory overhead:

$ xz --list /tmp/winxp.img.xz
Strms  Blocks   Compressed Uncompressed  Ratio  Check   Filename
    1     384  2,120.1 MiB  6,144.0 MiB  0.345  CRC64   /tmp/winxp.img.xz

A file with lots of small blocks like the above (16 MB block size) is relatively easy to seek inside. At most 16 MB of data has to be uncompressed to reach any byte.

Perhaps ironically, if your machine has lots of free memory then xz appears to choose a large block size, resulting in some one-block files. Here’s the same file when I originally compressed it for my guest library:

$ xz --list guest-library/winxp.img.xz
Strms  Blocks   Compressed Uncompressed  Ratio  Check   Filename
    1       1  2,100.0 MiB  6,144.0 MiB  0.342  CRC64   guest-library/winxp.img.xz

So unfortunately you may need to recompress some of your xz files using the new xz --block-size option:

$ xz --best --block-size=$((16*1024*1024)) winxp.img

Here’s how you use the new nbdkit xz plugin:

$ nbdkit plugins/nbdkit-xz-plugin.so file=winxp.img.xz
$ guestfish --ro -a nbd://localhost -i

Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.

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

Operating system: Microsoft Windows XP
/dev/sda1 mounted on /

><fs> ll /
total 1573209
drwxrwxrwx  1 root root       4096 Apr 16  2012 .
drwxr-xr-x 23 1000 1000       4096 Jun 24 13:57 ..
-rwxrwxrwx  1 root root          0 Oct 11  2011 AUTOEXEC.BAT
-rwxrwxrwx  1 root root          0 Oct 11  2011 CONFIG.SYS
drwxrwxrwx  1 root root       4096 Oct 11  2011 Documents and Settings
-rwxrwxrwx  1 root root          0 Oct 11  2011 IO.SYS
-rwxrwxrwx  1 root root          0 Oct 11  2011 MSDOS.SYS
[...]

4 Comments

Filed under Uncategorized

qemu 1.5.0 released, with ssh block device support

qemu 1.5.0 has been released, featuring ssh support so you can access remote disks over ssh, including from libguestfs.

Here’s how to use this from guestfish:

$ export LIBGUESTFS_BACKEND=direct
$ guestfish --ro -a ssh://onuma/mnt/scratch/winxp.img -i

Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.

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

Operating system: Microsoft Windows XP
/dev/sda1 mounted on /

><fs> ll /
total 1573209
drwxrwxrwx  1 root root       4096 Apr 16  2012 .
drwxr-xr-x 23 1000 1000       4096 May 20 19:47 ..
-rwxrwxrwx  1 root root          0 Oct 11  2011 AUTOEXEC.BAT
-rwxrwxrwx  1 root root          0 Oct 11  2011 CONFIG.SYS
drwxrwxrwx  1 root root       4096 Oct 11  2011 Documents and Settings
-rwxrwxrwx  1 root root          0 Oct 11  2011 IO.SYS
-rwxrwxrwx  1 root root          0 Oct 11  2011 MSDOS.SYS
-rwxrwxrwx  1 root root      47564 Apr 14  2008 NTDETECT.COM
drwxrwxrwx  1 root root       4096 Oct 11  2011 Program Files
drwxrwxrwx  1 root root       4096 Oct 11  2011 System Volume Information
drwxrwxrwx  1 root root      28672 Oct 11  2011 WINDOWS
-rwxrwxrwx  1 root root        211 Oct 11  2011 boot.ini
-rwxrwxrwx  1 root root     250048 Apr 14  2008 ntldr
-rwxrwxrwx  1 root root 1610612736 Oct 11  2011 pagefile.sys

Leave a comment

Filed under Uncategorized

Testing exabyte-sized filesystems using qcow2 and guestfish

You can use qcow2 backing files as a convenient way to test what happens when you try to create exabyte-sized filesystems. Just to remind you, 1 exabyte is a million terabytes, or a pile of ordinary hard disks stacked 8 miles high.

There is a bug in qemu that prevents you from creating very large disks unless you adjust the cluster_size option (thanks Kevin Wolf):

$ qemu-img create -f qcow2 huge.qcow2 \
      $((1024*1024))T -o cluster_size=2M
Formatting 'huge.qcow2', fmt=qcow2 size=1152921504606846976 encryption=off cluster_size=2097152 lazy_refcounts=off 

After that you can just attach the disk to guestfish and start playing with huge filesystems.

[I should note that virt-rescue is probably a better choice of tool here, especially for people who need to experiment with unusual filesystem or LVM options]

$ guestfish -a huge.qcow2

Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.

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

><fs> run
><fs> blockdev-getsize64 /dev/sda
1152921504606846976
><fs> part-disk /dev/sda gpt

Ext4 (according to Wikipedia) is supposed to support 1 exabyte disks, but I couldn’t get that to work, possibly because there was not enough RAM:

><fs> mkfs ext4 /dev/sda1
libguestfs: error: mkfs: ext4: /dev/sda1: mke2fs 1.42.5 (29-Jul-2012)
/dev/sda1: Not enough space to build proposed filesystem while setting up superblock

XFS could create a filesystem, but I didn’t let it run to completion because it would need about 5 petabytes to store the filesystem metadata:

><fs> mkfs xfs /dev/sda1
[ disks churn for many minutes while qcow2 file grows
and grows and grows ... ]

LVM2 PVs are possible, but creating a VG requires us to adjust the extent size:

><fs> pvcreate /dev/sda1
><fs> vgcreate VG /dev/sda1
libguestfs: error: vgcreate:   PV /dev/sda1 too large for extent size 4.00 MiB.
  Format-specific setup of physical volume '/dev/sda1' failed.
  Unable to add physical volume '/dev/sda1' to volume group 'VG'.
><fs> debug sh "vgcreate -s 1G VG /dev/sda1"
  Volume group "VG" successfully created
><fs> lvcreate LV VG 1000000000
><fs> lvs-full
[0] = {
  lv_name: LV
[...]
  lv_size: 1048576536870912
}

Previously …

Leave a comment

Filed under Uncategorized