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