How to Mapping Linux Block Devices to Storage LUNs

In some cases, you may need to find a block device mapped against a logical unit number (LUNs) for filesystem (FS) expansion or disaster recovery (DR) activity.

Also, this information is required if you want to work with the storage team to troubleshoot or fix a high latency or disk error on a specific block device.

Refer the following article to map ASM disks against storage LUNs.

This information can be found at the following location. However, you will not find mapping details for multipath LUNs because it shows the name of the multipath device instead of the block devices.

ls -ltrh /dev/disk/by-id

Therefore, since there is no direct command to find this information in Linux, this can be achieved by writing a small shell script, which we will discuss further in this article.

In this article, we will show you how Disks mapped to SAN LUNs in Linux.

Shell Script to Map block device against to Storage LUN

This shell script helps you to identify which SAN disk LUN id is assigned to which OS Underlying disk on Linux.

In this shell script we are using the lsblk command and smartctl command to achieve the results.

vi block_device_mapping_with_LUN.sh

#!/bin/bash
echo "Device_Name" "|" "LUN_ID"
echo "---------------------"
for lunmap in `lsblk | grep disk | grep ^s | awk '{print $1}'`
do echo -e "$lunmap \t--> $(smartctl -a /dev/$lunmap | grep "Logical Unit id" | awk -F":" '{print $2}')"
done

Set an executable permission to ‘block_device_mapping_with_LUN.sh’ file.

chmod +x block_device_mapping_with_LUN.sh

Finally run the script to view the results.

sh block_device_mapping_with_LUN.sh

Device_Name | LUN_ID
---------------------
sda --> 
sdb --> 3600d0230000000000e1140463955737c
sdc --> 3600d0230000000000e114046395577cd
sdd --> 3600d0230000000000e11404639558cc5

If you want to run the script on a single line instead of the steps above, use the below one. This one liner script will map Linux system disks against storage LUNs as shown below.

echo "Device_Name" "|" "LUN_ID"; echo "---------------------"; for lunmap in `lsblk | grep disk | grep ^s | awk '{print $1}'`; do echo -e "$lunmap \t--> $(smartctl -a /dev/$lunmap | grep "Logical Unit id" | awk -F":" '{print $2}')"; done

Device_Name | LUN_ID
---------------------
sda --> 
sdb --> 3600d0230000000000e1140463955737c
sdc --> 3600d0230000000000e114046395577cd
sdd --> 3600d0230000000000e11404639558cc5

Wrapping Up

In this tutorial, we’ve shown you to identify/check/match LUN presented from SAN with underlying OS disk on Linux.

If you have any questions or feedback, feel free to comment below.

About Vinoth Kumar

Vinoth Kumar has 3.5+ years of experience in Linux server administration & RHEL certified professional. He is currently working as a Senior L2 Linux Server administrator.

View all posts by Vinoth Kumar

2 Comments on “How to Mapping Linux Block Devices to Storage LUNs”

  1. Hi,
    change lunmpa to lunmap from following commands

    do echo “$lunmap \t–> $(smartctl -a /dev/$lunmpa | grep “Logical Unit id” | awk -F”:” ‘{print $2}’)”
    ————-

Leave a Reply to Jalal Cancel reply

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