MegaCLI Monitor RAID Status
Introduction
MegaCLI is a software tool for managing and maintaining hardware RAID. It allows you to retrieve all information about the current RAID controller, including the controller model, RAID array type, status of each disk in the array, etc. Typically, it is difficult to determine the current status of hard disks; this is usually done via physical inspections by data center staff. Is there a way to check and verify this using software? MegaCLI can accomplish this. Generally, we determine whether there are issues with disks in the array based on two values: Media Error Count: 0 and Other Error Count: 0. Media Error Count indicates potential disk errors, such as bad sectors; if this value is non-zero, it requires attention—the higher the value, the greater the risk. Other Error Count indicates that a disk may be loose and might need to be reinserted. MegaCLI can scan all disks in the array. We can detect relevant parameters via scripts to notify administrators.
I. Download MegaCLI
Currently, the company's DB database runs on IBM servers. Download directly from the official IBM site. If
for other servers, use the respective official download sites or the LSI website for downloads. Generally, the package is universal and applies to both 32-bit and 64-bit operating system platforms.
Download URL: ftp://download2.boulder.ibm.com/ecc/sar/CMA/XSA/ibm_utl_sraidmr_megacli-8.00.48_linux_32-64.zip
II. Installation
#unzip ibm_utl_sraidmr_megacli-8.00.48_linux_32-64.zip#cd linux# rpm -ivh Lib_Utils-1.00-09.noarch.rpm MegaCli-8.00.48-1.i386.rpmIII. Command Usage and Parameters
Click (here) to collapse or expand
- Command usage:
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL Check RAID level
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aALL Check RAID controller information
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL View hard disk information
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -aAll View battery information
- #/opt/MegaRAID/MegaCli/MegaCli64 -FwTermLog -Dsply -aALL View RAID controller logs
- #/opt/MegaRAID/MegaCli/MegaCli64 -adpCount [Display number of adapters]
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpGetTime –aALL [Display adapter time]
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aAll [Display all adapter information]
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -LALL -aAll [Display all logical disk group information]
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll [Display all physical information]
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL |grep 'Charger Status' [Check charging status]
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL [Display BBU status information]
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuCapacityInfo -aALL [Display BBU capacity information]
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuDesignInfo -aALL [Display BBU design parameters]
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuProperties -aALL [Display current BBU attributes]
- #/opt/MegaRAID/MegaCli/MegaCli64 -cfgdsply -aALL [Display RAID controller model, RAID settings, and disk-related information]
- 3. Changes in tape status during the process of removing and inserting disks.
- Device |Normal|Damage|Rebuild|Normal
- Virtual Drive |Optimal|Degraded|Degraded|Optimal
- Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online
- 4. View disk cache policy
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -L0 -a0
- or
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -L1 -a0
- or
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -a0
- ro
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -aALL
- ro
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -DskCache -LALL -aALL
- 5. Set disk cache policy
- Cache policy explanation:
- WT (Write through
- WB (Write back)
- NORA (No read ahead)
- RA (Read ahead)
- ADRA (Adaptive read ahead)
- Cached
- Direct
- Example:
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp WT|WB|NORA|RA|ADRA -L0 -a0
- or
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -Cached|-Direct -L0 -a0
- or
- enable / disable disk cache
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -EnDskCache|-DisDskCache -L0 -a0
- 6. Create a RAID 5 array composed of physical disks 2, 3, and 4, with physical disk 5 as the hot spare.
- #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [1:2,1:3,1:4] WB Direct -Hsp[1:5] -a0
- 7. Create an array without specifying a hot spare
- #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [1:2,1:3,1:4] WB Direct -a0
- 8. Delete an array
- #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdDel -L1 -a0
- 9. Add a disk online
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDRecon -Start -r5 -Add -PhysDrv[1:4] -L1 -a0
- 10. After array creation, there is an initialization synchronization process; you can view its progress.
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDInit -ShowProg -LALL -aALL
- Or display dynamically in a text-based visual interface
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDInit -ProgDsply -LALL -aALL
- 11. View background initialization progress of the array
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDBI -ShowProg -LALL -aALL
- Or display dynamically in a text-based visual interface
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDBI -ProgDsply -LALL -aALL
- 12. Designate the 5th disk as a global hot spare
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-EnclAffinity] [-nonRevertible] -PhysDrv[1:5] -a0
- 13. Specify a dedicated hot spare for a specific array
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-Dedicated [-Array1]] [-EnclAffinity] [-nonRevertible] -PhysDrv[1:5] -a0
- 14. Delete global hot spare
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Rmv -PhysDrv[1:5] -a0
- 15. Offline/Online a physical disk
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDOffline -PhysDrv [1:4] -a0
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDOnline -PhysDrv [1:4] -a0
- 16. View physical disk rebuild progress
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ShowProg -PhysDrv [1:5] -a0
- Or display in dynamic visual text interface
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ProgDsply -PhysDrv [1:5] -a0
- Changes in tape status during the process of removing and inserting disks:
- Device |Normal|Damage|Rebuild|Normal
- Virtual Drive |Optimal|Degraded|Degraded|Optimal
- Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online
1. View RAID level

2. View RAID controller information, mainly outputting some configuration information of the RAID controller

RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 1.086 TB
State : Optimal
Strip Size : 128 KB
Number Of Drives per span: 4 // Indicates that 4 physical disks form one RAID1 disk group
Span Depth : 2 // Indicates that 2 RAID1 disk groups form a RAID10
3. View information for all hard disks
/opt/MegaCli64 -pdlist –aALL

4. View current RAID cache status. If the RAID cache status is set to WB, attention must be paid to battery discharge. Set the battery discharge mode to automatic learning mode
/opt/MegaRAID/MegaCli/MegaCli64 -ldgetprop -dskcache -lall -aall

5. Related settings for RAID batteries
View battery status information (Display BBU Status Information)
MegaCli -AdpBbuCmd -GetBbuStatus -aN|-a0,1,2|-aALL
MegaCli -AdpBbuCmd -GetBbuStatus -aALL
View battery capacity (Display BBU Capacity Information)
MegaCli -AdpBbuCmd -GetBbuCapacityInfo -aN|-a0,1,2|-aALL
MegaCli -AdpBbuCmd -GetBbuCapacityInfo –aALL
View battery design parameters (Display BBU Design Parameters)
MegaCli -AdpBbuCmd -GetBbuDesignInfo -aN|-a0,1,2|-aALL
MegaCli -AdpBbuCmd -GetBbuDesignInfo –aALL
View current battery properties (Display Current BBU Properties)
MegaCli -AdpBbuCmd -GetBbuProperties -aN|-a0,1,2|-aALL
MegaCli -AdpBbuCmd -GetBbuProperties –aALL
Set battery to learning mode as cycling mode (Start BBU Learning Cycle)
Description Starts the learning cycle on the BBU.
No parameter is needed for this option.
MegaCli -AdpBbuCmd -BbuLearn -aN|-a0,1,2|-aALL
Set disk cache mode and access method (Change Virtual Disk Cache and Access Parameters)
Description Allows you to change the following virtual disk parameters:
-WT (Write through), WB (Write back): Selects write policy.
-NORA (No read ahead), RA (Read ahead), ADRA (Adaptive read ahead): Selects read policy.
-Cached, -Direct: Selects cache policy.
-RW, -RO, Blocked: Selects access policy.
-EnDskCache: Enables disk cache.
-DisDskCache: Disables disk cache.
MegaCli -LDSetProp { WT | WB|NORA |RA | ADRA|-Cached|Direct} |
{-RW|RO|Blocked} |
{-Name[string]} |
{-EnDskCache|DisDskCache} –Lx |
-L0,1,2|-Lall -aN|-a0,1,2|-aALL
MegaCli -LDSetProp WT -L0 -a0
Display disk cache and access method (Display Virtual Disk Cache and Access Parameters)
MegaCli -LDGetProp -Cache | -Access | -Name | -DskCache -Lx|-L0,1,2|
-Lall -aN|-a0,1,2|-aALL
Displays the cache and access policies of the virtual disk(s):
-WT (Write through), WB (Write back): Selects write policy.
-NORA (No read ahead), RA (Read ahead), ADRA (Adaptive read ahead): Selects read policy.
-Cache, -Cached, Direct: Displays cache policy.
-Access, -RW, -RO, Blocked: Displays access policy.
-DskCache: Displays physical disk cache policy.
Megaraid Essentials: Using LSI Megaraid allows effective monitoring of RAID. Other vendors such as HP and IBM also have their own RAID APIs
MegaCli -ldinfo -lall -aall
Query RAID level, number of disks, capacity, and stripe size.
MegaCli -cfgdsply -aALL |grep Policy
Query controller cache policy
MegaCli -LDSetProp WB -L0 -a0
Set write-back function
MegaCli -LDSetProp CachedBadBBU -L0 -a0
Set to maintain WB function even if the battery fails
MegaCli -AdpBbuCmd -BbuLearn a0
Manual charging
MegaCli -FwTermLog -Dsply -aALL
Query logs
Display adapter count: MegaCli -adpCount
Display all adapter information: MegaCli -AdpAllInfo -aAll
Critical Disks : 0
Failed Disks : 0
Display all logical disk group information: MegaCli -LDInfo -LALL -aAll
Display all physical information: MegaCli -PDList -aAll
Media Error Count: 0
Other Error Count: 0
View charging status: MegaCli -AdpBbuCmd -GetBbuStatus -aALL
Learn Cycle Requested : No
Fully Charged : Yes
Display BBU (backup battery) status information: MegaCli -AdpBbuCmd -GetBbuStatus -aALL
Display BBU capacity information: MegaCli -AdpBbuCmd -GetBbuCapacityInfo -aALL
Display BBU design parameters: MegaCli -AdpBbuCmd -GetBbuDesignInfo -aALL
Display current BBU properties: MegaCli -AdpBbuCmd -GetBbuProperties -aALL
Display RAID controller model, RAID settings, and disk information: MegaCli -cfgdsply -aALL
View cache policy settings: MegaCli -cfgdsply -aALL |grep -i Policy
Current Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
View battery charge progress percentage: MegaCli -AdpBbuCmd -GetBbuStatus -aALL
Different states for various devices and disks:
Device |Normal|Damage|Rebuild|Normal
Virtual Drive |Optimal|Degraded|Degraded|Optimal
Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online
6. Detect RAID disk status via script
Script under Linux
#!/bin/bash
#check raid disk statusMEGACLI="/opt/MegaRAID/MegaCli/MegaCli64 "
$MEGACLI -pdlist -aALL | grep "Firmware state" | awk -F : '{print $2}' | awk -F , '{print $1}' >/tmp/fireware.log
$MEGACLI -pdlist -aALL | grep -E "Media Error|Other Error" | awk -F : '{print $2}' >/tmp/disk.log
for i in `cat < /tmp/disk.log`
do
if [ $i -ne 0 ]
then
curl "http://xxxxxxB&state=ALARM&description=raid_disk_error"
fi
done
for i in `cat < /tmp/fireware.log`
do
if [ $i != Online ]
then
curl "http://xxxxxxstate=ALARM&description=raid_disk_offline"
fi
done
Script under Windows
The tools used for the Windows script are some software from the gnu for windows platform, such as bash, grep, awk, cat
Call the script directly via bash
For example: G:\raid_check\unixtools>bash.exe G:\disk.sh
#check raid disk statusMEGACLI="//G/raid_check/MegaCli.exe"
GREP="//G/raid_check/unixtools/grep.exe"
AWK="//G/raid_check/unixtools/awk.exe"
CAT="//G/raid_check/unixtools/cat.exe"
CURL="//G/raid_check/unixtools/curl.exe"
$MEGACLI -pdlist -aALL | $GREP "Firmware state" |$AWK -F: '{print $2}' |$AWK -F , '{print $1}' >//c/fireware.log
$MEGACLI -pdlist -aALL | $GREP -E "Media Error|Other Error" | $AWK -F : '{print $2}' > //c/disk.log
for i in `$CAT c:/disk.log`
do
if [ $i -ne 0 ]
then
$CURL "http://xxxxxx&description=raid_disk_error"
fi
done
for i in `$CAT c:/fireware.log`
do
if [ $i != Online ]
then
$CURL "http://xxxxx&state=ALARM&description=raid_disk_offline"
fi
Images localized into English for illustration; labels may vary by product version.