A handy script to uniquely identify disks/LUNS underlying a Filesystem. This can be helpful in identifying details needed to identify the LUN ID, WWN, WWID, Vendor, File systems mounted on it etc, for a disk/LUN presented from SAN or Local.

udevadm is a Utility native to Linux, which can be used to query udev database. This can be used to query details about block devices presented from SAN, to list useful information such as LUN ID, Vendor, WWN etc.

The below script makes your life easy and identifies all **Mounted** file systems, finds its underlying disk details, runs a udevadm query on the same and prints it in an easy to read format.

fork-git

#!/bin/bash
#Bash Script to identify disk, Vendor name, Serial & WWN for all kinds of Mounted Block devices
for i in `lsblk | grep disk | egrep -v 'Vx|ram|raw|loop|fd|md|dm-|sr|scd|st' | awk '{ print $1 }'`
do
lsblk /dev/$i | awk '{print "MOUNT="$NF}' | grep -i '/'
if [ $? = "0" ]; then
lsblk /dev/$i | grep disk | awk '{print "BLOCK_SIZE="$4}'
udevadm info --query=all --name /dev/$i | egrep 'DEVNAME=|ID_VENDOR=|ID_SERIAL_RAW=|ID_WWN=|ID_PATH=|ID_SCSI_SERIAL=' | awk '{ print $2 }'
echo "--------------"
fi
done

Below is a partial output of the script showing File systems and its underlying Netapp LUN details.

MOUNT=/Data
BLOCK_SIZE=62.9T
DEVNAME=/dev/sdb
ID_VENDOR=DELL
ID_SERIAL_RAW=36d0946600e82d800224428d411d8fcdb
ID_WWN=0x6d0946600e82d800
ID_SCSI_SERIAL=00dbfcd811d428442200d8820e604609
ID_PATH=pci-0000:02:00.0-scsi-0:2:1:0
--------------
MOUNT=/opt/apps
BLOCK_SIZE=1.5T
DEVNAME=/dev/sdd
ID_VENDOR=NETAPP
ID_SERIAL_RAW=360a98000417646566724443564466867
ID_WWN=0x60a9800041764656
ID_SCSI_SERIAL=AvFVg$D5dFhg
ID_PATH=pci-0000:84:00.0-fc-0x500a098489ab3031-lun-1
--------------
MOUNT=/opt/apps
BLOCK_SIZE=1.5T
DEVNAME=/dev/sdc
ID_VENDOR=NETAPP
ID_SERIAL_RAW=360a98000417646566724443564466865
ID_WWN=0x60a9800041764656
ID_SCSI_SERIAL=AvFVg$D5dFhe
ID_PATH=pci-0000:84:00.0-fc-0x500a098489ab3031-lun-0
--------------