New in nbdkit ≥ 1.1.6, you can run nbdkit as a “captive process” under external programs like qemu or guestfish. This means that nbdkit runs for as long as qemu/guestfish is running, and when they exit it cleans up and exits too.
Here is a rather involved way to boot a Fedora 20 guest:
$ virt-builder fedora-20 $ nbdkit file file=fedora-20.img \ --run 'qemu-kvm -m 1024 -drive file=$nbd,if=virtio'
--run parameter is what tells nbdkit to run as a captive under
$nbd on the qemu command line is substituted automatically with the right
nbd: URL for the port or socket that nbdkit listens on. As soon as qemu-kvm exits, nbdkit is killed and cleaned up.
Here is another example using guestfish:
$ nbdkit file file=fedora-20.img \ --run 'guestfish --format=raw -a $nbd -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: Fedora release 20 (Heisenbug) /dev/sda3 mounted on / /dev/sda1 mounted on /boot ><fs>
The main use for this is not to run the nbdkit file plugin like this, but in conjunction with perl and python plugins, to let people easily open and edit OpenStack Glance/Cinder and other unconventional disk images.
4 responses to “New in nbdkit: Run nbdkit as a captive process”
Pingback: Use guestfish and nbdkit to examine physical disk locations | Richard WM Jones
Pingback: Streaming NBD server | Richard WM Jones
Pingback: Tip: Run virt-inspector on a compressed disk (with nbdkit) | Richard WM Jones
Pingback: Split block drivers from qemu with nbdkit | Richard WM Jones