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?
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?
It's an ancient topic, I know, but this answer may hopefully be useful for future generations of script programmers.
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)
(...)
Display a single device (let's say one's interested in 02-xorg.sb
) with
$ losetup -j /mnt/live/memory/data/slax/02-xorg.sb
/dev/loop1: [2065]:26 (/mnt/live/memory/data/slax/02-xorg.sb)
Now, the device name /dev/loop1
is in the first field/column (if we separate rows by spaces). To extract the device name, 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}'
/dev/loop1
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.