nbdkit-file-plugin(1)
π nbdkit-file-plugin β the nbdkit file plugin π
okay bestie, welcome to nbdkit-file-plugin(1), part of the nbdkit fam. this is the plugin that literally just serves a file over NBD. no cap. let's get into it π¦
β¨ NAME β¨
nbdkit-file-plugin β the file plugin for nbdkit, iykyk.
β¨ SYNOPSIS β¨
nbdkit file [file=]FILENAME
[fadvise=normal|random|sequential]
[reduce-memory-pressure=true]
nbdkit file dir=DIRECTORY
nbdkit file fd=FILE_DESCRIPTOR
nbdkit file dirfd=FILE_DESCRIPTOR
β¨ DESCRIPTION β¨
so nbdkit-file-plugin is a file serving plugin for nbdkit(1). that's the whole vibe. π
it serves the file you name in FILENAME over NBD. and yes, local block devices (like /dev/sda, we see you) can be served too. iconic.
if you use the dir parameter, plot twist, the plugin switches into a whole different mode where it serves files out of the given DIRECTORY. in that mode the filename is picked by the client, which sends an NBD export name. main character client energy honestly.
if you use the fd or dirfd parameter, then you get to hand the plugin the file descriptor of a single disk or a directory, inherited from the parent process. this is lowkey so useful when you need special permissions or capabilities just to open that file descriptor, or when you wanna run nbdkit inside a sandboxed environment. π«Ά
heads up: the file is writable unless either the -r command line option is used, or nbdkit-readonly-filter(1) is in the mix.
β¨ PARAMETERS β¨
exactly one of file, dir, fd or dirfd must be given. no mixing and matching, bestie, pick one. this controls the mode of the plugin β serving a single file, the files in a directory, a single file descriptor, or the files in the directory of the file descriptor.
dir=DIRECTORYβ (nbdkit β₯ 1.22, not Windows) serve all regular files and block devices located directly inside the directory namedDIRECTORY, including the ones found by following symbolic links. other special files hanging out in the directory (like subdirectories, pipes, or Unix sockets) get ignored, sorry not sorry. see "Serving multiple files and block devices" below. πΈdirfd=FILE_DESCRIPTORβ (nbdkit β₯ 1.34, not Windows) this is basicallydir=but instead of naming the directory, the parent process should open the directory and pass this file descriptor to nbdkit by inheritance. see "Serving multiple files and block devices" below. πfadvise=normal,fadvise=random,fadvise=sequentialβ (nbdkit β₯ 1.22, not Windows) this optional flag hints to the kernel that you'll access the file normally, or in a random order, or sequentially. the exact behaviour is OS-dependent, but on Linux:normalmakes the kernel read-ahead,sequentialmakes the kernel read-ahead twice as much asnormal, andrandomturns read-ahead off entirely. see also posix_fadvise(2). the default isnormal. β¨fd=FILE_DESCRIPTORβ (nbdkit β₯ 1.34, not Windows) the parameter is the number of a file descriptor. serve the file or device that's already open on this file descriptor. the file descriptor is usually inherited from the parent process. π[file=]FILENAMEβ serve the file namedFILENAME. a local block device name can be used here too. when this mode is active, the export name the client asks for is just ignored, respectfully. thefile=prefix can be omitted in most cases. see "Magic parameters" in nbdkit(1). π¦[file=]\\.\C:,[file=]\\.\Volume,[file=]\\.\PhysicalDiskN,[file=]\\.\CdRomNβ (Windows only) serve the Windows volume specified by the device name. see:https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-device-namespaces. πreduce-memory-pressure=trueβ (nbdkit β₯ 1.22, not Windows) if the file is very large and the plugin is gonna read or write the whole thing, that can cause the file to be cached in memory (in the page cache on Linux), which evicts other files and processes, and that leads to overall slow system performance and I/O storms. π if you know the file will only be read/written once and won't be needed afterwards (so keeping it in memory afterwards is pointless, fr fr), usereduce-memory-pressure=true. this makes reads and writes minimize their use of the page cache. the default is false, which uses the kernel's normal page cache strategy. see alsofadviseabove, which can hint the access pattern. in nbdkit 1.22 - 1.44 this option was calledcache=none, but that caused a lot of confusion for people used to qemu and kernel caching modes, which are not related to this setting. not me getting flashbacks to that rename π
β¨ NOTES β¨
π Serving multiple files and block devices
using dir=DIRECTORY (or dirfd=DIRFD) you can serve all regular files and block devices located directly inside the directory named DIRECTORY, including those found by following symbolic links. other special files in the directory (such as subdirectories, pipes, or Unix sockets) are ignored. π
when this mode is used, the file to be served is chosen by the export name passed by the client. and for security, when using directory mode, this plugin will not accept export names containing slash (/). periodt.
for example:
$ ls -l /var/tmp/exports
total 0
-rw-r--r--. 1 rjones rjones 1048576 Dec 14 15:34 disk1
-rw-r--r--. 1 rjones rjones 2097152 Dec 14 15:34 disk2
lrwxrwxrwx. 1 rjones rjones 9 Dec 14 15:35 sda1 -> /dev/sda1
$ nbdkit file dir=/var/tmp/exports
this will serve three exports called disk1, disk2 and sda1. the first two are regular files and the last one is a block device. slay.
the NBD URIs of the three exports are:
nbd://localhost/disk1nbd://localhost/disk2nbd://localhost/sda1
you can add or remove files or symbolic links from the directory while nbdkit is running. live edits, we love to see it. β¨
to list exports, use the nbdinfo(1) --list option, for example:
$ nbdinfo --list nbd://localhost
protocol: newstyle-fixed without TLS, using structured packets
export="disk1":
export-size: 1048576 (1M)
uri: nbd://localhost:10809/disk1
[etc]
an NBD client can request a list of available exports using NBD_OPT_LIST. for libnbd clients see nbd_opt_list(3).
a client that requests the default export ("") will be rejected. however, you can use nbdkit-exportname-filter(1) to adjust the default export as well as do other transformations of export names. for example, to make /var/tmp/exports/disk1 be the default export:
nbdkit file dir=/var/tmp/exports \
--filter=exportname default-export=disk1
πΈ Optimizing for random or sequential access
if you know in advance that the NBD client will access the file randomly or only sequentially, then you can hint that to the kernel using:
nbdkit file disk.img fadvise=random
nbdkit file disk.img fadvise=sequential
as described in the "PARAMETERS" section above, on Linux this disables or increases the amount of read-ahead that the kernel does. π
π¦ Files on tmpfs
if you want to expose a file that resides on a file system known to have poor lseek(2) performance when searching for holes (tmpfs is known to be one such file system), you can use nbdkit-noextents-filter(1) to avoid the penalty of probing for holes. we do not tolerate slow hole-probing in this house. π
π
Plugin --dump-plugin output
you can get extra info about how the file plugin was compiled by doing:
nbdkit file --dump-plugin
some of the fields which may appear are listed below. note these are for information only and may be changed or removed at any time in the future. (so don't build your whole personality around them, bestie.)
file_block_size=yesβ if set, the plugin has support for getting the minimum and preferred I/O size of block devices.file_blkrotational=yesβ if set, the plugin has support for getting the rotational property of block devices.file_blksszget=yes,file_blkzeroout=yesβ if both set, the plugin may be able to efficiently zero ranges of block devices, where the driver and block device itself supports this. β¨file_blkdiscard=yesβ if set, the plugin may be able to efficiently trim ranges of block devices, where the driver and block device itself supports this.file_extents=yesβ if set, the plugin can read file extents.file_falloc_fl_punch_hole=yesβ if set, the plugin may be able to punch holes (make sparse) files and block devices.file_falloc_fl_zero_range=yesβ if set, the plugin may be able to efficiently zero ranges of files and block devices.winfile=yesβ if present, this is the Windows version of the file plugin with reduced functionality and some special Windows-only features, as noted in this manual. π
π Windows sparse files
this plugin supports sparse files on Windows (with hole punching). however, for this to work the files must already have the sparse property β the plugin will not make existing files sparse. use the fsutil sparse command to control the sparseness property of files.
π Old rdelay and wdelay parameters.
before nbdkit supported filters (< 1.2) this plugin had extra parameters rdelay and wdelay to insert delays. those parameters have been moved to nbdkit-delay-filter(1). modify the command line to add --filter=delay in order to use these parameters. glow-up complete. π
β Concatenating files
to concatenate and export multiple files, use nbdkit-split-plugin(1).
β¨ DEBUG FLAG β¨
-D file.zero=1β this enables very verbose debugging of the NBD zero request. this can be used to tell if the file plugin is able to zero ranges in the file or block device efficiently or not. π
β¨ FILES β¨
$plugindir/nbdkit-file-plugin.soβ the plugin.
use nbdkit --dump-config to find the location of $plugindir. π«Ά
β¨ VERSION β¨
nbdkit-file-plugin first appeared in nbdkit 1.0. OG behaviour. π
β¨ SEE ALSO β¨
nbdkit(1), nbdkit-plugin(3), nbdkit-nfs-plugin(1), nbdkit-partitioning-plugin(1), nbdkit-split-plugin(1), nbdkit-tmpdisk-plugin(1), nbdkit-count-filter(1), nbdkit-delay-filter(1), nbdkit-exportname-filter(1), nbdkit-fua-filter(1), nbdkit-luks-filter(1), nbdkit-noextents-filter(1), nbdkit-readonly-filter(1), nbdinfo(1).
β¨ AUTHORS β¨
Eric Blake
Nir Soffer
Richard W.M. Jones
β¨ COPYRIGHT β¨
Copyright Red Hat
π LICENSE π
okay bestie, legal time, don't scroll π Red Hat is letting you redistribute and use this in source and binary forms, with or without modification, and honestly? iconic of them. But β and this is the whole vibe check β you have to meet three conditions. All of them. No skipping, fr fr.
- Redistributions of source code</> must keep the copyright notice above, this whole list of conditions, and the disclaimer that's about to follow. Like, all of it, untouched. π
- Redistributions in binary form</> must reproduce that same copyright notice, conditions list, and disclaimer in the documentation and/or other materials that ship with the distribution. Yes, even the binaries. Especially the binaries. π
- 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. So no "Red Hat said my project slays" energy unless you actually asked and they actually said yes. π
and now the part that's in ALL CAPS because it legally HAS to be, no cap π this is verbatim, I am not paraphrasing a single word of it:
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.
β οΈ real talk, not a bit: there is no warranty. Not express, not implied, not merchantability, not fitness for a particular purpose. If something goes sideways, Red Hat and the contributors are not liable. That's the deal, that's the price of free software, and it's still a slay. π«Ά
and that's the whole page, bestie!! π you just read nbdkit-file-plugin(1) from nbdkit-1.48.1, dated 2026-08-29. go forth and serve files, stay hydrated, and remember: the copyright notice stays in the source. πβ¨π¦
π¦ where this page comes from
- fedora 44: nbdkit-basic-plugins 1.48.1-1.fc44 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms