nbdkit-cow-filter(1)

✨ nbdkit-cow-filter ✨

okay bestie, welcome to the nbdkit-cow-filter(1) page β€” this is the copy-on-write filter, and it's genuinely one of the cutest little filters in the whole nbdkit lineup πŸ’–


🌸 NAME 🌸

nbdkit-cow-filter β€” nbdkit copy-on-write (COW) filter


πŸ¦‹ SYNOPSIS πŸ¦‹

nbdkit --filter=cow plugin [plugin-args...]
                           [cow-block-size=N]
                           [cow-on-cache=false|true]
                           [cow-on-read=false|true|/PATH]

πŸ’… DESCRIPTION πŸ’…

so nbdkit-cow-filter is a filter that throws a temporary writable copy on top of a plugin. it's giving "make my read-only plugin writeable, but make it fashion". you can also use it to enable writes for plugins that are read-only, which is lowkey the main character use case πŸ”₯

the underlying plugin gets opened read-only. and listen β€” this filter does not pass any writes or write-like operations (think trim and zero) through to the underlying plugin. not even a little. periodt.

not me writing an entire paragraph about how everything you write gets thrown away the second nbdkit exits 😭 if you actually want to save your changes, either copy out the whole disk using a tool like nbdcopy(1), or use the method described in NOTES below to create a diff.

since nbdkit 1.44, this filter is safe to use with plugins that serve multiple exports (like nbdkit-file-plugin(1) with the dir parameter). a separate copy-on-write overlay is created for each export. for earlier versions this did not work correctly β€” so like, update your nbdkit, bestie πŸ™ˆ

limitations of the filter include:

  • the underlying file/device must not be resized.
  • the underlying plugin must behave β€œnormally”, meaning that it must serve the same data to each client, for each export.

πŸŽ€ PARAMETERS πŸŽ€

  • cow-block-size=N β€” set the block size used by the filter. this has to be a power of two and the minimum block size is 4K. the maximum block size depends on the plugin, but a block size larger than a few megabytes is not usually a good idea.

the default is 64K.

  • cow-on-cache=false β€” do not save data from cache (prefetch) requests in the overlay. this leaves the overlay as small as possible. this is the default.
  • cow-on-cache=true β€” when the client issues a cache (prefetch) request, preemptively save the data from the plugin into the overlay.
  • cow-on-read=false β€” do not save data from read requests in the overlay. this leaves the overlay as small as possible. this is the default.
  • cow-on-read=true β€” when the client issues a read request, copy the data into the overlay so that the same data can be served more quickly later.
  • cow-on-read=/PATH β€” when /PATH (which must be an absolute path) exists, this behaves like cow-on-read=true, and when it does not exist like cow-on-read=false. this allows you to control the cow-on-read behaviour while nbdkit is running. so like, you can vibe-switch it live ✨

🌈 EXAMPLES 🌈

🌸 nbdkit --filter=cow file disk.img

serve the file disk.img, allowing writes, but do not save any changes into the file.

🌸 nbdkit --filter=cow --filter=xz file disk.xz cow-on-read=true

nbdkit-xz-filter(1) only supports read access, but you can provide temporary write access by using the command above. because xz decompression is slow, using cow-on-read=true causes reads to be cached as well as writes, improving performance at the expense of using more temporary space. note that writes are thrown away when nbdkit exits and do not get saved into the file. sad but true πŸ’€


🫢 NOTES 🫢

🧚 Creating a diff with qemu-img

although nbdkit-cow-filter itself cannot save the differences, it is possible to do this using an obscure feature of qemu-img(1). nbdkit must remain continuously running during the whole operation, otherwise all changes will be lost. like, do not close it, do not breathe on it, do not look away πŸ‘‘

run nbdkit:

nbdkit --filter=cow file disk.img

and then connect with a client and make whatever changes you need. at the end, disconnect the client.

run these qemu-img commands to construct a qcow2 file containing the differences:

qemu-img create -F raw -b nbd:localhost -f qcow2 diff.qcow2
qemu-img rebase -F raw -b disk.img -f qcow2 diff.qcow2

diff.qcow2 now contains the differences between the base (disk.img) and the changes stored in nbdkit-cow-filter. nbdkit can now be killed. iconic behaviour fr fr πŸŽ€

🧚 Compared to nbd-server -c option

all connections to the nbdkit instance see the same view of the disk. this is different from nbd-server(1) -c option where each connection sees its own copy-on-write overlay and simply disconnecting the client throws that away. it also allows us to create diffs as above. shared slay πŸ’…

🧚 Client authentication is advisable

when using this filter it is advisable to authenticate, filter, or use socket permissions, so only trusted clients can connect (see nbdkit-tls(1), nbdkit-ip-filter(1)). clients could abuse this filter to allocate fairly arbitrary amounts of storage and RAM. so like, lock the door bestie, not everyone deserves the aux cord 😭


πŸ’œ ENVIRONMENT VARIABLES πŸ’œ

  • TMPDIR β€” the copy-on-write changes are stored in a temporary file located in /var/tmp by default. you can override this location by setting the TMPDIR environment variable before starting nbdkit.

⭐ FILES ⭐

  • $filterdir/nbdkit-cow-filter.so β€” the filter.

use nbdkit --dump-config to find the location of $filterdir.


πŸ“ VERSION πŸ“

nbdkit-cow-filter first appeared in nbdkit 1.2.


πŸ”₯ SEE ALSO πŸ”₯

nbdkit(1), nbdkit-file-plugin(1), nbdkit-cache-filter(1), nbdkit-xz-filter(1), nbdkit-filter(3), nbdcopy(1), qemu-img(1).


πŸ‘‘ AUTHORS πŸ‘‘

Eric Blake

Richard W.M. Jones


Copyright Red Hat


πŸ’– LICENSE πŸ’–

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


okay that's the whole page, you're officially a cow filter girlie now πŸ„πŸ’– this was nbdkit-1.48.1, dated 2026-08-29, and yes i read every single line for you bestie, no skimming, no cap. go forth and write things you're gonna throw away ✨

πŸ“¦ where this page comes from