MegaCLI Cheat Sheet: RAID Status, Rebuild and Drive Swap
Quick fix
Check every drive withmegacli -PDList -aALL | grep -E "Slot Number|Firmware state" and every array with megacli -LDInfo -Lall -aALL | grep -E "Virtual Drive|State". Watch a rebuild with megacli -PDRbld -ShowProg -PhysDrv [E:S] -a0, using the enclosure and slot numbers from -PDList.On this page
MegaCLI manages LSI MegaRAID controllers, including the Dell PERC H700, H710 and H730 family. Its syntax is cryptic, so this cheat sheet collects the commands you actually need when a drive fails: status checks, rebuilds, drive replacement and foreign configurations.
Installing MegaCLI
MegaCLI is not in the Debian or Ubuntu archives. Broadcom ships it as an RPM (MegaCli-8.07.14), and the community hwraid repository packages it for Debian and Ubuntu as megacli:
sudo apt-get install megacliThat command only works after you add the hwraid repository. If you install Broadcom’s RPM (or convert it with alien), the binary is /opt/MegaRAID/MegaCli/MegaCli64; link it into your PATH so the commands below work as written:
sudo ln -s /opt/MegaRAID/MegaCli/MegaCli64 /usr/local/bin/megacliCommon Parameters
Controller Syntax: -aN
- Use this to specify the adapter ID, starting at 0.
-aALLis fine for read-only commands. For changes, name the adapter (-a0) to avoid touching every controller.
Physical Drive: -PhysDrv [E:S]
E: Enclosure IDS: Slot number (starting at 0).- Retrieve enclosure and slot information with:
megacli -EncInfo -aALL
megacli -PDList -aALL | grep -E "Enclosure Device ID|Slot Number"Virtual Drive: -Lx
- Use to specify the virtual drive where
xis a number starting at 0 or the stringall.
Information Commands
Drive and Array Status
- List all physical drives with their state (
Online, Spun Up,Failed,Rebuild,Unconfigured(good)):bashmegacli -PDList -aALL - Show virtual drives (arrays) and whether they are
OptimalorDegraded:bashmegacli -LDInfo -Lall -aALL - Check media and predictive failure counters, which warn you before a drive fails:bash
megacli -PDList -aALL | grep -E "Slot Number|Media Error Count|Predictive Failure Count"
Controller Information
- Display adapter details:bash
megacli -AdpAllInfo -aALL - Show RAID configuration:bash
megacli -CfgDsply -aALL - Check the cache battery (BBU); a failed battery forces write-through and slows writes:bash
megacli -AdpBbuCmd -GetBbuStatus -aALL - Export event logs:bash
megacli -AdpEventLog -GetEvents -f lsi-events.log -a0 -NoLog
Common Operations
Blink a Drive LED
Find the physical disk before you pull it:
megacli -PDLocate -start -PhysDrv [E:S] -a0
megacli -PDLocate -stop -PhysDrv [E:S] -a0Replace a Drive
- Set the drive offline:bash
megacli -PDOffline -PhysDrv [E:S] -aN - Mark the drive as missing:bash
megacli -PDMarkMissing -PhysDrv [E:S] -aN - Prepare for removal:bash
megacli -PDPrpRmv -PhysDrv [E:S] -aN - Replace the drive and assign it to the missing array row (get
Arrayandrowfrommegacli -PDGetMissing -aN):bashmegacli -PDGetMissing -aN megacli -PdReplaceMissing -PhysDrv [E:S] -ArrayN -rowN -aN - Start the rebuild process:bash
megacli -PDRbld -Start -PhysDrv [E:S] -aN
Most controllers start the rebuild on their own when a new drive goes into a slot that belonged to a degraded array, so check -PDList before running steps 4 and 5.
Watch a Rebuild
megacli -PDRbld -ShowProg -PhysDrv [E:S] -aNAdd a Hot Spare
megacli -PDHSP -Set -PhysDrv [E:S] -aNFix a “Foreign” Drive
A drive that was part of another array shows as Foreign. Scan first, then either import the configuration (keep the data) or clear it (discard it):
- Scan for foreign configurations:bash
megacli -CfgForeign -Scan -aALL - Import it, if the drive belongs to an array you want back:bash
megacli -CfgForeign -Import -aALL - Or clear it, then mark the drive as good so it can be reused:bash
megacli -CfgForeign -Clear -aALL megacli -PDMakeGood -PhysDrv [E:S] -aN
Silence or Disable the Alarm
Silence the current alarm only:
megacli -AdpSetProp AlarmSilence -aALLDisable it permanently (you will no longer hear about the next failure, so make sure monitoring covers it):
megacli -AdpSetProp AlarmDsbl -aALLFAQ
How do I check if a RAID array is degraded with MegaCLI?
Run megacli -LDInfo -Lall -aALL | grep State. Optimal is healthy; Degraded means a member drive failed or is rebuilding; Offline means the array has lost too many drives.
Why does MegaCLI fail with libncurses.so.5: cannot open shared object file?
The binary is old and links against ncurses 5. Install libncurses5 where your distribution still ships it, or use StorCLI or PERCCLI, which do not need it.
MegaCLI shows “Unconfigured(bad)” for a new drive. What now?
Run megacli -PDMakeGood -PhysDrv [E:S] -aN to mark it good, then check for a foreign configuration with -CfgForeign -Scan.