RAID Array

Thursday, Jul 2, 2026

I made a RAID Array with my Raspberry Pi

I had a problem with my NAS on my Raspberry Pi, for some reason it was running very slow and causing the Pi to crash randomly. It was just a single usb hard drive using Samba. So I decided to replace it with a RAID, in order to actaully get the Pi back in working order I had to reimage it. (I think this actually fixed my issue.) Then I got started making the RAID drive

Steps To Build Initially

  1. Installed mdadm using apt
    1. sudo apt update
    2. sudo apt install mdadm
  2. Then I had to attach and reformat the drives, the Raspberry Pi automatically mounted them so I had to unmount first.
    1. sudo umount /dev/sdX
    2. sudo mkfs -t ext4 /dev/sdX
  3. Once I had them all formated and attached not mounted
    1. sudo mdadm --create --verbose /dev/md0 --level=6 --raid-devices=X /dev/sdX Fill in the X with the drive names that you have, and you can change the name /dev/md0 to something else if you like.
  4. In order to keep it across reboots you need to run
    1. sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf This adds the drive information to the configuration file. tee -a will add the output to the end of the file.
    2. sudo update-initramfs -u This updates the initial file system for the Raspberry Pi.
    3. echo '/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab This adds it to the fstab file, which is what the computer using to mount the file systems on start up. IMPORTANT! nofail is important! your system can fail to boot if it doesn't detect the file system with out it.

Steps to add Drives

  1. Plug it in and find it with lsblk
  2. If it's mounted unmount it with sudo umount /dev/sdX
  3. Reformat it with sudo mkfs -t ext4 /dev/sdX
  4. Add it to the array with sudo mdadm --manage /dev/md0 -add /dev/sdX
  5. Then you can decide to either increase the array size or keep it as a spare
    1. If you want to increase the size sudo mdadm /dev/md0 --grow --raid-devices=N with N being the new number of drives.
    2. Then you need to refresh how big the computer thinks your drive is sudo resize2fs /dev/md0

This was a fun little project, I hope this can be a good way to keep my files safe and find a use for old usb drives that I have laying around. I used this guide a lot Digital Ocean Guide