1LOSETUP(8) System Administration LOSETUP(8)
2
3
4
6 losetup - set up and control loop devices
7
9 Get info:
10
11 losetup [loopdev]
12
13 losetup -l [-a]
14
15 losetup -j file [-o offset]
16
17 Detach a loop device:
18
19 losetup -d loopdev ...
20
21 Detach all associated loop devices:
22
23 losetup -D
24
25 Set up a loop device:
26
27 losetup [-o offset] [--sizelimit size] [--sector-size size] [-Pr]
28 [--show] -f|loopdev file
29
30 Resize a loop device:
31
32 losetup -c loopdev
33
35 losetup is used to associate loop devices with regular files or block
36 devices, to detach loop devices, and to query the status of a loop
37 device. If only the loopdev argument is given, the status of the
38 corresponding loop device is shown. If no option is given, all loop
39 devices are shown.
40
41 Note that the old output format (i.e., losetup -a) with comma-delimited
42 strings is deprecated in favour of the --list output format.
43
44 It’s possible to create more independent loop devices for the same
45 backing file. This setup may be dangerous, can cause data loss,
46 corruption and overwrites. Use --nooverlap with --find during setup to
47 avoid this problem.
48
49 The loop device setup is not an atomic operation when used with --find,
50 and losetup does not protect this operation by any lock. The number of
51 attempts is internally restricted to a maximum of 16. It is recommended
52 to use for example flock(1) to avoid a collision in heavily parallel
53 use cases.
54
56 The size and offset arguments may be followed by the multiplicative
57 suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB,
58 EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has the same meaning
59 as "KiB") or the suffixes KB (=1000), MB (=1000*1000), and so on for
60 GB, TB, PB, EB, ZB and YB.
61
62 -a, --all
63 Show the status of all loop devices. Note that not all information
64 is accessible for non-root users. See also --list. The old output
65 format (as printed without --list) is deprecated.
66
67 -d, --detach loopdev...
68 Detach the file or device associated with the specified loop
69 device(s). Note that since Linux v3.7 kernel uses "lazy device
70 destruction". The detach operation does not return EBUSY error
71 anymore if device is actively used by system, but it is marked by
72 autoclear flag and destroyed later.
73
74 -D, --detach-all
75 Detach all associated loop devices.
76
77 -f, --find [file]
78 Find the first unused loop device. If a file argument is present,
79 use the found device as loop device. Otherwise, just print its
80 name.
81
82 --show
83 Display the name of the assigned loop device if the -f option and a
84 file argument are present.
85
86 -L, --nooverlap
87 Check for conflicts between loop devices to avoid situation when
88 the same backing file is shared between more loop devices. If the
89 file is already used by another device then re-use the device
90 rather than a new one. The option makes sense only with --find.
91
92 -j, --associated file [-o offset]
93 Show the status of all loop devices associated with the given file.
94
95 -o, --offset offset
96 The data start is moved offset bytes into the specified file or
97 device. The offset may be followed by the multiplicative suffixes;
98 see above.
99
100 --sizelimit size
101 The data end is set to no more than size bytes after the data
102 start. The size may be followed by the multiplicative suffixes; see
103 above.
104
105 -b, --sector-size size
106 Set the logical sector size of the loop device in bytes (since
107 Linux 4.14). The option may be used when create a new loop device
108 as well as stand-alone command to modify sector size of the already
109 existing loop device.
110
111 -c, --set-capacity loopdev
112 Force the loop driver to reread the size of the file associated
113 with the specified loop device.
114
115 -P, --partscan
116 Force the kernel to scan the partition table on a newly created
117 loop device. Note that the partition table parsing depends on
118 sector sizes. The default is sector size is 512 bytes, otherwise
119 you need to use the option --sector-size together with --partscan.
120
121 -r, --read-only
122 Set up a read-only loop device.
123
124 --direct-io[=on|off]
125 Enable or disable direct I/O for the backing file. The optional
126 argument can be either on or off. If the optional argument is
127 omitted, it defaults to on.
128
129 -v, --verbose
130 Verbose mode.
131
132 -l, --list
133 If a loop device or the -a option is specified, print the default
134 columns for either the specified loop device or all loop devices;
135 the default is to print info about all devices. See also --output,
136 --noheadings, --raw, and --json.
137
138 -O, --output column[,column]...
139 Specify the columns that are to be printed for the --list output.
140 Use --help to get a list of all supported columns.
141
142 --output-all
143 Output all available columns.
144
145 -n, --noheadings
146 Don’t print headings for --list output format.
147
148 --raw
149 Use the raw --list output format.
150
151 -J, --json
152 Use JSON format for --list output.
153
155 Cryptoloop is no longer supported in favor of dm-crypt. For more
156 details see cryptsetup(8).
157
159 losetup returns 0 on success, nonzero on failure. When losetup displays
160 the status of a loop device, it returns 1 if the device is not
161 configured and 2 if an error occurred which prevented determining the
162 status of the device.
163
165 Since version 2.37 losetup uses LOOP_CONFIGURE ioctl to setup a new
166 loop device by one ioctl call. The old versions use LOOP_SET_FD and
167 LOOP_SET_STATUS64 ioctls to do the same.
168
170 LOOPDEV_DEBUG=all
171 enables debug output.
172
174 /dev/loop[0..N]
175 loop block devices
176
177 /dev/loop-control
178 loop control device
179
181 The following commands can be used as an example of using the loop
182 device.
183
184 # dd if=/dev/zero of=~/file.img bs=1024k count=10
185 # losetup --find --show ~/file.img
186 /dev/loop0
187 # mkfs -t ext2 /dev/loop0
188 # mount /dev/loop0 /mnt
189 ...
190 # umount /dev/loop0
191 # losetup --detach /dev/loop0
192
194 Karel Zak <kzak@redhat.com>, based on the original version from
195 Theodore Ts’o <tytso@athena.mit.edu>.
196
198 For bug reports, use the issue tracker at
199 https://github.com/util-linux/util-linux/issues.
200
202 The losetup command is part of the util-linux package which can be
203 downloaded from Linux Kernel Archive
204 <https://www.kernel.org/pub/linux/utils/util-linux/>.
205
206
207
208util-linux 2.38 2022-03-09 LOSETUP(8)