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