In guestfish ≥ 1.3.5 you can run arbitrary test scripts using the debug backdoor (if it is enabled in your build, which it is in all Fedora builds). This is a good way to use the libguestfs appliance for your own tests or experiments. You can already do this using virt-rescue, but this gives you a way to script it.
For example, here we use the mke2fs “-T” option as an experiment:
$ guestfish ><fs> sparse /tmp/test.img 100M ><fs> run ><fs> part-disk /dev/sda mbr ><fs> debug-upload -<<EOF /tmp/script.sh 0755 #!/bin/sh - /sbin/mke2fs -T news /dev/${sd}a1 EOF ><fs> debug sh "/tmp/script.sh" mke2fs 1.41.9 (22-Aug-2009) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 25600 inodes, 25599 blocks 1279 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=29360128 1 block group 32768 blocks per group, 32768 fragments per group 25600 inodes per group [...]
Note that two environment variables are made available to “debug sh” scripts:
-
root
is the path to where filesystems are mounted in the appliance, eg. “/sysroot” -
sd
is the prefix for block devices, usually expanding to either “sd”, “hd” or “vd” depending on the block device driver and appliance kernel in use
None of this is portable or stable. We can change the “debug” interface at any time, and it might be disabled in particular builds on libguestfs. You should add commands that you need to the libguestfs API — it’s easy!