The MegaRAID Command Tool (CT) is a command line interface (CLI) application for SAS. You can use this utility to configure, monitor, and maintain the MegaRAID SAS RAID controllers and the devices connected to them.


To be noted is that the Command Tool  supports only the MegaRAID controllers that support SAS and SATA II. It does not support other types of MegaRAID controllers, suchas U320, SATA I, or IDE.


For more info about MegaRAID, read MegaRAID SAS Software User Guide


In this article, I'll only show you some  of Megacli command examples, you can also check MegaCli command reference for more

 

Download and Install the MegaCLI tool package

Go to the LSI Downloads page: LSI Downloads, you can either type megacli to search, or chose by product at left bar.
Download the MegaCLI zip file. You will see the same file is for DOS, Windows, Linux and FreeBSD.
Unzip the file
In the Linux directory there is an RPM. If you are using Redhat you can install it.
For Ubuntu run "rpm2cpio MegaCli-*.rpm | cpio -idmv" to expand the directory structure. You may need to "apt-get install rpm2cpio" .
For FreeBSD unzip the file in the FreeBSD directory.

Display all Adapters Configuration without log

This command shows Atapter, Logical Drive, Physical Drive etc.. all in one.

#MegaCli64 -CfgDsply -aALL -nolog

Display Adapters properties

# MegaCli64 -AdpAllInfo -aALL

Get Number of Adapter

#MegaCli64 -adpCount
Controller Count: 1.

List all physical disks

The -a command line switch specifies the Adapter ID, in this case Adapter 0.

Note:[-aALL] option assumes that the parameters specified are valid for all the Adapters.

In the example below, it only show physical disk number, size and disk type.

# MegaCli64 -pdList -a0 | grep -i -E "slot|RAW Size|pd type"
Slot Number: 0
PD Type: SAS
Raw Size: 558.911 GB [0x45dd2fb0 Sectors]
Slot Number: 1
PD Type: SAS
Raw Size: 558.911 GB [0x45dd2fb0 Sectors]
Slot Number: 2
PD Type: SAS
Raw Size: 558.911 GB [0x45dd2fb0 Sectors]
Slot Number: 3
PD Type: SAS
Raw Size: 558.911 GB [0x45dd2fb0 Sectors]

Create a Logical Drive

Query physical disk info first

#MegaCli64 -PDList -aALL | egrep 'Adapter|Enclosure|Slot|Inquiry'
Adapter #0
Enclosure Device ID: 252
Slot Number: 0
Enclosure position: N/A
Inquiry Data: IBM-ESXSMBF2600RC SB2AEA00JHK4SB2ASB2ASB2A
Enclosure Device ID: 252
Slot Number: 1
Enclosure position: N/A
Inquiry Data: IBM-ESXSMBF2600RC SB2AEA00JHK1SB2ASB2ASB2A
Enclosure Device ID: 252
Slot Number: 2
Enclosure position: N/A
Inquiry Data: IBM-ESXSAL13SEB600 SB3534401NH4SB35SB35SB35
Enclosure Device ID: 252
Slot Number: 3
Enclosure position: N/A
Inquiry Data: IBM-ESXSAL13SEB600 SB35344031H4SB35SB35SB35

Create a Logical Drive

#MegaCli64 -CfgLdAdd -r1 '[252:2,252:3]' -a0

List Logical Drive info

The -L specifies the LD ID, -a specifies Adapter ID, same as the example above.

#MegaCli64 -LDInfo -Lall -aALL

Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name :
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 557.861 GB
Mirror Data : 557.861 GB
State : Optimal
Strip Size : 128 KB
Number Of Drives : 2
Span Depth : 1
Default Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disabled
Encryption Type : None
Is VD Cached: No

Virtual Drive: 1 (Target Id: 1)
Name :
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 557.861 GB
Mirror Data : 557.861 GB
State : Optimal
Strip Size : 128 KB
Number Of Drives : 2
Span Depth : 1
Default Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disabled
Encryption Type : None
Is VD Cached: No

In the case above, 2 LD were listed, with detail info such as raid level, size, strip size, cache policy etc..

Just want to get number of LD configured, here is it

#MegaCli64 -LdGetNum -aAll
Number of Virtual Drives Configured on Adapter 0: 2

View information about the battery backup-up unit state

#MegaCli64 -AdpBbuCmd -aAll 
BBU status for Adapter: 0

BatteryType: iBBU08
Voltage: 4080 mV
Current: 0 mA
Temperature: 31 C
Battery State     : Operational

BBU Firmware Status:

  Charging Status              : None
  Voltage                                 : OK
  Temperature                             : OK
  Learn Cycle Requested                      : No
  Learn Cycle Active                      : No
  Learn Cycle Status                      : OK
  Learn Cycle Timeout                     : No
  I2c Errors Detected                     : No
  Battery Pack Missing                    : No
  Battery Replacement required            : No
  Remaining Capacity Low                  : No
  Periodic Learn Required                 : No
  Transparent Learn                       : No
  No space to cache offload               : No
  Pack is about to fail & should be replaced : No
  Cache Offload premium feature required  : No
  Module microcode update required        : No
BBU GasGauge Status: 0x0280
  Relative State of Charge: 100 %
  Charger System State: 1
  Charger System Ctrl: 0
  Charging current: 0 mA
  Absolute state of charge: 88 %
  Max Error: 0 %

  Battery backup charge time : 48 hours +

BBU Capacity Info for Adapter: 0

  Relative State of Charge: 100 %
  Absolute State of charge: 88 %
  Remaining Capacity: 1333 mAh
  Full Charge Capacity: 1336 mAh
  Run time to empty: Battery is not being discharged.  
  Average time to empty: 2 Hour, 40 Min.
  Estimated Time to full recharge: Battery is not being charged.  
  Cycle Count: 6

BBU Design Info for Adapter: 0

  Date of Manufacture: 02/29, 2012
  Design Capacity: 1500 mAh
  Design Voltage: 4100 mV
  Specification Info: 0
  Serial Number: 698
  Pack Stat Configuration: 0x0000
  Manufacture Name: LS36691
  Device Name: bq27541
  Device Chemistry: LION
  Battery FRU: N/A
  Transparent Learn = 0
  App Data = 0

BBU Properties for Adapter: 0

  Auto Learn Period: 30 Days
  Next Learn time: Sat Aug 23 01:57:06 2014
 
  Learn Delay Interval:0 Hours
  Auto-Learn Mode: Enabled
  BBU Mode = 4

Configure write-cache to be disabled when battery is broken

# MegaCli64 -LDSetProp NoCachedBadBBU -LALL -aALL

Change physical disk cache policy

To disable it at no UPS situation

# MegaCli -LDGetProp -DskCache -LAll -aALL

To enable it:

# MegaCli -LDGetProp -DskCache -LAll -aALL

Blink Hard Drive Lights

Sometime, if a disk not complete dead, you may not see a amber light

Start Blinking

MegaCli64 -PdLocate -start -physdrv[<ENCLOSURE>:<DRIVE>] -a0

Stop Blinking

MegaCli64 -PdLocate -stop -physdrv[<ENCLOSURE><DRIVE>] -a0

View reconstruction progress

When reconstructing a RAID array, you can check its progress with this command, in this case, Logical Drive 0, Adapter 0

# MegaCli64 -LDRecon ShowProg L0 -a0

Patrol Read

Patrol read is a feature which tries to discover disk error before it is too late and data is lost. By default it is done automatically (with a delay of 168 hours between different patrol reads) and will take up to 30% of IO resources.

You can find more detail in megaraid patrol read and consistent check and MeagRAID Patrol Read Detail

To see information about the patrol read state and the delay between patrol read runs:

# MegaCli64 -AdpPR -Info -aALL

To find out the current patrol read rate, execute

# MegaCli64 -AdpGetProp PatrolReadRate -aALL

To reduce patrol read resource usage to 2% in order to minimize the performance impact:

# MegaCli64 -AdpSetProp PatrolReadRate 2 -aALL

To disable automatic patrol read:

# MegaCli64 -AdpPR -Dsbl -aALL

To enable automatic patrol read:

#MegaCli64 -AdpPR -EnblAuto -aALL

To start a manual patrol read scan:

# MegaCli64 -AdpPR -Start -aALL

To stop a patrol read scan:

# MegaCli64 -AdpPR -Stop -aALL

Note: Use the above commands to run patrol read in off-peak times.


Check  MegaRAID Patrol Read  and MegaRAID Consistency Check for more details