virt-resize from an NBD source

New in libguestfs ≥ 1.23.23 is the ability to use virt-resize from a remote source.

One use for this is to use nbdkit’s xz plugin as a source, to easily create new images from highly compressed templates. In the example below nbdkit transparently (and in RAM) uncompresses the disk image, serving it up over /tmp/sock (a socket):

$ nbdkit -r -f -U /tmp/sock \
    /usr/lib64/nbdkit/plugins/nbdkit-xz-plugin.so \
    file=f17x64.img.xz

Virt-resize fetches the image from the socket and writes & resizes it to the destination file:

$ truncate -s 20G /tmp/output.img   # adjust target size
$ virt-resize 'nbd://?socket=/tmp/sock' /tmp/output.img
$ killall nbdkit; rm /tmp/sock

You can then use virt-sysprep to set the hostname and run configuration scripts in the output image.

Unfortunately you also have to temporarily disable SELinux for this to work, because SELinux prevents qemu from connecting to the NBD socket. Grrrr.

Leave a comment

Filed under Uncategorized

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.