1LOSETUP(8)                   System Administration                  LOSETUP(8)
2
3
4

NAME

6       losetup - set up and control loop devices
7

SYNOPSIS

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]
28                    [-Pr] [--show] -f|loopdev file
29
30       Resize a loop device:
31
32            losetup -c loopdev
33

DESCRIPTION

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 cor‐
38       responding 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, cor‐
46       ruption 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 recom‐
52       mended to use for example flock(1) to avoid a collision in heavily par‐
53       allel use cases.
54
55

OPTIONS

57       The  size  and  offset  arguments may be followed by the multiplicative
58       suffixes KiB (=1024), MiB (=1024*1024), and so on for  GiB,  TiB,  PiB,
59       EiB,  ZiB and YiB (the "iB" is optional, e.g., "K" has the same meaning
60       as "KiB") or the suffixes KB (=1000), MB (=1000*1000), and  so  on  for
61       GB, TB, PB, EB, ZB and YB.
62
63
64       -a, --all
65              Show the status of all loop devices.  Note that not all informa‐
66              tion is accessible for non-root users.  See  also  --list.   The
67              old output format (as printed without --list) is deprecated.
68
69       -d, --detach loopdev...
70              Detach  the  file  or  device associated with the specified loop
71              device(s). Note that since Linux v3.7 kernel uses  "lazy  device
72              destruction".   The detach operation does not return EBUSY error
73              anymore if device is actively used by system, but it  is  marked
74              by autoclear flag and destroyed later.
75
76       -D, --detach-all
77              Detach all associated loop devices.
78
79       -f, --find [file]
80              Find  the  first  unused  loop  device.   If  a file argument is
81              present, use the found device as loop device.   Otherwise,  just
82              print its name.
83
84       --show Display  the  name  of the assigned loop device if the -f option
85              and a file argument are present.
86
87       -L, --nooverlap
88              Check for conflicts between loop devices to avoid situation when
89              the  same  backing  file is shared between more loop devices. If
90              the file is already used  by  another  device  then  re-use  the
91              device  rather  than a new one. The option makes sense only with
92              --find.
93
94       -j, --associated file [-o offset]
95              Show the status of all loop devices associated  with  the  given
96              file.
97
98       -o, --offset offset
99              The  data start is moved offset bytes into the specified file or
100              device.  The offset may be followed by the  multiplicative  suf‐
101              fixes; see above.
102
103       --sizelimit size
104              The  data  end  is set to no more than size bytes after the data
105              start.  The size may be followed by the multiplicative suffixes;
106              see above.
107
108       -b, --sector-size size
109              Set  the  logical sector size of the loop device in bytes (since
110              Linux 4.14). The option may be  used  when  create  a  new  loop
111              device  as  well as stand-alone command to modify sector size of
112              the already existing loop device.
113
114       -c, --set-capacity loopdev
115              Force the loop driver to reread the size of the file  associated
116              with the specified loop device.
117
118       -P, --partscan
119              Force  the kernel to scan the partition table on a newly created
120              loop device.  Note that the partition table parsing  depends  on
121              sector  sizes.   The default is sector size is 512 bytes, other‐
122              wise you need to use  the  option  --sector-size  together  with
123              --partscan.
124
125       -r, --read-only
126              Set up a read-only loop device.
127
128       --direct-io[=on|off]
129              Enable or disable direct I/O for the backing file.  The optional
130              argument can be either on or off.  If the argument  is  omitted,
131              it defaults to off.
132
133       -v, --verbose
134              Verbose mode.
135
136       -l, --list
137              If  a  loop  device  or  the  -a  option is specified, print the
138              default columns for either the specified loop device or all loop
139              devices;  the  default  is to print info about all devices.  See
140              also --output, --noheadings, --raw, and --json.
141
142       -O, --output column[,column]...
143              Specify the columns that are to be printed for the  --list  out‐
144              put.  Use --help to get a list of all supported columns.
145
146       --output-all
147              Output all available columns.
148
149       -n, --noheadings
150              Don't print headings for --list output format.
151
152       --raw  Use the raw --list output format.
153
154       -J, --json
155              Use JSON format for --list output.
156
157       -V, --version
158              Display version information and exit.
159
160       -h, --help
161              Display help text and exit.
162
163

ENCRYPTION

165       Cryptoloop  is  no  longer  supported  in  favor of dm-crypt.  For more
166       details see cryptsetup(8).
167
168

EXIT STATUS

170       losetup returns 0 on success, nonzero on failure.   When  losetup  dis‐
171       plays  the  status  of a loop device, it returns 1 if the device is not
172       configured and 2 if an error occurred which prevented  determining  the
173       status of the device.
174
175

ENVIRONMENT

177       LOOPDEV_DEBUG=all
178              enables debug output.
179
180

FILES

182       /dev/loop[0..N]
183              loop block devices
184
185       /dev/loop-control
186              loop control device
187

EXAMPLE

189       The  following  commands  can  be  used as an example of using the loop
190       device.
191
192              # dd if=/dev/zero of=~/file.img bs=1024k count=10
193              # losetup --find --show ~/file.img
194              /dev/loop0
195              # mkfs -t ext2 /dev/loop0
196              # mount /dev/loop0 /mnt
197               ...
198              # umount /dev/loop0
199              # losetup --detach /dev/loop0
200

AUTHORS

202       Karel  Zak  <kzak@redhat.com>,  based  on  the  original  version  from
203       Theodore Ts'o <tytso@athena.mit.edu>
204

AVAILABILITY

206       The  losetup command is part of the util-linux package and is available
207       from https://www.kernel.org/pub/linux/utils/util-linux/.
208
209
210
211util-linux                       November 2015                      LOSETUP(8)
Impressum