1nbdkit-data-plugin(1) NBDKIT nbdkit-data-plugin(1)
2
3
4
6 nbdkit-data-plugin - nbdkit plugin for serving data from the command
7 line
8
10 nbdkit data data="0 1 2 3 @0x1fe 0x55 0xaa" [size=size]
11
12 nbdkit data base64="aGVsbG8gbmJka2l0IHVzZXI=" [size=size]
13
14 nbdkit data raw="binary_data" [size=size]
15
17 "nbdkit-data-plugin" is a plugin for nbdkit(1) which serves a small
18 amount of data specified directly on the command line. The plugin gets
19 its name from the "data:" URI scheme used by web browsers. This is
20 mainly useful for testing NBD clients.
21
22 You can serve data read-only using the -r flag, or read-write. Any
23 writes are thrown away when nbdkit exits.
24
25 Most operating systems have command line size limits which are quite a
26 lot smaller than any desirable disk image, so specifying a large, fully
27 populated disk image on the command line would not be possible.
28 However you can specify a small amount of data at the beginning of the
29 image, possibly followed by zeroes (using the "size" parameter to pad
30 the image to the full size), or use the "data" parameter creatively to
31 make mostly sparse disk images.
32
33 The "size" parameter can specify any virtual size up to the maximum
34 supported by nbdkit (2⁶³-1 bytes).
35
37 Create a 1 MB empty disk:
38 nbdkit data raw= size=1M
39
40 (This is a contrived example, it is better to use
41 nbdkit-memory-plugin(1) for real applications.)
42
43 Create a 1 MB disk with some nonsense data at the beginning:
44 nbdkit data base64=MTIz size=1M
45
46 The above command serves the bytes "0x31 0x32 0x33" (which is the
47 base64 decoding of "MTIz"), followed by 1M - 3 bytes of zeroes.
48
49 Create a 1 MB disk with one empty MBR-formatted partition:
50 nbdkit data data="
51 @0x1b8 178 190 207 221 0 0 0 0 2 0 131 32 32 0 1 0 0 0 255 7
52 @0x1fe 85 170
53 " size=1048576
54
55 This example was created by running:
56
57 $ rm -f disk
58 $ truncate -s 1M disk
59 $ echo start=1 | sfdisk disk
60 Device Boot Start End Sectors Size Id Type
61 disk1 1 2047 2047 1023.5K 83 Linux
62 $ ./disk2data.pl disk
63
64 The "disk2data.pl" script is provided in the nbdkit sources
65 (https://github.com/libguestfs/nbdkit/blob/master/plugins/data/disk2data.pl).
66
67 Create a disk with a partition from another file:
68 nbdkit data data="
69 @0x1b8 178 190 207 221 0 0 0 0 2 0 131 32 32 0 1 0 0 0 255 7
70 @0x1fe 85 170
71 @0x200 <partition-data
72 " size=1048576
73
74 The "<FILE" syntax is used to include a file of binary data. Note
75 that nbdkit-partitioning-plugin(1) is easier to use and more
76 flexible.
77
78 Create a small disk filled with a test pattern
79 nbdkit data data="0x55*4096"
80
81 This creates a disk containing 4096 0x55 bytes. See also
82 nbdkit-pattern-plugin(3).
83
84 Create a 7 EB (exabyte) disk with one empty GPT-formatted partition:
85 The data plugin supports huge sparse virtual disks, up to the
86 maximum size supported by nbdkit itself (2⁶³-1 bytes =
87 8 exabytes - 1 byte). These cause all sorts of problems for
88 software and so make excellent test cases. To partition such a
89 huge disk requires the GPT (GUID Partition Table) format since MBR
90 is limited to just 2 TB.
91
92 nbdkit data data="
93 @0x1c0 2 0 0xee 0xfe 0xff 0xff 0x01 0 0 0 0xff 0xff 0xff 0xff
94 @0x1fe 0x55 0xaa
95 @0x200 0x45 0x46 0x49 0x20 0x50 0x41 0x52 0x54
96 0 0 1 0 0x5c 0 0 0
97 0x9b 0xe5 0x6a 0xc5 0 0 0 0 1 0 0 0 0 0 0 0
98 0xff 0xff 0xff 0xff 0xff 0xff 0x37 0 0x22 0 0 0 0 0 0 0
99 0xde 0xff 0xff 0xff 0xff 0xff 0x37 0
100 0x72 0xb6 0x9e 0x0c 0x6b 0x76 0xb0 0x4f
101 0xb3 0x94 0xb2 0xf1 0x61 0xec 0xdd 0x3c 2 0 0 0 0 0 0 0
102 0x80 0 0 0 0x80 0 0 0 0x79 0x8a 0xd0 0x7e 0 0 0 0
103 @0x400 0xaf 0x3d 0xc6 0x0f 0x83 0x84 0x72 0x47
104 0x8e 0x79 0x3d 0x69 0xd8 0x47 0x7d 0xe4
105 0xd5 0x19 0x46 0x95 0xe3 0x82 0xa8 0x4c
106 0x95 0x82 0x7a 0xbe 0x1c 0xfc 0x62 0x90
107 0x80 0 0 0 0 0 0 0 0x80 0xff 0xff 0xff 0xff 0xff 0x37 0
108 0 0 0 0 0 0 0 0 0x70 0 0x31 0 0 0 0 0
109 @0x6fffffffffffbe00
110 0xaf 0x3d 0xc6 0x0f 0x83 0x84 0x72 0x47
111 0x8e 0x79 0x3d 0x69 0xd8 0x47 0x7d 0xe4
112 0xd5 0x19 0x46 0x95 0xe3 0x82 0xa8 0x4c
113 0x95 0x82 0x7a 0xbe 0x1c 0xfc 0x62 0x90
114 0x80 0 0 0 0 0 0 0 0x80 0xff 0xff 0xff 0xff 0xff 0x37 0
115 0 0 0 0 0 0 0 0 0x70 0 0x31 0 0 0 0 0
116 @0x6ffffffffffffe00
117 0x45 0x46 0x49 0x20 0x50 0x41 0x52 0x54
118 0 0 1 0 0x5c 0 0 0
119 0x6c 0x76 0xa1 0xa0 0 0 0 0
120 0xff 0xff 0xff 0xff 0xff 0xff 0x37 0
121 1 0 0 0 0 0 0 0 0x22 0 0 0 0 0 0 0
122 0xde 0xff 0xff 0xff 0xff 0xff 0x37 0
123 0x72 0xb6 0x9e 0x0c 0x6b 0x76 0xb0 0x4f
124 0xb3 0x94 0xb2 0xf1 0x61 0xec 0xdd 0x3c
125 0xdf 0xff 0xff 0xff 0xff 0xff 0x37 0
126 0x80 0 0 0 0x80 0 0 0 0x79 0x8a 0xd0 0x7e 0 0 0 0
127 " size=7E
128
130 Exactly one of the "data", "base64" or "raw" parameters must be
131 supplied.
132
133 data=DATA
134 Specify the disk data using a simple compact format. See "DATA
135 FORMAT" below.
136
137 base64=BASE64
138 The "base64" parameter can be used to supply binary data encoded in
139 base64 on the command line.
140
141 This is only supported if nbdkit was compiled with GnuTLS ≥ 3.6.0.
142 You can find out by checking if:
143
144 $ nbdkit data --dump-plugin
145
146 contains:
147
148 data_base64=yes
149
150 raw=BINARY
151 The "raw" parameter can be used to supply raw binary data directly
152 on the command line.
153
154 It is usually quite difficult to do this unless you are running
155 nbdkit from another program (see nbdkit-captive(1)). One
156 particular problem is that the data must not contain zero bytes
157 (ie. "\0") since those will be processed in C to mean the end of
158 the string. In almost all cases it is better to use base64
159 encoding or the custom "data" format.
160
161 size=SIZE
162 The data is truncated or extended to the size specified.
163
164 This parameter is optional: If omitted the size is defined by the
165 size of the "data", "raw" or "base64" parameter.
166
168 The "data" parameter lets you specify small disk images in a simple,
169 compact format. It is a string containing a list of bytes which are
170 written into the disk image sequentially. You can move the virtual
171 offset where bytes are written using @offset.
172
173 For example:
174
175 nbdkit data data="0 1 2 3 @0x1fe 0x55 0xaa"
176
177 creates a 0x200 = 512 byte (1 sector) image containing the four bytes
178 "0 1 2 3" at the start, and the two bytes "0x55 0xaa" at the end of the
179 sector, with the remaining 506 bytes in the middle being all zeroes.
180
181 Fields in the string can be:
182
183 @OFFSET
184 Moves the current offset to "OFFSET". The offset may be specified
185 as either decimal, octal (prefixed by 0) or hexadecimal (prefixed
186 by "0x").
187
188 <FILE
189 Read the contents of FILE into the disk image at the current
190 offset. The offset is incremented by the size of the file. The
191 filename can be a relative or absolute path, but cannot contain
192 whitespace in the name.
193
194 BYTE
195 Write "BYTE" at the current offset and advance the offset by 1
196 byte. The byte may be specified as either decimal, octal (prefixed
197 by 0) or hexadecimal (prefixed by "0x").
198
199 BYTE*N
200 Repeat "BYTE" "N" times (where "N" is a number). Note there must
201 not be any whitespace around the "*" character.
202
203 Whitespace between fields in the string is ignored.
204
205 In the example above the size (512 bytes) is implied by the data. But
206 you could additionally use the "size" parameter to either truncate or
207 extend (with zeroes) the disk image.
208
209 disk2data.pl script
210 This script can convert from small disk images into the data format
211 described above.
212
213 It is provided in the nbdkit sources. See
214 https://github.com/libguestfs/nbdkit/blob/master/plugins/data/disk2data.pl
215
217 $plugindir/nbdkit-data-plugin.so
218 The plugin.
219
220 Use "nbdkit --dump-config" to find the location of $plugindir.
221
223 "nbdkit-data-plugin" first appeared in nbdkit 1.6.
224
226 nbdkit(1), nbdkit-captive(1), nbdkit-plugin(3), nbdkit-info-plugin(1),
227 nbdkit-memory-plugin(1), nbdkit-null-plugin(1),
228 nbdkit-partitioning-plugin(1), nbdkit-pattern-plugin(1),
229 nbdkit-random-plugin(1), nbdkit-zero-plugin(1),
230 https://github.com/libguestfs/nbdkit/blob/master/plugins/data/disk2data.pl,
231 https://en.wikipedia.org/wiki/Base64.
232
234 Richard W.M. Jones
235
237 Copyright (C) 2018 Red Hat Inc.
238
240 Redistribution and use in source and binary forms, with or without
241 modification, are permitted provided that the following conditions are
242 met:
243
244 · Redistributions of source code must retain the above copyright
245 notice, this list of conditions and the following disclaimer.
246
247 · Redistributions in binary form must reproduce the above copyright
248 notice, this list of conditions and the following disclaimer in the
249 documentation and/or other materials provided with the
250 distribution.
251
252 · Neither the name of Red Hat nor the names of its contributors may
253 be used to endorse or promote products derived from this software
254 without specific prior written permission.
255
256 THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY
257 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
258 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
259 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE
260 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
261 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
262 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
263 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
264 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
265 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
266 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
267
268
269
270nbdkit-1.16.1 2019-12-03 nbdkit-data-plugin(1)