Show Storage Luns Allocated on Linux

When you are working in a storage environment, it is often desirable to add, remove or re-size storage devices while the operating system is running and without rebooting. But instead of doing theses operations, you can most need to identify/show the actual allocated Luns on the server before doing other storage operation on the server.

What is a LUN

A LUN is a Logical Unit Number. It can be used to refer to an entire physical disk, or a subset of a larger physical disk or disk volume. The physical disk or disk volume could be an entire single disk drive, a partition (subset) of a single disk drive, or disk volume from a RAID controller comprising multiple disk drives aggregated together for larger capacity and redundancy.

1) Check attached LUN or SAN disk in Linux

To check the attached LUN from a storage device in Linux, we can use the /proc/scsi/scsi file content but it will give you some information and you can not be able to distinguish physical attached drive to LUN. Display the content as below as below

# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi3 Channel: 00 Id: 00 Lun: 00
  Vendor: LIO-ORG  Model: block            Rev: 4.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi3 Channel: 00 Id: 00 Lun: 01
  Vendor: LIO-ORG  Model: block2           Rev: 4.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi3 Channel: 00 Id: 00 Lun: 02
  Vendor: LIO-ORG  Model: rhelblock        Rev: 4.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 05

Normally Luns would be showing as Host: scsi3 Channel: 00 Id: 00 Lun: 00  and you can also use iscsiadm (only used when storage using iscsi target) command to get information about attached lun.

# iscsiadm -m session -P 3
iSCSI Transport Class version 2.0-870
version 6.2.0.873-35
Target: iqn.2017-06.com.linoxide:target1 (non-flash)
	Current Portal: 172.16.20.139:3260,1
	Persistent Portal: 172.16.20.139:3260,1
		**********
		Interface:
		**********
............
............
************************
		Attached SCSI devices:
		************************
		Host Number: 3	State: running
		scsi3 Channel 00 Id 0 Lun: 0
			Attached scsi disk sdd		State: running
		scsi3 Channel 00 Id 0 Lun: 1
			Attached scsi disk sde		State: running
		scsi3 Channel 00 Id 0 Lun: 2
			Attached scsi disk sdf		State: running

You can also check below path for lun information.

# ls /dev/disk/by-path/
ip-172.16.20.139:3260-iscsi-iqn.2017-06.com.linoxide:target1-lun-0
ip-172.16.20.139:3260-iscsi-iqn.2017-06.com.linoxide:target1-lun-1
ip-172.16.20.139:3260-iscsi-iqn.2017-06.com.linoxide:target1-lun-2
pci-0000:00:07.1-ata-2.0
pci-0000:00:10.0-scsi-0:0:0:0
pci-0000:00:10.0-scsi-0:0:0:0-part1
pci-0000:00:10.0-scsi-0:0:0:0-part2
pci-0000:00:10.0-scsi-0:0:1:0
pci-0000:00:10.0-scsi-0:0:2:0

2) Using multipath command

As per best practice, multipathing should be configured, for redundancy. Multipathing is a technique that lets you use more than one physical path that transfers data between the host and an external storage device. These I/O paths are physical SAN connections that can include separate cables, switches, and controllers.

Redhat default multipathing service is multipathd daemon. Below commands are from a server that has a multipathing enabled using multipathd daemon.

# multipath -v4 -ll
Jun 21 04:58:40 | loading /lib64/multipath/libcheckdirectio.so checker
Jun 21 04:58:40 | loading /lib64/multipath/libprioconst.so prioritizer
Jun 21 04:58:40 | Discover device /sys/devices/pci0000:00/0000:00:07.1/ata2/host2/target2:0:0/2:0:0:0/block/sr0
Jun 21 04:58:40 | sr0: device node name blacklisted
Jun 21 04:58:40 | Discover device /sys/devices/pci0000:00/0000:00:10.0/host0/target0:0:0/0:0:0:0/block/sda
................................
................................
===== paths list =====
uuid hcil    dev dev_t pri dm_st chk_st vend/prod/rev             dev_st 
     0:0:0:0 sda 8:0   -1  undef ready  VMware, ,VMware Virtual S running
     0:0:1:0 sdb 8:16  -1  undef ready  VMware, ,VMware Virtual S running
     0:0:2:0 sdc 8:32  -1  undef ready  VMware, ,VMware Virtual S running
     3:0:0:0 sdd 8:48  -1  undef ready  LIO-ORG ,block            running
     3:0:0:1 sde 8:64  -1  undef ready  LIO-ORG ,block2           running
     3:0:0:2 sdf 8:80  -1  undef ready  LIO-ORG ,rhelblock        running
Jun 21 04:58:40 | directio checker refcount 6
Jun 21 04:58:40 | directio checker refcount 5
Jun 21 04:58:40 | directio checker refcount 4
Jun 21 04:58:40 | directio checker refcount 3
Jun 21 04:58:40 | directio checker refcount 2
Jun 21 04:58:40 | directio checker refcount 1
Jun 21 04:58:40 | unloading const prioritizer
Jun 21 04:58:40 | unloading directio checker

If you do not have a vendor based software to detect your SAN disk (LUNs) or instead you can use multipath tool which is an open source utility. Then you can see the device name running through multipath.

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.

1 Comment

  1. or you could use the inq utility available from emc, much easier to read and supports more than EMC arrays