# Raid

# Software Raid

#### **Create raid:**

<p class="callout info">Raid levels can be changed with: --level=1 // --level=0 // --level=5</p>

**Raid 1**

```
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdX /dev/sdX
```

<span class="highlight">Raid 5</span>

```
mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdX /dev/sdX /dev/sdX
```

**Raid 6**

```
mdadm --create --verbose /dev/md0 --level=6 --raid-devices=4 /dev/sda /dev/sdX /dev/sdX /dev/sdX
```

**Raid 10**

```
mdadm --create --verbose /dev/md0 --level=10 --layout=o3 --raid-devices=4 /dev/sdX /dev/sdX /dev/sdX /dev/sdX
```

#### **Stop raid:**

```
mdadm --stop /dev/md0
```

#### **Assemble raid:**

```
mdadm -A /dev/mdX /dev/sdaX --run
```

##### **Adding a drive in a failed raid:**

```command
mdadm --manage /dev/md0 --add /dev/sdb1
```

##### **Resize drives after a HDD swap to something larger**

```shell
screen
resize2fs `mount | grep "on / " | cut -d " " -f 1` && exit
```

<p class="callout info">Then check with "watch df -h" and watch it go up</p>

#### **Cloning a partition table** 

##### MBR:

<p class="callout info">X = Source (old drive), Y = Destination (new drive)</p>

```
sfdisk -d /dev/sdX | sfdisk /dev/sdY --force
```

##### GPT:

<p class="callout info">Install gdisk </p>

<p class="callout danger"><span class="s1">The first command copies the partition table of </span><span class="s2">sdX</span><span class="s1"> to </span><span class="s2">sdY</span></p>

```
sgdisk -R /dev/sdY /dev/sdX
sgdisk -G /dev/sdY
```

# MegaCli

#### Check raid card:

```
lspci | grep -i raid
```

#### Ubuntu/Debian:

```
apt-get install alien
# Convert to .deb
alien  -k --scripts  filename.rpm
# Install .deb
dpkg  -i  filename.deb
```

#### CentOS/Other:

[https://docs.broadcom.com/docs-and-downloads/raid-controllers/raid-controllers-common-files/8-07-14\_MegaCLI.zip](https://docs.broadcom.com/docs-and-downloads/raid-controllers/raid-controllers-common-files/8-07-14_MegaCLI.zip)

Clear all config

```
-CfgLdDel -Lall -aAll
-CfgClr -aAll
```

Physical drive information

```shell
-PDList -aALL
-PDInfo -PhysDrv [E:S] -aALL
```

<span class="s1">Virtual drive information</span>

```
-LDInfo -Lall -aALL
```

<span class="s1">Enclosure information.</span>

```p3
-EncInfo -aALL
```

Set physical drive state to online

```p3
-PDOnline -PhysDrv[E:S] -aALL
```

Stop Rebuild manually on the drive

```p3
-PDRbld -Stop -PhysDrv[E:S] -aALL
```

<span class="s1">Show rebuild progress</span>

```p3
-PDRbld -ShowProg -PhysDrv[E:S] -aALL
```

View dead disks (offline or missing)

```p6
-ldpdinfo -aall |grep -i “firmware state\|slot”
```

View new disks

```p6
-pdlist -aall |grep -i “firmware\|unconfigured\|slot”
```

Create raid 1:

```p7
-CfgLdAdd -r1 [E:S, E:S] -aN
```

Create raid 0:

```p7
-CfgLdAdd -r0 [E:S, E:S] -aN
```

Init ALL VDs

```
-LDInit -Start -LALL -a0
```

Init 1 VD

```
-LDInit -Start -L[VD_ID] -a0
```

<span class="s1">clearcache</span>

```p3
-DiscardPreservedCache -L3 -aN (3 being the VD number)
```

Check FW

```p1
-AdpAllInfo -aALL | grep 'FW Package Build'
```

<span class="s1">Flash FW</span>

```p1
-AdpFwFlash -f <Your rom file> -a0
```

Flash FW to older version

```
 -adpfwflash -f $ROMFILE -noverchk -a0
```

Check BBU

```
-AdpBbuCmd  -a0
```

Flash LED on HDD

```shell
-PdLocate -start -physdrv[E:S] -aALL
-PdLocate -stop -physdrv[E:S] -aALL
```

Scan Foreign

```shell
-CfgForeign -Scan -a0
```

Import Foreign

```shell
-cfgforeign -import -a0
```

Bad to Good

```shell
MegaCli -PDMakeGood -PhysDrv[E:S] -aN
```

Disable auto rebuild

```
-AdpAutoRbld -Dsbl -a0
```

Enable auto rebuild

```
-AdpAutoRbld -Enbl -a0
```

Check BBU

```
-AdpBbuCmd -a0
```

#### JBOD

Figure out the Enclosure Device ID

```
-PDList -a0 | grep -e '^Enclosure Device ID:' | head -1 | cut -f2- -d':' | xargs
```

Set all the drives to “Good”

```
-PDMakeGood -PhysDrv[$id:1,$id:2,$id:3,$id:4,$id:5,$id:6,$id:7,$id:8] -Force -a0
```

Check and see if JBOD support is enabled

```
AdpGetProp EnableJBOD -aALL
```

Turn JBOD support on

```
AdpSetProp EnableJBOD 1 -a0
```

Set each disk from above to be in JBOD mode

```
-PDMakeJBOD -PhysDrv[$id:1,$id:2,$id:3,$id:4,$id:5,$id:6,$id:7,$id:8] -a0
```

The syntax for checking a disk within a MegaRAID based controller is as follows via CLI:

<p class="callout info">This shows the "Device ID: X", Replace n with the Device ID</p>

```shell
-LdPdInfo -a0 | grep Id
```

```
smartctl -a -d sat+megaraid,n /dev/sg0
```

Disk missing - No automatically rebuilding

```
-PdReplaceMissing -PhysDrv [E:S] -ArrayN -rowN -aN
-PDRbld -Start -PhysDrv [E:S] -aN
```

For more see here: [https://www.broadcom.com/support/knowledgebase/1211161498596/megacli-cheat-sheet--live-examples](https://www.broadcom.com/support/knowledgebase/1211161498596/megacli-cheat-sheet--live-examples)