I'm using cryptsetup with loopback devices. I'm looking for a way, given a device mapping, to identify which loopback device is used by this device.

i.e. get /dev/loop1 as a result of an operation on /dev/mapper/some_mapping

How can this be done?


  • Have you already tried losetup -a? – ott-- Aug 12 '13 at 11:05
  • losetup -a shows all loop devices. The purpose of this is an unmount script that by the mount point name unmaps the dev mapper device, and frees the loopback device as well. There may be several mounts at a given time, therefore there's a need to know which loop device is behind which dev mapper device. – miluz Aug 12 '13 at 12:25
  • what about getting the major/minor numbers from dmsetup ls, and then just checking in the /dev/ tree for the loopdevice with corresponding numbers? – Petter H Aug 12 '13 at 12:27
  • dmsetup ls prints the major,minor of the device hosting the image files, not the loop devices major,minor. – miluz Aug 12 '13 at 13:16
  • Isn't your mount point name not the same as the /dev/mapper and the image name? My script works like this, I call it crim m im1 to mount or crim u im1 to umount. It even checks if the image is Luks. – ott-- Aug 12 '13 at 15:39

it's ancient topic, I know, but answer may hopefuly be useful for future generation of script programmers

I found at least some answer to referred question being in travel:

all devices can be displayed with

$ losetup -a

/dev/loop0: [2065]:25 (/mnt/live/memory/data/slax/01-core.sb)
/dev/loop1: [2065]:26 (/mnt/live/memory/data/slax/02-xorg.sb)
/dev/loop2: [2065]:27 (/mnt/live/memory/data/slax/03-kdeps.sb)

single one with (lets say one's intrested in `02-xorg.sb'

$ losetup -j /mnt/live/memory/data/slax/02-xorg.sb

/dev/loop1: [2065]:26 (/mnt/live/memory/data/slax/02-xorg.sb)

now, as can be seen device is in first field/column (if dividing row with spaces), so to extract it awk can be used, only remember to remove ':' with substitute

$ losetup -j /mnt/live/memory/data/slax/02-xorg.sb | awk '{sub(/:/,"",$1); print $1}'


~~ cieply


cryptsetup status some_mapping prints out a device entry, so I think that will work for your case (not sure about the more general /dev/mapper question when not using cryptsetup).


losetup shows a device number when used as root, or when you are in group disk (an ioctl is needed on the loop device).

The numbers you see in one of the other answers (ie. 2065) can be decomposed by dividing and modding by 256, ie. 2065 / 256 = 8, which is a scsi device, and 2065 % 256 = 17, which is /dev/sdb1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.