11

Out of curiosity, I would like to know is there a way to find out the source of mounted partition?

For example, output of df -h is:

/dev/loop1 3M 3M 0 100% /media/loop

From this output, I know a loop device of 3M is mounted at /media/loop, but I have no clue to determine the exact location of the /dev/loop1 device.

root@SHW:~# mount -o loop /home/SHW/Downloads/TinyCore-current.iso
/mnt/loop mount: block device /home/SHW/Downloads/TinyCore-current.iso is write-protected, mounting read-only
root@SHW:~# tail -n1 /proc/mounts
/dev/loop1 /mnt/loop iso9660 ro,relatime 0 0

How do I find out the absolute path of /dev/loop1 f I don't know who mounted those partitions? (In this case the path is /home/SHW/Downloads/TinyCore-current.iso.)

3 Answers 3

13

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.

1
  • One can also just use losetup /dev/(target).
    – neverMind9
    Commented Mar 8, 2019 at 17:08
3

To get the backing file path use:

cat /sys/block/loop1/loop/backing_file
1
  • This is a great option since losetup may not always be available Commented Sep 6, 2020 at 15:51
-2

I have no clue to determine the exact location of /dev/loop1 device.

What do you mean by the exact location of /dev/loop1 device? /dev/loop* where * is a number are loopback (virtual) devices, which are used to mount filesystems that are not located on other block devices, such as hard disks. You can enumerate them and see where they are mounted, using the mount command and you can setup a new one using the losetup command.

If you want to know to which physical device a /dev/ node is attached, then there are ways to do that. You can use udevadm to query udev. On my system, the following commands give more information about the sda disk:

$ udevadm info --query=path --name=sda
/devices/pci0000:00/0000:00:1f.2/ata4/host3/target3:0:0/3:0:0:0/block/sda
$ udevadm info --query=symlink --name=sda
disk/by-id/ata-ST3500418AS_6VMD78AY disk/by-id/wwn-0x5000c500224ac74f

In addition to these, you can use lspci to get more information about where the device is physically attached. On my system, /dev/sda is attached to the sata controller:

$ lspci
[snip]
00:1f.2 SATA controller: Intel Corporation 7 Series/C210 Series Chipset Family 6-port SATA Controller [AHCI mode] (rev 04)
[snip]
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .