# RAID | MDADM

# Creating RAID and mounting it

Is \[[\[Formatting - Drives\]\] ](https://wiki.danicus.net/books/hardware/page/formatting-a-drive-in-linux "Formatting a drive in linux")needed? Do that first, then come back.

See if mdadm is installed or not  
`mdadm`

 If not, install it  
 `apt install mdadm`

Check for all storage drives in system  
`lsblk`

Create the RAID with the drive you are going to use  
`mdadm --create /dev/md111((create your own file name)) --level=5 --raid-devices=4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1`

Check to see if the array is in progress

```bash
cat /proc/mdstat
```

This is going to take a while... Once it is completed:

Check the block ID for the new virtual drive/s  
`blkid`  
  
Make a File System on that new drive  
`mkfs.ext4 /dev/md111` (find your own disk location)

mkfs.ext4 - .ext4 means the "type" of file. shown on "sudo blkin" then state locate of the file its going to be

Create a location to mount the new virtual drive/s  
"/" is a good place to start

Mount the RAID to the storage location  
`mount /dev/md111 /sirstorage`

Check to see if the RAID is in the location you created  
`df -h`  
`sudo mdadm --detail /dev/md111` &lt;----Local RAID location

Add array to the fstab file | this will mount the array every time the computer starts up. You can do this with as many mounts/drives as you like.   
`nano /etc/fstab`  
 look at the headers and include this under the correct header  
 File system: `/dev/md111` mount point: `/storage/location` type: `ext4` options: `errors=remount-ro` put zeros on the rest.

[![image.png](https://wiki.danicus.net/uploads/images/gallery/2023-03/scaled-1680-/YNaimage.png)](https://wiki.danicus.net/uploads/images/gallery/2023-03/YNaimage.png)

Test to see if array mount worked  
`umount /storage/location`  
`mount -a`

\*\*Reboot!!\*\*  
 Reboot the system, just in case. Make sure the array is still mounting after reboot. If its there, you are good to go son!

Need to extend your RAID? Go find that one. "Extending RAID"

# Extending RAID

Prepare new disk  
 Need to partition? Do it now. I'll wait...

Setup: The current RAID has 4 drives and we want to add a 5th drive. The current array is "md111" and we have already checked drives on the system `lsblk` to see which drive we will be adding "sdd1"

Add disk to RAID  
`mdadm --add /dev/md111 /dev/sdd1`

mdadm --add /current/drive/array (array that already has the other raid dirves in it) /new/drive/to/add (the 1 drive that you will be adding)

Grow RAID:  
`mdadm --grow --raid-devices=4 /dev/md111` This will grow your current array to accept a new drive

Now that you have expanded the underlying partition, you must now resize your filesystem to take advantage of it.  
You may want to perform an fsck on the file system first to make sure there are no underlying issues before attempting to resize the file system

Integrity Check: `e2fsck -f /dev/md111`

Resize array: `resize2fs /dev/md111`

Mount it: `mount /dev/md111 /your/new/local/location`

Check RAID rebuild status or Current status  
`cat /proc/mdstat`

Sources you can use:  
[https://raid.wiki.kernel.org/index.php/Growing](https://raid.wiki.kernel.org/index.php/Growing)

# Troubleshooting RAID

Setup: Our current RAID array with 5 drives in it is "md111". Its location is /dev/md111

Resize the blocks  
`resize2fs -f /dev/md111`

Stop Array  
`mdadm --stop /dev/md111`

Auto scan for arrays  
`mdadm --assemble --scan`

Once the new mdadm.conf was ready, execute "sudo update-initramfs -u" This updats the conf file used by initramfs.  
`sudo update-initramfs -u`