1nbdkit-loop(1) NBDKIT nbdkit-loop(1)
2
3
4
6 nbdkit-loop - use nbdkit with the Linux kernel client to create loop
7 devices and loop mounts
8
10 nbdkit (server) can be used with the Linux kernel nbd (client) in a
11 loop mode allowing any of the plugins supported by nbdkit to be turned
12 into Linux block devices.
13
14 In addition to nbdkit(1) itself, the main commands you will use are:
15
16 nbd-client -b 512 localhost /dev/nbd0
17 which attaches a locally running nbdkit instance to the kernel
18 device /dev/nbd0. -b 512 can be omitted when using
19 nbd-client(8) ≥ 3.19.
20
21 nbd-client -d /dev/nbd0
22 which detaches /dev/nbd0, and:
23
24 nbd-client -c /dev/nbd0
25 which queries whether /dev/nbd0 is attached or not.
26
27 modprobe nbd
28 which may be needed to load the nbd client kernel module.
29
30 The nbd-client(8) and modprobe(8) commands must be run as root.
31
32 Warning: Do not loop mount untrusted filesystems
33 Untrusted filesystems and untrusted disk images should not be loop
34 mounted because they could contain exploits that attack your host
35 kernel. Use the tools from libguestfs(3) instead since it safely
36 isolates untrusted filesystems from the host.
37
38 Loop mount a filesystem from a compressed file
39 If you have a filesystem or disk image in xz-compressed format then you
40 can use nbdkit-xz-filter(1) and nbdkit-file-plugin(1) to loop mount it
41 as follows:
42
43 nbdkit --filter=xz file disk.xz
44 nbd-client -b 512 localhost /dev/nbd0
45 mount /dev/nbd0p1 /mnt
46
47 Loop mount a filesystem from a web server
48 You can use nbdkit-curl-plugin(1) to loop mount a filesystem from a
49 disk image on a web server:
50
51 nbdkit [--filter=xz] curl https://example.com/disk.img
52 nbd-client -b 512 localhost /dev/nbd0
53 mount /dev/nbd0p1 /mnt
54
55 Use --filter=xz if the remote image is XZ-compressed.
56
57 Create a giant btrfs filesystem
58 nbdkit is useful for testing the limits of Linux filesystems. Using
59 nbdkit-memory-plugin(1) you can create virtual disks stored in RAM with
60 a virtual size up to 2⁶³-1 bytes, and then create filesystems on these:
61
62 nbdkit memory $(( 2**63 - 1 ))
63 nbd-client -b 512 localhost /dev/nbd0
64
65 Partition the device using GPT, creating a single partition with all
66 default settings:
67
68 gdisk /dev/nbd0
69
70 Make a btrfs filesystem on the disk and mount it:
71
72 mkfs.btrfs -K /dev/nbd0p1
73 mount /dev/nbd0p1 /mnt
74
75 Inject errors into Linux devices
76 Using nbdkit-error-filter(1) you can see how Linux devices react to
77 errors:
78
79 nbdkit --filter=error \
80 memory 64M \
81 error-rate=100% error-file=/tmp/inject
82 nbd-client -b 512 localhost /dev/nbd0
83 mkfs -t ext4 /dev/nbd0
84 mount /dev/nbd0 /mnt
85
86 Inject errors by touching /tmp/inject, and stop injecting errors by
87 removing this file.
88
89 Write Linux block devices in shell script
90 Using nbdkit-sh-plugin(3) you can write custom Linux block devices in
91 shell script for testing. For example the following shell script
92 creates a disk which contains a bad sector:
93
94 #!/bin/bash -
95 case "$1" in
96 thread_model) echo parallel ;;
97 get_size) echo 64M ;;
98 pread)
99 if [ $4 -le 100000 ] && [ $(( $4+$3 )) -gt 100000 ]; then
100 echo EIO Bad block >&2
101 exit 1
102 else
103 dd if=/dev/zero count=$3 iflag=count_bytes
104 fi ;;
105 *) exit 2 ;;
106 esac
107
108 Create a loop from this shell script using:
109
110 nbdkit sh ./bad-sector.sh
111 nbd-client -b 512 localhost /dev/nbd0
112
113 You can then try running tests such as:
114
115 badblocks /dev/nbd0
116
118 nbdkit(1), nbdkit-plugin(3), loop(4), losetup(8), mount(8), nbdfuse(1),
119 nbd-client(8), modprobe(8), libguestfs(3), http://libguestfs.org.
120
122 Richard W.M. Jones
123
125 Copyright (C) 2013-2018 Red Hat Inc.
126
128 Redistribution and use in source and binary forms, with or without
129 modification, are permitted provided that the following conditions are
130 met:
131
132 · Redistributions of source code must retain the above copyright
133 notice, this list of conditions and the following disclaimer.
134
135 · Redistributions in binary form must reproduce the above copyright
136 notice, this list of conditions and the following disclaimer in the
137 documentation and/or other materials provided with the
138 distribution.
139
140 · Neither the name of Red Hat nor the names of its contributors may
141 be used to endorse or promote products derived from this software
142 without specific prior written permission.
143
144 THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY
145 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
146 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
147 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE
148 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
149 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
150 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
151 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
152 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
153 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
154 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155
156
157
158nbdkit-1.16.1 2019-12-03 nbdkit-loop(1)