大网数据广告活动
服务器运维问答

Find out which loop device is behind a dev mapper block device

· 52CE 我爱测

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 …

问题原文

原帖链接 · miluz · CC BY-SA 4.0

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?

社区高分解答

原帖链接 · cieply · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-08-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。