]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/losetup.8.adoc
Merge branch 'xry111/pidfs' of https://github.com/xry111/util-linux
[thirdparty/util-linux.git] / sys-utils / losetup.8.adoc
1 //po4a: entry man manual
2 = losetup(8)
3 :doctype: manpage
4 :man manual: System Administration
5 :man source: util-linux {release-version}
6 :page-layout: base
7 :command: losetup
8
9 == NAME
10
11 losetup - set up and control loop devices
12
13 == SYNOPSIS
14
15 Get info:
16
17 *losetup* [_loopdev_]
18
19 *losetup* *-l* [*-a*]
20
21 *losetup* *-j* _file_ [*-o* _offset_]
22
23 Detach a loop device:
24
25 *losetup* *-d* _loopdev_ ...
26
27 Detach all associated loop devices:
28
29 *losetup* *-D*
30
31 Set up a loop device:
32
33 *losetup* [*-o* _offset_] [*--sizelimit* _size_] [*--sector-size* _size_] [*--loop-ref* _name_] [*-Pr*] [*--show*] *-f*|_loopdev file_
34
35 Resize a loop device:
36
37 *losetup* *-c* _loopdev_
38
39 == DESCRIPTION
40
41 *losetup* is used to associate loop devices with regular files or block devices, to detach loop devices, and to query the status of a loop device. If only the _loopdev_ argument is given, the status of the corresponding loop device is shown. If no option is given, all loop devices are shown.
42
43 Note that the old output format (i.e., *losetup -a*) with comma-delimited strings is deprecated in favour of the *--list* output format.
44
45 It's possible to create more independent loop devices for the same backing file. *This setup may be dangerous, can cause data loss, corruption and overwrites.* Use *--nooverlap* with *--find* during setup to avoid this problem.
46
47 The loop device setup is not an atomic operation when used with *--find*, and *losetup* does not protect this operation by any lock. The number of attempts is internally restricted to a maximum of 16. It is recommended to use for example *flock*(1) to avoid a collision in heavily parallel use cases.
48
49 == OPTIONS
50
51 The _size_ and _offset_ arguments may be followed by the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB") or the suffixes KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB and YB.
52
53 *-a*, *--all*::
54 Show the status of all loop devices. Note that not all information is accessible for non-root users. See also *--list*. The old output format (as printed without *--list*) is deprecated.
55
56 *-d*, *--detach* _loopdev_...::
57 Detach the file or device associated with the specified loop device(s). Note that since Linux v3.7 kernel uses "lazy device destruction". The detach operation does not return *EBUSY* error anymore if device is actively used by system, but it is marked by autoclear flag and destroyed later.
58
59 *-D*, *--detach-all*::
60 Detach all associated loop devices.
61
62 *-f*, *--find* [_file_]::
63 Find the first unused loop device. If a _file_ argument is present, use the found device as loop device. Otherwise, just print its name.
64
65 *--show*::
66 Display the name of the assigned loop device if the *-f* option and a _file_ argument are present.
67
68 *-L*, *--nooverlap*::
69 Check for conflicts between loop devices to avoid situation when the same backing file is shared between more loop devices. If the file is already used by another device then re-use the device rather than a new one. The option makes sense only with *--find*.
70
71 *-j*, *--associated* _file_ [*-o* _offset_]::
72 Show the status of all loop devices associated with the given _file_.
73
74 *-o*, *--offset* _offset_::
75 The data start is moved _offset_ bytes into the specified file or device. The _offset_ may be followed by the multiplicative suffixes; see above.
76
77 *--loop-ref* _string_::
78 Set reference string. The backwardly compatible default is to use the backing filename as a reference in loop setup ioctl (aka lo_file_name). This option can overwrite this default behavior and set the reference to the _string_. The reference may be used by udevd in /dev/loop/by-ref. Linux kernel does not use the reference at all, but it could be used by some old utils that cannot read the backing file from sysfs. The reference is readable only for the root user (see *--output* +REF) and it is restricted to 64 bytes.
79
80 *--sizelimit* _size_::
81 The data end is set to no more than _size_ bytes after the data start. The _size_ may be followed by the multiplicative suffixes; see above.
82
83 *-b*, *--sector-size* _size_::
84 Set the logical sector size of the loop device in bytes (since Linux 4.14). The option may be used when creating a new loop device as well as a stand-alone command to modify sector size of the already existing loop device.
85
86 *-c*, *--set-capacity* _loopdev_::
87 Force the loop driver to reread the size of the file associated with the specified loop device.
88
89 *-P*, *--partscan*::
90 Force the kernel to scan the partition table on a newly created loop device. Note that the partition table parsing depends on sector sizes. The default is sector size is 512 bytes, otherwise you need to use the option *--sector-size* together with *--partscan*.
91
92 *-r*, *--read-only*::
93 Set up a read-only loop device.
94
95 *--direct-io*[**=on**|*off*]::
96 Enable or disable direct I/O for the backing file. The optional argument can be either *on* or *off*. If the optional argument is omitted, it defaults to *on*.
97
98 *-v*, *--verbose*::
99 Verbose mode.
100
101 *-l*, *--list*::
102 If a loop device or the *-a* option is specified, print the default columns for either the specified loop device or all loop devices; the default is to print info about all devices. See also *--output*, *--noheadings*, *--raw*, and *--json*.
103
104 *-O*, *--output* _column_[,_column_]...::
105 Specify the columns that are to be printed for the *--list* output. Use *--help* to get a list of all supported columns.
106
107 *--output-all*::
108 Output all available columns.
109
110 *-n*, *--noheadings*::
111 Don't print headings for *--list* output format.
112
113 *--raw*::
114 Use the raw *--list* output format.
115
116 *-J*, *--json*::
117 Use JSON format for *--list* output.
118
119 == ENCRYPTION
120
121 *Cryptoloop is no longer supported in favor of dm-crypt.* For more details see *cryptsetup*(8).
122
123 == EXIT STATUS
124
125 *losetup* returns 0 on success, nonzero on failure. When *losetup* displays the status of a loop device, it returns 1 if the device is not configured and 2 if an error occurred which prevented determining the status of the device.
126
127 == NOTES
128
129 Since version 2.37 *losetup* uses *LOOP_CONFIGURE* ioctl to setup a new loop device by one ioctl call. The old versions use *LOOP_SET_FD* and *LOOP_SET_STATUS64* ioctls to do the same.
130
131 == ENVIRONMENT
132
133 *LOOPDEV_DEBUG*=all::
134 enables debug output.
135
136 == FILES
137
138 _/dev/loop[0..N]_::
139 loop block devices
140
141 _/dev/loop-control_::
142 loop control device
143
144 == EXAMPLE
145
146 The following commands can be used as an example of using the loop device.
147
148 # dd if=/dev/zero of=~/file.img bs=1024k count=10
149 # losetup --find --show ~/file.img
150 /dev/loop0
151 # mkfs -t ext2 /dev/loop0
152 # mount /dev/loop0 /mnt
153 ...
154 # umount /dev/loop0
155 # losetup --detach /dev/loop0
156
157 == AUTHORS
158
159 mailto:kzak@redhat.com[Karel Zak], based on the original version from mailto:tytso@athena.mit.edu[Theodore Ts'o].
160
161 include::man-common/bugreports.adoc[]
162
163 include::man-common/footer.adoc[]
164
165 ifdef::translation[]
166 include::man-common/translation.adoc[]
167 endif::[]