---
obj: application
repo: git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git
---

# losetup
set up and control [loop devices](../../../linux/Loop%20Device.md)

## Usage
Get info:
```shell
losetup [loopdev]
losetup -l [-a]
losetup -j file
```

Attach a loop device:
```shell
losetup -fP file
```

Detach a loop device:
```shell
losetup -d loopdev ...
```

Detach all associated loop devices:
```shell
losetup -D
```

## Options
| Option                            | Description                                                                                                                                                                                                                                                       |
| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-a, --all`                       | Show the status of all loop devices                                                                                                                                                                                                                               |
| `-d, --detach loopdev...`         | Detach the file or device associated with the specified loop device(s)                                                                                                                                                                                            |
| `-D, --detach-all`                | Detach all associated loop devices                                                                                                                                                                                                                                |
| `-f, --find [file]`               | Find the first unused loop device. If a file argument is present, use the found device as loop device. Otherwise, just print its name                                                                                                                             |
| `--show`                          | Display the name of the assigned loop device if the `-f` option and a file argument are present                                                                                                                                                                   |
| `-L, --nooverlap`                 | 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` |
| `-j, --associated file`           | Show the status of all loop devices associated with the given file                                                                                                                                                                                                |
| `-P, --partscan`                  | Force the kernel to scan the partition table on a newly created loop device. Note that the partition table parsing depends on sector sizes                                                                                                                        |
| `-r, --read-only`                 | Set up a read-only loop device                                                                                                                                                                                                                                    |
| `-v, --verbose`                   | Verbose mode                                                                                                                                                                                                                                                      |
| `-l, --list`                      | If a loop device or the -a option is specified, print the default columns for either the specified loop device or all loop devices                                                                                                                                |
| `-O, --output column[,column]...` | Specify the columns that are to be printed for the `--list` output                                                                                                                                                                                                | 
| `-J, --json`                      | Use JSON format for `--list` output                                                                                                                                                                                                                               |

## Output Columns
| Output       | Description                            | 
| ------------ | -------------------------------------- |
| NAME         | loop device name                       |
| AUTOCLEAR    | autoclear flag set                     |
| BACK-FILE    | device backing file                    |
| BACK-INO     | backing file inode number              |
| BACK-MAJ:MIN | backing file major:minor device number |
| MAJ:MIN      | loop device major:minor number         |
| OFFSET       | offset from the beginning              |
| PARTSCAN     | partscan flag set                      |
| RO           | read-only device                       |
| SIZELIMIT    | size limit of the file in bytes        |
| DIO          | access backing file with direct-io     |
| LOG-SEC      | logical sector size in bytes           |