Source path of loop-device
Use losetup
's --list
option:
$ losetup --list /dev/loop0
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE
/dev/loop0 0 0 0 0 /tmp/backing-file
If you only want the file, use the -O
option to pick the column:
$ losetup --list --noheadings -O BACK-FILE /dev/loop0
/tmp/backing-file
This option is part of recent versions of util-linux
. Earlier versions support only the -a
option, which lists all active devices in a harder-to-process format:
$ losetup -a
/dev/loop0: []: (/tmp/backing-file)
Either way, it's not overly onerous to process however you want.