GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
nbdkit-data-plugin(1) NBDKIT nbdkit-data-plugin(1)

nbdkit-data-plugin - nbdkit plugin for serving data from the command line

 nbdkit data data="0 1 2 3 @0x1fe 0x55 0xaa" [size=size]

 nbdkit data base64="aGVsbG8gbmJka2l0IHVzZXI=" [size=size]

 nbdkit data raw="binary_data" [size=size]

"nbdkit-data-plugin" is a plugin for nbdkit(1) which serves a small amount of data specified directly on the command line. The plugin gets its name from the "data:" URI scheme used by web browsers. This is mainly useful for testing NBD clients.

You can serve data read-only using the -r flag, or read-write. Any writes are thrown away when nbdkit exits.

Most operating systems have command line size limits which are quite a lot smaller than any desirable disk image, so specifying a large, fully populated disk image on the command line would not be possible. However you can specify a small amount of data at the beginning of the image, possibly followed by zeroes (using the "size" parameter to pad the image to the full size), or use the "data" parameter creatively to make mostly sparse disk images.

The "size" parameter can specify any virtual size up to the maximum supported by nbdkit (2⁶³-1 bytes).

Create a 1 MB empty disk:
 nbdkit data raw= size=1M
    

(This is a contrived example, it is better to use nbdkit-memory-plugin(1) for real applications.)

Create a 1 MB disk with some nonsense data at the beginning:
 nbdkit data base64=MTIz size=1M
    

The above command serves the bytes "0x31 0x32 0x33" (which is the base64 decoding of "MTIz"), followed by 1M - 3 bytes of zeroes.

Create a 1 MB disk with one empty MBR-formatted partition:
 nbdkit data data="
   @0x1b8 178 190 207 221 0 0 0 0 2 0 131 32 32 0 1 0 0 0 255 7
   @0x1fe 85 170
   " size=1048576
    

This example was created by running:

 $ rm -f disk
 $ truncate -s 1M disk
 $ echo start=1 | sfdisk disk
 Device Boot Start   End Sectors    Size Id Type
 disk1           1  2047    2047 1023.5K 83 Linux
 $ ./disk2data.pl disk
    

The "disk2data.pl" script is provided in the nbdkit sources (https://github.com/libguestfs/nbdkit/blob/master/plugins/data/disk2data.pl).

Create a disk with a partition from another file:
 nbdkit data data="
   @0x1b8 178 190 207 221 0 0 0 0 2 0 131 32 32 0 1 0 0 0 255 7
   @0x1fe 85 170
   @0x200 <partition-data
   " size=1048576
    

The "<FILE" syntax is used to include a file of binary data. Note that nbdkit-partitioning-plugin(1) is easier to use and more flexible.

Create a small disk filled with a test pattern:
 nbdkit data data=' ( 0x55 0xAA )*2048 '
    

This creates a disk containing 4096 bytes filled with the repeating pattern 0x55 0xAA. See also nbdkit-pattern-plugin(3).

Create a 7 EB (exabyte) disk with one empty GPT-formatted partition:
The data plugin supports huge sparse virtual disks, up to the maximum size supported by nbdkit itself (2⁶³-1 bytes = 8 exabytes - 1 byte). These cause all sorts of problems for software and so make excellent test cases. To partition such a huge disk requires the GPT (GUID Partition Table) format since MBR is limited to just 2 TB.

 nbdkit data data="
   @0x1c0 2 0 0xee 0xfe 0xff 0xff 0x01 0  0 0 0xff 0xff 0xff 0xff
   @0x1fe 0x55 0xaa
   @0x200 0x45 0x46 0x49 0x20 0x50 0x41 0x52 0x54
                 0 0 1 0 0x5c 0 0 0
          0x9b 0xe5 0x6a 0xc5 0 0 0 0  1 0 0 0 0 0 0 0
          0xff 0xff 0xff 0xff 0xff 0xff 0x37 0  0x22 0 0 0 0 0 0 0
          0xde 0xff 0xff 0xff 0xff 0xff 0x37 0
                 0x72 0xb6 0x9e 0x0c 0x6b 0x76 0xb0 0x4f
          0xb3 0x94 0xb2 0xf1 0x61 0xec 0xdd 0x3c  2 0 0 0 0 0 0 0
          0x80 0 0 0 0x80 0 0 0  0x79 0x8a 0xd0 0x7e 0 0 0 0
   @0x400 0xaf 0x3d 0xc6 0x0f 0x83 0x84 0x72 0x47
                 0x8e 0x79 0x3d 0x69 0xd8 0x47 0x7d 0xe4
          0xd5 0x19 0x46 0x95 0xe3 0x82 0xa8 0x4c
                 0x95 0x82 0x7a 0xbe 0x1c 0xfc 0x62 0x90
          0x80 0 0 0 0 0 0 0  0x80 0xff 0xff 0xff 0xff 0xff 0x37 0
          0 0 0 0 0 0 0 0  0x70 0 0x31 0 0 0 0 0
   @0x6fffffffffffbe00
          0xaf 0x3d 0xc6 0x0f 0x83 0x84 0x72 0x47
                 0x8e 0x79 0x3d 0x69 0xd8 0x47 0x7d 0xe4
          0xd5 0x19 0x46 0x95 0xe3 0x82 0xa8 0x4c
                 0x95 0x82 0x7a 0xbe 0x1c 0xfc 0x62 0x90
          0x80 0 0 0 0 0 0 0  0x80 0xff 0xff 0xff 0xff 0xff 0x37 0
          0 0 0 0 0 0 0 0  0x70 0 0x31 0 0 0 0 0
   @0x6ffffffffffffe00
          0x45 0x46 0x49 0x20 0x50 0x41 0x52 0x54
                 0 0 1 0 0x5c 0 0 0
          0x6c 0x76 0xa1 0xa0 0 0 0 0
                 0xff 0xff 0xff 0xff 0xff 0xff 0x37 0
          1 0 0 0 0 0 0 0  0x22 0 0 0 0 0 0 0
          0xde 0xff 0xff 0xff 0xff 0xff 0x37 0
                 0x72 0xb6 0x9e 0x0c 0x6b 0x76 0xb0 0x4f
          0xb3 0x94 0xb2 0xf1 0x61 0xec 0xdd 0x3c
                 0xdf 0xff 0xff 0xff 0xff 0xff 0x37 0
          0x80 0 0 0 0x80 0 0 0  0x79 0x8a 0xd0 0x7e 0 0 0 0
   " size=7E
    

Exactly one of the "data", "base64" or "raw" parameters must be supplied.
data=DATA
Specify the disk data using a simple compact format. See "DATA FORMAT" below.
base64=BASE64
The "base64" parameter can be used to supply binary data encoded in base64 on the command line.

This is only supported if nbdkit was compiled with GnuTLS ≥ 3.6.0. You can find out by checking if:

 $ nbdkit data --dump-plugin
    

contains:

 data_base64=yes
    
raw=BINARY
The "raw" parameter can be used to supply raw binary data directly on the command line.

It is usually quite difficult to do this unless you are running nbdkit from another program (see nbdkit-captive(1)). One particular problem is that the data must not contain zero bytes (ie. "\0") since those will be processed in C to mean the end of the string. In almost all cases it is better to use base64 encoding or the custom "data" format.

size=SIZE
The data is truncated or extended to the size specified.

This parameter is optional: If omitted the size is defined by the size of the "data", "raw" or "base64" parameter.

The "data" parameter lets you specify small disk images in a simple, compact format. It is a string containing a list of bytes which are written into the disk image sequentially. You can move the virtual offset where bytes are written using @offset.

For example:

 nbdkit data data="0 1 2 3 @0x1fe 0x55 0xaa"

creates a 0x200 = 512 byte (1 sector) image containing the four bytes "0 1 2 3" at the start, and the two bytes "0x55 0xaa" at the end of the sector, with the remaining 506 bytes in the middle being all zeroes. In this example the size (512 bytes) is implied by the data. But you could additionally use the "size" parameter to either truncate or extend (with zeroes) the disk image.

Fields in the string can be:

@OFFSET
Moves the current offset to "OFFSET". The offset may be specified as either decimal, octal (prefixed by 0) or hexadecimal (prefixed by "0x"). Offset @0 is the first byte of the disk.
BYTE
Write "BYTE" at the current offset and advance the offset by 1 byte. The byte may be specified as either decimal, octal (prefixed by 0) or hexadecimal (prefixed by "0x").
BYTE*N
Repeat "BYTE" "N" times (where "N" is a number). Note there must not be any whitespace around the "*" character. Increases the offset by "N".
<FILE
Read the contents of binary FILE into the disk image at the current offset. The offset is incremented by the size of the file. The filename can be a relative or absolute path, but cannot contain whitespace in the name.
( ... )*N
Repeat the enclosed pattern "N" times. The offset is incremented by the length of the enclosed pattern × N. For example to create a repeating pattern of 0x55, 0xAA for 512 (2×256) bytes do:

 data="( 0x55 0xAA )*256"
    

The "( ... )" section recursively creates a new data parser so any of the above operators can appear inside, including nested "(...)*N".

Whitespace between fields in the string is ignored.

This script can convert from small disk images into the data format described above.

It is provided in the nbdkit sources. See https://github.com/libguestfs/nbdkit/blob/master/plugins/data/disk2data.pl

$plugindir/nbdkit-data-plugin.so
The plugin.

Use "nbdkit --dump-config" to find the location of $plugindir.

"nbdkit-data-plugin" first appeared in nbdkit 1.6.

nbdkit(1), nbdkit-captive(1), nbdkit-plugin(3), nbdkit-info-plugin(1), nbdkit-memory-plugin(1), nbdkit-null-plugin(1), nbdkit-partitioning-plugin(1), nbdkit-pattern-plugin(1), nbdkit-random-plugin(1), nbdkit-tmpdisk-plugin(1), nbdkit-zero-plugin(1), https://github.com/libguestfs/nbdkit/blob/master/plugins/data/disk2data.pl, https://en.wikipedia.org/wiki/Base64.

Richard W.M. Jones

Copyright (C) 2018-2020 Red Hat Inc.

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.

2022-04-13 nbdkit-1.20.4

Search for    or go to Top of page |  Section 1 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.