How to Find LUN Mapped to Controller in Linux
Finding which Logical Unit Number (LUN) is mapped to a controller in Linux can seem tricky if you’re new to storage management. But once you understand the basics, it becomes straightforward. Whether you’re managing SAN storage or troubleshooting connectivity, knowing how to identify LUN mappings helps you control your storage environment better.
In this article, I’ll guide you through practical steps to find LUNs mapped to controllers in Linux. We’ll cover commands, tools, and tips that work across different Linux distributions. By the end, you’ll be able to confidently check your storage mappings and manage your devices efficiently.
Understanding LUNs and Controllers in Linux Storage
Before diving into commands, it’s important to understand what LUNs and controllers are in the context of Linux storage.
- LUN (Logical Unit Number): This is a unique identifier used on a SCSI bus to distinguish between devices. In SAN environments, a LUN represents a logical disk or volume presented by the storage array.
- Controller: This refers to the hardware or software component managing the connection between the host (your Linux system) and the storage devices. Controllers handle communication and data transfer.
In Linux, storage devices connected via Fibre Channel, iSCSI, or SAS often show up as SCSI devices. The system assigns device names like /dev/sda, /dev/sdb, etc., but these don’t directly tell you which controller or LUN they belong to. That’s why you need specific commands to map these relationships.
Using lsscsi to List LUNs and Controllers
One of the easiest tools to start with is lsscsi. It lists all SCSI devices, showing their host, channel, target, and LUN numbers.
To install lsscsi, run:
sudo apt-get install lsscsi # Debian/Ubuntu
sudo yum install lsscsi # RHEL/CentOS
Then, run:
lsscsi -g
This command outputs a list like:
[0:0:0:0] disk Vendor Model Rev /dev/sda /dev/sg0
[1:0:1:1] disk Vendor Model Rev /dev/sdb /dev/sg1
Here, the numbers in brackets represent [Host:Channel:Target:LUN]. The Host corresponds to the controller, and the last number is the LUN.
- Host: The SCSI host adapter number (controller).
- Channel: Usually 0 for most setups.
- Target: The target ID on the SCSI bus.
- LUN: The logical unit number.
By checking the Host number, you can identify which controller manages the device. For example, Host 0 might be controller 0, Host 1 controller 1, and so on.
Exploring /sys Filesystem for Detailed Mapping
Linux exposes detailed device information in the /sys filesystem. You can find LUN and controller mappings here.
Navigate to:
cd /sys/class/scsi_device/
Each directory here is named like host:channel:target:lun. For example:
0:0:0:0
1:0:1:1
You can check the controller (host) and LUN by listing these directories.
To get more info about a specific device, use:
cat /sys/class/scsi_device/0:0:0:0/device/block/sda/device/scsi_level
Or to find the device name:
ls -l /sys/class/scsi_device/0:0:0:0/device/block/
This shows the block device (e.g., sda) associated with that LUN.
Using multipath to Identify LUNs and Controllers
If your system uses multipath I/O (common in SAN environments), the multipath command helps map LUNs to controllers.
Run:
sudo multipath -ll
This command lists multipath devices with their WWIDs, paths, and associated controllers. The output looks like:
3600508b400105e210000900000490000 dm-0 IBM,2810XIV
size=100G features='1 queue_if_no_path' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| `- 2:0:0:1 sdb 8:16 active ready running
`-+- policy='round-robin 0' prio=1 status=enabled
`- 3:0:0:1 sdc 8:32 active ready running
Here, the numbers like 2:0:0:1 represent [Host:Channel:Target:LUN]. You can see which hosts (controllers) manage each path to the LUN.
Using sg_map and sg_inq for SCSI Device Details
The sg3_utils package provides tools like sg_map and sg_inq to get detailed SCSI device info.
Install it with:
sudo apt-get install sg3-utils
Run:
sg_map -i
This lists SCSI devices with their device names and LUNs.
To get detailed inquiry data for a device:
sg_inq /dev/sgX
Replace /dev/sgX with the generic SCSI device from sg_map. This shows vendor, product, and LUN info.
Checking iSCSI Sessions for LUN Mapping
If you use iSCSI storage, you can check which LUNs are mapped to your controllers by inspecting iSCSI sessions.
Run:
iscsiadm -m session -P 3
This command shows detailed session info, including target names, LUNs, and device nodes.
Look for sections like:
Attached SCSI devices:
Host Number: 3 State: running
scsi3 Channel 00 Id 00 Lun: 0
Attached scsi disk sdb State: running
This tells you which LUNs are attached to which iSCSI session and host (controller).
Using udevadm to Trace Device Paths
udevadm helps trace device attributes and paths, which can help identify controller and LUN mappings.
Run:
udevadm info --query=all --name=/dev/sdb
Look for attributes like:
ID_SCSI_HOSTID_SCSI_TARGETID_SCSI_LUN
These values correspond to the controller and LUN for the device.
Summary Table of Commands and Their Uses
| Command | Purpose | Notes |
lsscsi -g | List SCSI devices with Host and LUN info | Quick overview of devices |
multipath -ll | Show multipath devices and paths | Useful in SAN with multipath |
sg_map -i | Map SCSI generic devices to block devices | Detailed SCSI device info |
iscsiadm -m session -P 3 | Show iSCSI session and LUN info | For iSCSI storage environments |
udevadm info --query=all --name=/dev/sdX | Get device attributes including LUN | Trace device to controller mapping |
Tips for Managing LUNs and Controllers in Linux
- Always check if multipath is enabled, as it affects how devices appear.
- Use
dmesg | grep sdafter connecting storage to see kernel messages about devices. - Keep your storage drivers and multipath tools updated for best compatibility.
- Document your storage mappings for easier troubleshooting.
- Use vendor-specific tools if available, as they sometimes provide clearer mapping info.
Conclusion
Finding which LUN is mapped to which controller in Linux is essential for managing your storage effectively. By using tools like lsscsi, multipath, and iscsiadm, you can quickly identify device mappings and troubleshoot issues. Exploring the /sys filesystem and using udevadm also gives you detailed insights into device attributes.
With these commands and tips, you’ll be able to navigate your Linux storage environment confidently. Whether you’re working with Fibre Channel, iSCSI, or SAS devices, understanding LUN-to-controller mappings helps you maintain a stable and efficient system.
FAQs
How do I install lsscsi on my Linux system?
You can install lsscsi using your package manager. For Debian/Ubuntu, run sudo apt-get install lsscsi. For RHEL/CentOS, use sudo yum install lsscsi. It’s a lightweight tool for listing SCSI devices.
What does the [Host:Channel:Target:LUN] format mean?
This format identifies SCSI devices. Host is the controller number, Channel is usually 0, Target is the device ID on the bus, and LUN is the logical unit number representing the storage volume.
Can I find LUN mappings for iSCSI devices?
Yes. Use the command iscsiadm -m session -P 3 to see detailed iSCSI session info, including LUNs mapped to your Linux host.
What is the role of multipath in LUN mapping?
multipath manages multiple paths to the same storage device. It shows which controllers (hosts) and paths are active for each LUN, helping with redundancy and performance.
How can I check which controller manages /dev/sdb?
Run udevadm info --query=all --name=/dev/sdb and look for ID_SCSI_HOST. This value indicates the controller (host) number managing that device.
