In my previous post, I covered how to extend an initramfs to serve as a basis for tests and other purposes. In that example, the initramfs was simply copied off a device after installation. It occurred to me that python-guestfs would be a useful tool to make this step easier. So I've written the vmextract helper which is currently in the vmdebootstrap upstream git and will make it into the next release of vmdebootstrap for Debian (0.7).
Once vmdebootstrap has built an image, various files can be generated or modified during the install operations and some of these files can be useful when testing the image or packages which would be included in an updated image, before release. One example is the initrd built by the process of installing a Debian kernel. Rather than having to mount the image and copy the files manually, the <code>vmextract</code> helper can do it for you, without needing root privileges or any special setup.
$ /usr/share/vmdebootstrap/vmextract.py --verbose --boot \ --image bbb/bbb-debian-armmp.img \ --path /boot/initrd.img-3.14-2-armmp \ --path /lib/arm-linux-gnueabihf/libresolv.so.2
This uses python-guestfs (which will become a Recommended package for vmdebootstrap) to prepare a read-only version of the image - in this case with the /boot partition also mounted - and copies files out into the current working directory.
Note the repeating use of --path to build a list of files to be copied out. To copy out an entire directory (and all sub-directories) as a single tarball, use:
$ /usr/share/vmdebootstrap/vmextract.py --verbose --boot \ --image bbb/bbb-debian-armmp.img \ --directory /boot/ \ --filename bbb-armmp-boot.tgz
If --filename is not specified, the default filename is vmextract.tgz.
(vmextract uses gzip compression, just because.)
The other point to note is the use of the --boot option to mount the /boot partition as well as the root partition of the image as this example uses the beaglebone-black support which has a boot partition.
It's just a little helper which I hope will prove useful - if only to avoid both the need for sudo and the need for loopback mount operations with the inherent confusion of calculating offsets. Thanks to the developers of python-guestfs for making this workable in barely 100 lines of python. It uses the same cliapp support as vmdebootstrap, so can be used silently in scripts by omitting the --verbose option.
I haven't taken this on to the next step of unpacking the initrd and extending it, but that would just a bit of shell scripting using the files extracted by vmextract.py.
Next on the list will be extensions to vmdebootstrap to build live images of Debian, essentially adding Debian Installer to a vmdebootstrap image, which could actually be another python-guestfs helper (mounting read-write this time) to avoid adding lots more code to vmdebootstrap (which has grown to nearly 600 lines of python). That way, we can publish the bare VM images as well as a live conversion and reducing the number of times debootstrap needs to be called.