When working with MegaRAID controllers on Linux systems, one common frustration is mapping logical drives (virtual disks) to their corresponding Linux block devices. The standard MegaCli tools provide detailed information about physical disks but don't directly show the relationship between virtual drives and /dev/sd* paths.
Here's a reliable method to find the /dev/sd* device for Virtual Drive 0 on Adapter 8:
# First, get the Enclosure and Slot numbers for the virtual drive
./MegaCli64 -LDinfo -L0 -a8 | grep -E 'Number Of Drives|Span Depth'
# Cross-reference with physical disks
./MegaCli64 -PDlist -a8 | grep -E 'Enclosure Device|Slot Number|WWN'
# Find the matching WWN in /dev/disk/by-id
ls -lah /dev/disk/by-id | grep -i "WWN_FROM_PREVIOUS_STEP"
# Alternatively, use the SCSI inquiry method
lsscsi | grep -i "LSI"
For systems with sg3-utils installed, try this more direct approach:
# Install sg3-utils if needed
yum install sg3-utils
# Map MegaRAID devices to SCSI generic
sg_map -x
# Cross-reference with:
ls -l /dev/disk/by-path/ | grep -i "scsi-8"
For repeated use, consider this bash script:
#!/bin/bash
ADAPTER=8
VDRIVE=0
# Get WWNs of drives in virtual drive
WWN_LIST=$(./MegaCli64 -LDinfo -L$VDRIVE -a$ADAPTER | \
awk '/^Number Of Drives/{d=$NF} /^Span Depth/{s=$NF} END{print d*s}')
# Find matching /dev/sd* devices
for wwn in $(./MegaCli64 -PDlist -a$ADAPTER | grep WWN | awk '{print $2}' | head -n $WWN_LIST); do
find /dev/disk/by-id/ -name "*$wwn*" -exec readlink -f {} \;
done
If you're still having trouble:
- Check dmesg after controller initialization:
dmesg | grep -i megaraid
- Verify the driver version:
modinfo megaraid_sas
- Update MegaCLI if older than version 8.07
Once you've identified the device:
smartctl -a /dev/sdX -d megaraid,0
Should return valid SMART data for the virtual drive.
When working with MegaRAID controllers on Linux systems, one common pain point is correlating virtual drives (logical volumes) with their corresponding Linux device names (like /dev/sdt
). The MegaCli
utility provides detailed information about physical and logical drives, but doesn't directly show this mapping.
First, let's examine what information we can gather:
# List physical drives on adapter 8
./MegaCli64 -pdlist -a8 | grep -E 'WWN|Enclosure Device ID|Slot Number'
# Example output:
Enclosure Device ID: 32
Slot Number: 0
WWN: 500051610003776C
--
Enclosure Device ID: 32
Slot Number: 1
WWN: 5000516100037BFC
Here's the complete workflow to find the Linux device name for Virtual Drive 0 on Adapter 8:
# Step 1: Get the WWN of physical drives in the virtual drive
./MegaCli64 -ldpdinfo -a8 -L0 | grep WWN
# Step 2: Find the corresponding /dev/disk/by-id/wwn-* symlinks
ls -l /dev/disk/by-id/wwn-* | grep -f <(./MegaCli64 -ldpdinfo -a8 -L0 | grep WWN | cut -d' ' -f2)
# Step 3: Resolve to the final /dev/sdX device
readlink -f /dev/disk/by-id/wwn-0x500051610003776C
If you have the sg3-utils
package installed, you can use this simpler approach:
# First find the sg device corresponding to your virtual drive
./MegaCli64 -ldinfo -L0 -a8 | grep 'Device Name'
# Output might show something like: /dev/sg4
# Then map it to the sd device
sg_map -x | grep /dev/sg4
# Output example: /dev/sg4 /dev/sdc
Here's a bash script that automates the entire process:
#!/bin/bash
# Usage: ./map_vd_to_sd.sh [adapter] [virtual_drive]
ADAPTER=${1:-0}
VD=${2:-0}
# Get enclosure and slot info for drives in VD
DRIVES=$(./MegaCli64 -ldpdinfo -a$ADAPTER -L$VD | awk '/WWN/{print $2}')
for wwn in $DRIVES; do
# Convert to lowercase and prepend 0x for by-id matching
wwn_id="wwn-0x${wwn,,}"
if [ -e "/dev/disk/by-id/$wwn_id" ]; then
sd_device=$(readlink -f "/dev/disk/by-id/$wwn_id")
echo "Virtual Drive $VD on Adapter $ADAPTER maps to: $sd_device"
fi
done
1. The WWN format in /dev/disk/by-id/
may vary between distributions
2. Some systems show WWNs with 0x prefix, others without
3. Always verify with lsblk
or fdisk -l
before making changes to disks