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/ \

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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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