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

OPTIONS

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

ENCRYPTION

151       Cryptoloop is no longer supported  in  favor  of  dm-crypt.   For  more
152       details see cryptsetup(8).
153
154

RETURN VALUE

156       losetup  returns  0  on success, nonzero on failure.  When losetup dis‐
157       plays the status of a loop device, it returns 1 if the  device  is  not
158       configured  and  2 if an error occurred which prevented determining the
159       status of the device.
160
161

FILES

163       /dev/loop[0..N]
164              loop block devices
165
166       /dev/loop-control
167              loop control device
168
169

EXAMPLE

171       The following commands can be used as an  example  of  using  the  loop
172       device.
173
174              # dd if=/dev/zero of=~/file.img bs=1024k count=10
175              # losetup --find --show ~/file.img
176              /dev/loop0
177              # mkfs -t ext2 /dev/loop0
178              # mount /dev/loop0 /mnt
179               ...
180              # umount /dev/loop0
181              # losetup --detach /dev/loop0
182

ENVIRONMENT

184       LOOPDEV_DEBUG=all
185              enables debug output.
186

AUTHORS

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

AVAILABILITY

192       The losetup command is part of the util-linux package and is  available
193       from https://www.kernel.org/pub/linux/utils/util-linux/.
194
195
196
197util-linux                       November 2015                      LOSETUP(8)
Impressum