How to map LUN, Disk, LVM and FileSystem in Linux

There are situations where you want to map storage LUN (Logical Unit Number), Block Device, LVM (LV & VG names) and File System (FS) information for FS expansion or Disaster Recovery (DR) operation.

This is a routine activity for most Linux administrators, and we usually use some script that displays the block device mapping against SAN LUN, and then we will manually add the LVM and File System information to complete the operation.

Going forward, you don’t need to manually intervene on this activity because these information can be mapped by shell script as shown below.

Refer the following articles similar to this:

Shell Script to map LUN, Disk, LVM and FileSystem in Linux

This small shell script helps you to identify which SAN disks are mapped to which Block devices, LV, VG and Filesystem on Linux.

Make a Note: We have excluded ‘sda’ disk because this is Operating System (OS) disk, which has multiple partitions.

vi block_device_mapping_with_LUN_FS_LVM.sh

#!/bin/bash
for bdevice in `lsblk | grep disk | awk '{print $1}' | grep -v 'sda'`
do
for mpoint in `lsblk /dev/$bdevice | grep lvm | awk '{print $NF}'`
do
LVM_INFO=`lvs -o +devices | grep -i $bdevice | awk '{print $1,$2}'`
LUN_ID=`lsscsi --scsi | grep $bdevice | awk '{print $NF}'`
echo "$bdevice --> $mpoint --> $LVM_INFO --> $LUN_ID"
done
done

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

chmod +x block_device_mapping_with_LUN_FS_LVM.sh

Finally run the script to view the results.

sh block_device_mapping_with_LUN_FS_LVM.sh
Mapping FS, LVM, Disk against Storage LUN.

Make a Note: In the above output, device sdb won’t show any LUN info because it’s a virtual disk added from VMWare end, which doesn’t have any LUN. Other 3 disks are mapped from Storage which is why can see LUN info.

If you would like to run the above script on the fly, use the following one liner script.

for bdevice in `lsblk | grep disk | awk '{print $1}' | grep -v 'sda'`; do for mpoint in `lsblk /dev/$bdevice | grep lvm | awk '{print $NF}'`; do LVM_INFO=`lvs -o +devices | grep -i $bdevice | awk '{print $1,$2}'`; LUN_ID=`lsscsi --scsi | grep $bdevice | awk '{print $NF}'`; echo "$bdevice --> $mpoint --> $LVM_INFO --> $LUN_ID"; done; done

sdb --> [SWAP] --> swap2lv swapvg --> -
sdc --> /appserver --> appserver_lv appserver_vg --> 360000670000415600477312020662021
sdd --> /data --> data_lv data_vg --> 360000670000415600477312020662022
sde --> /backup --> backup_lv backup_vg --> 360000670000415600477312020662023

Wrapping Up

In this tutorial, we’ve shown you how to check LUN presented from SAN with underlying OS disk, LV Name, VG Name and associated Filesystem on Linux.

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

One Comment on “How to map LUN, Disk, LVM and FileSystem in Linux”

Leave a Reply

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