I’ve talked before about libnbd, our NBD client library. New in libnbd 1.2 is a tool called nbdfuse which lets you turn NBD servers into virtual files.
A couple of weeks ago I mentioned you can use libnbd as a C library to edit qcow2 files. Now you can turn qcow2 files into virtual raw files:
$ mkdir dir $ nbdfuse dir/file.raw \ --socket-activation qemu-nbd -f qcow2 file.qcow2 $ ls -l dir/ total 0 -rw-rw-rw-. 1 nbd nbd 1073741824 Jan 1 10:10 file.raw
Reads and writes to file.raw
are backed by the original qcow2 file which is updated in real time.
Another fun thing to do is to use nbdkit, xz filter and curl to turn xz-compressed remote disk images into uncompressed local files:
$ mkdir dir $ nbdfuse dir/disk.img \ --command nbdkit -s curl --filter=xz \ http://builder.libguestfs.org/fedora-30.xz $ ls -l dir/ total 0 -rw-rw-rw-. 1 nbd nbd 6442450944 Jan 1 10:10 disk.img $ file dir/disk.img dir/disk.img: DOS/MBR boot sector $ qemu-system-x86_64 -m 4G \ -drive file=dir/disk.img,format=raw,if=virtio,snapshot=on
Thanks. Recently I had a need to edit some files within a .qcow2 on a machine to which I have no root access. guestfish’s list of dependencies was too extensive to manually build, so instead I was able to use nbdfuse and qemu-nbd as described here, along with some other tools to FUSE-mount .qcow2 partitions. qcow2fuse.bash is the script I wrote to glue all the necessary tools together:
https://github.com/jrwwallis/qcow2fuse