Recently one of my RAID drives failed failed on my server and I had to learn to use MegaCli.

MegaCli is a command line tool used to manage DELL hardware RAID devices, however, the available guides are cryptic and difficult to follow. This post shows how I was able to install and use megacli on a Debian Server.

TL:DR – As I had a hotswap RAID controller I was able to simply pull the failed drive, insert the new drive, and the RAID array was restored. I was able to confirm the success using megacli over ssh, however, the megacli guides are cryptic at best. Most of the guides show output from a working system and do not show the actual output and commands on a failed system.

I am running a Debian server and The Debian Raid Guide was invaluable as was Erik’s cheatsheet

For those who are interested, provides information on installing from Broadcom and a wrapper script form MegaCli.

Unfortunately the process was cryptic enough to warrant some additional information.

First identify the RAID controller

lspci -nn | grep RAID
02:0e.0 RAID bus controller [0104]: Dell PowerEdge Expandable RAID controller 5 [1028:0015]

MegaCLI is NOT in the debian repos, however, a .deb is available at Debian MegaCLI packages at . Alternately you can download the source code from Source Forge

Add the following repository to /etc/apt/sources.list :

deb jessie main

Add the gpg key and install

wget -O – | sudo apt-key add –

sudo apt-get install megacli

Here is where the fun starts =)

First, although most online guides use the command MegaCli, the actual command after installing the package is megacli making copy paste difficult.

First you have to identify the raid device and physical drives as you need to specify them with the commands.

To see all information, run megacli -AdpAllInfo -aALL. I suggest you pipe the output to less or a file.

megacli -AdpAllInfo -aALL >
megacli -AdpAllInfo -aALL | less

The relevant information from my system was

Enclosure Device ID: 8

Device Present
Virtual Drives : 1
Degraded : 1
Offline : 0
Physical Devices : 2
Disks : 1
Critical Disks : 0
Failed Disks : 0


Note: From Erik’s cheatsheet, Drives are specified using :

the -PhysDrv [E:S] parameter is used, where E is the enclosure device ID in which the drive resides and S the slot number (starting with zero)

The “S” parameters were easy enough, drive 0 and drive 1 , but the E parameter was obscure. Turns out it is identified in the line “Enclosure Device ID: 8” shown above. Common numbers on other posts on megacli are 0 and 256 .

So on my system drive 0 = [8:0] and drive 1 = [8:1]

Because my default shell is zsh rather then bash, when using the command megacli -PdInfo -PhysDrv [8:0] -a0 I HAD TO ESCAPE THE BRACKETS like so megacli -PdInfo -PhysDrv\[8:0\] a0

Drive 0

megacli -PdInfo -PhysDrv \[8:0\] -a0

Adapter 0: Device at Enclosure – 8, Slot – 0 is not found.

Exit Code: 0x00

Drive 1

>megacli -PdInfo -PhysDrv \[8:1\] -a0

Enclosure Device ID: 8
Slot Number: 1
Drive’s position: DiskGroup: 0, Span: 0, Arm: 1
Enclosure position: N/A
Device Id: 1
Sequence Number: 4
Media Error Count: 0
Other Error Count: 17
Predictive Failure Count: 0
Last Predictive Failure Event Seq Number: 0

Raw Size: 931.512 GB [0x74706db0 Sectors]
Non Coerced Size: 931.012 GB [0x74606db0 Sectors]
Coerced Size: 931.0 GB [0x74600000 Sectors]
Sector Size: 0
Firmware state: Online, Spun Up
Device Firmware Level: SN04
Shield Counter: 0
Successful diagnostics completion on : N/A
SAS Address(0): 0x1221000001000000
Connected Port Number: 1
Inquiry Data: 5QJ09SPBST31000340NS SN04
FDE Capable: Not Capable
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: Unknown
Link Speed: Unknown
Media Type: Hard Disk Device
Drive Temperature : N/A
PI Eligibility: No
Drive is formatted for PI information: No
Port-0 :
Port status: Active
Port’s Linkspeed: Unknown
Drive has flagged a S.M.A.R.T alert : No

So drive 0 had failed. As my raid controller is hot swap and, as the drive had failed, I could not run any additional commands suggested on Eirk’s cheatsheet.

megacli -PDPrpRmv -PhysDrv \[8:0\] -a0

Adapter #0: Failed to Perform prepare for removal Operation.

So just replace the failed drive. You can see the drive being rebuilt with the command

megacli -PDRbld -ShowProg -PhysDrv \[8:0\] -aALL

Rebuild Progress on Device at Enclosure 8, Slot 0 Completed 79% in 5 Minutes.

Exit Code: 0x00

Once the rebuild is done, you can check the log (after generating it).

megacli -fwtermlog -dsply -a0 -nolog > megacli.log

The log file is extensive, but scrolling to the bottom we see the new drive recognized and rebuilt

06/20/17 17:40:50: EVT#15853-06/20/17 17:40:50: 91=Inserted: PD 00(e1/s0)
06/20/17 17:40:50: EVT#15854-06/20/17 17:40:50: 247=Inserted: PD 00(e1/s0) Info: enclPd=08, scsiType=0, portMap=01, sasAddr=1221000000000000,0000000000000000
06/20/17 17:40:50: EVT#15855-06/20/17 17:40:50: 236=PD 00(e1/s0) is not a certified drive
06/20/17 17:40:50: EVT#15856-06/20/17 17:40:50: 114=State change on PD 00(e1/s0) from UNCONFIGURED_GOOD(0) to OFFLINE(10)
06/20/17 17:40:50: EVT#15857-06/20/17 17:40:50: 106=Rebuild automatically started on PD 00(e1/s0)
06/20/17 17:40:50: EVT#15858-06/20/17 17:40:50: 114=State change on PD 00(e1/s0) from OFFLINE(10) to REBUILD(14)
06/20/17 17:42:23: EVT#15859-06/20/17 17:42:23: 103=Rebuild progress on PD 00(e1/s0) is 0.99%(93s)

…… clipped output …..

06/20/17 21:03:16: EVT#15958-06/20/17 21:03:16: 103=Rebuild progress on PD 00(e1
/s0) is 99.94%(12146s)
06/20/17 21:03:26: EVT#15959-06/20/17 21:03:26: 100=Rebuild complete on PD 00(e1
06/20/17 21:03:27: EVT#15960-06/20/17 21:03:27: 81=State change on VD 00/0 from DEGRADED(2) to OPTIMAL(3)

EDIT 12.18.2017

First there is a helpful wrapper script on

I copied it to /root/bin/raid

I then used to identify and reinitialize a failed drive

root@banshee~/bin# ./raid drives
Slot Number: 0 – Online, Spun Up
Slot Number: 1 – Failed

root@banshee~/bin# megacli PDOffline -PhysDrv \[8:1\] -aALL

Adapter: 0: EnclId-8 SlotId-1 state changed to OffLine.

Exit Code: 0x00

root@banshee~/bin# megacli PDOnline -PhysDrv \[8:1\] -aALL

EnclId-8 SlotId-1 state changed to OnLine.

Exit Code: 0x00

root@banshee~/bin# ./raid drives
Slot Number: 0 – Online, Spun Up
Slot Number: 1 – Online, Spun Up

This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *