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 size=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 get_size) echo 64M ;;
97 pread)
98 if [ $4 -le 100000 ] && [ $(( $4+$3 )) -gt 100000 ]; then
99 echo EIO Bad block >&2
100 exit 1
101 else
102 dd if=/dev/zero count=$3 iflag=count_bytes
103 fi ;;
104 *) exit 2 ;;
105 esac
106
107 Create a loop from this shell script using:
108
109 nbdkit sh ./bad-sector.sh
110 nbd-client -b 512 localhost /dev/nbd0
111
112 You can then try running tests such as:
113
114 badblocks /dev/nbd0
115
117 nbdkit(1), nbdkit-plugin(3), loop(4), losetup(8), mount(8),
118 nbd-client(8), modprobe(8), libguestfs(3), http://libguestfs.org.
119
121 Richard W.M. Jones
122
124 Copyright (C) 2013-2018 Red Hat Inc.
125
127 Redistribution and use in source and binary forms, with or without
128 modification, are permitted provided that the following conditions are
129 met:
130
131 · Redistributions of source code must retain the above copyright
132 notice, this list of conditions and the following disclaimer.
133
134 · Redistributions in binary form must reproduce the above copyright
135 notice, this list of conditions and the following disclaimer in the
136 documentation and/or other materials provided with the
137 distribution.
138
139 · Neither the name of Red Hat nor the names of its contributors may
140 be used to endorse or promote products derived from this software
141 without specific prior written permission.
142
143 THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY
144 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
145 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
146 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE
147 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
148 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
149 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
150 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
151 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
152 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
153 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
154
155
156
157nbdkit-1.12.3 2019-05-21 nbdkit-loop(1)