losetup

set up and control loop devices

Usage

Get info:

losetup [loopdev]
losetup -l [-a]
losetup -j file

Attach a loop device:

losetup -fP file

Detach a loop device:

losetup -d loopdev ...

Detach all associated loop devices:

losetup -D

Options

OptionDescription
-a, --allShow the status of all loop devices
-d, --detach loopdev...Detach the file or device associated with the specified loop device(s)
-D, --detach-allDetach 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
--showDisplay the name of the assigned loop device if the -f option and a file argument are present
-L, --nooverlapCheck 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 fileShow the status of all loop devices associated with the given file
-P, --partscanForce 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-onlySet up a read-only loop device
-v, --verboseVerbose mode
-l, --listIf 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, --jsonUse JSON format for --list output

Output Columns

OutputDescription
NAMEloop device name
AUTOCLEARautoclear flag set
BACK-FILEdevice backing file
BACK-INObacking file inode number
BACK-MAJ:MINbacking file major:minor device number
MAJ:MINloop device major:minor number
OFFSEToffset from the beginning
PARTSCANpartscan flag set
ROread-only device
SIZELIMITsize limit of the file in bytes
DIOaccess backing file with direct-io
LOG-SEClogical sector size in bytes