RAID Server commands | tw_cli | MegaCli | mdadm
Tags: linux, raid, sysadmin, server
Published: 2023-12-21 06:30:26

---
title: RAID Server commands | tw_cli | MegaCli | mdadm
published: true
description: This post covers the important commands of the RAID server of MegaCli, tw_cli, and mdam
tags: #linux #raid #sysadmin #server
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttd2w776rmrjhuzs5mpt.png


# Use a ratio of 100:42 for best results.
# published_at: 2023-12-21 06:10 +0000
---

#### Basic terms


- RAID: Redundant Array of Independent Disks. It's a data storage virtualization technology.
- Controller: The hardware that manages the RAID array.
- Unit: A virtual drive that consists of one or more physical drives.
- Drive: A physical hard drive or SSD.
- Rebuild: The process of recreating lost data on a new drive.
- Parity: A mathematical method to recreate data lost from a disk in the array.
- Striping: Data is split across multiple disks.
- Mirroring: Data is duplicated on two or more disks.



#### Debugging

When debugging, it's important to check the status of your RAID controller and units regularly. If you see a status of `DEGRADED`, this means one or more drives have failed. If you see a status of `REBUILDING`, this means the RAID is currently rebuilding data on a new drive.

## MegaCli Commands

- **View Adapter Information**:
    
    ```bash
    MegaCli -AdpAllInfo -aALL
    ```
    
- **View the Configuration of the Controller**:
    
    ```bash
    MegaCli -CfgDsply -aALL
    ```
    
- **List All Drives**:
    
    ```bash
    MegaCli -PDList -aALL
    ```
    
- **View the Physical Disk Information**:
    
    ```bash
    MegaCli -PDInfo -PhysDrv [Enclosure:Slot] -aALL
    ```
    
- **Check the Virtual Drive (Logical Drive) Information**:
    
    ```bash
    Copy codeMegaCli -LDInfo -Lall -aALL
    ```
    
- **View the Battery Backup Unit (BBU) Status**:
    
    ```bash
    MegaCli -AdpBbuCmd -aALL
    ```
    
- **Check for Consistency of RAID Configuration**:
    
    ```bash
    MegaCli -LDCC -aALL
    ```
    
- **Rebuild a Drive**:
    
    ```bash
    MegaCli -PDRbld -Start -PhysDrv [Enclosure:Slot] -aALL
    MegaCli -PDRbld -Stop -PhysDrv [Enclosure:Slot] -aALL
    MegaCli -PDRbld -ShowProg -PhysDrv [Enclosure:Slot] -aALL
    ```
    
- **Identify a Failed Drive**:
    
    ```bash
    MegaCli -PDList -aALL | grep -E 'Slot Number|Firmware state'

    # OR
    MegaCli -CfgDsply -aALL | awk '/Physical Disk:/{print ""; print; next} /Slot Number|Firmware state|Enclosure Device ID:|Inquiry Data|Device Id/{print}'

    ```

- **Replace a Failed Drive**:
    
    ```bash
    MegaCli -PDOffline -PhysDrv [Enclosure:Slot] -aALL
    MegaCli -PDMarkMissing -PhysDrv [Enclosure:Slot] -aALL
    MegaCli -PDPrpRmv -PhysDrv [Enclosure:Slot] -aALL
    ```
    
- **View Event Log**:
    
    ```bash
    MegaCli -AdpEventLog -GetEvents -f events.log -aALL
    ```
    
- **Silence Alarm**:
    
    ```bash
    MegaCli -AdpSetProp AlarmSilence -aALL
    
    ```
    

## mdadm commands

- To create a RAID 5 array:

```bash
mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1

```

- To view the status of the RAID:

```bash
cat /proc/mdstat

```

- To stop a raid array:

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

```

- To remove a failed disk:

```bash
mdadm --manage /dev/md0 --remove /dev/sda1

```

- To add a new disk to the array:

```bash
mdadm --manage /dev/md0 --add /dev/sdd1

```

Please note these commands are general and your RAID setup and commands may differ.



## tw_cli Commands

`tw_cli` is a command line tool for managing 3ware RAID controllers. Here are some basic commands:

- To check the status of the RAID controller:

```bash
tw_cli info c0
```

- To check the status of a unit:

```bash
tw_cli /c0/u0 show
```

- To check the status of a drive:

```bash
tw_cli /c0/p0 show
```

- To silence an alarm:

```bash
tw_cli /c0 silence
```

- To rebuild a unit:

```bash
tw_cli /c0/u0 start rebuild disk=1
```




- To delete a unit:

```bash
tw_cli /c7/u2 del
```

- To disable a drive:

```bash
tw_cli /c0/p1 remove
```

- To enable a drive:

```bash
tw_cli /c0/p1 add
```

- To show events:

```bash
tw_cli /c0 show events
```

- To show all physical drives:

```bash
tw_cli /c0 show phy
```

## Conclusion

Understanding the RAID server and different command tools is important to manage, maintain, and monitor the RAID Server controllers and units to prevent data loss and smooth operation. 


### About me
I was recently hired as a System Administrator to handle a variety of RAID servers. My job involves a mix of analyzing and setting up these servers, keeping an eye on their performance, writing scripts to make things run smoother, and putting together dashboards to keep everything easy to track and manage.

My Email: hi@ericgit.me