How to find which images belong to which /dev/loop?
losetup
(the command normally used to set them up) will tell you:
$ /sbin/losetup --list
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE
/dev/loop0 0 0 0 0 /var/tmp/jigdo/debian-7.6.0-amd64-CD-1.iso
Note that with older versions you may hat to use use -a
instead of --list
, and this outputs in a different and now deprecated format.
The information comes from /sys
:
$ cat /sys/class/block/loop0/loop/backing_file
/var/tmp/jigdo/debian-7.6.0-amd64-CD-1.iso
Another, possibly more portable, option is to get it from udisks:
$ udisksctl info -b /dev/loop0
/org/freedesktop/UDisks2/block_devices/loop0:
⋮
org.freedesktop.UDisks2.Loop:
Autoclear: false
BackingFile: /var/tmp/jigdo/debian-7.6.0-amd64-CD-1.iso
SetupByUID: 1000
⋮
losetup
will also happily remove them for you, using the -d
option. That just requires the loop device as a parameter; it doesn't care about the backing file/device.