Create a Raspberry Pi raid array with USB HDDs using mdadm
Create a Raid 0, or Raid 1 or Raid 5 disk array with a Raspberry Pi 2. Once the Raid array is assembled, you could then create a Network attached files server or mini dna server. This project is ideal for when you want to combine the capacity of a number of drives to create a single large volume or when planning to create a file server that stores important data like family photographs or documents.
Before you begin, please read about about raid assemblies, their advantages and disadvantages. Also read about data back ups using raid compared to redundant or incremental backups.
This tutorial uses mdadm and covers setting up a raid 0 array ( where two hard drives of 1tb each are combined to form a single volume that has a 2gb capacity ). You could very easily setup a raid 1 or a raid 5 assembly by replacing the mdadm configuration. Mdadm is a Linux utility used to manage and monitor software RAID devices.
Please bookmark and read the Mdadm cheat sheet while configuring the Raid assembly.
- Connect Hard Drives to the Raspberry Pi .
- Install mdadm to create the raid assembly
- Configure the raid assembly.
Time and Difficulty :
- Time : 15 to 30 mins once you have the Raspbian Image file and the rest of the software.
- Newbie Difficulty level : Moderately easy ; Will need to use terminal and type in commands.
What you will need :
- Raspberry Pi 2 Model B or one of its clones like Banana Pi M1 or M2 or Banana Pro.
- Ethernet connection or a supported USB Wifi adapter for the Pi
- SD or Micro SD Card that fits into your Pi (4GB or above is recommended)
- SSH connection to the Pi or a USB Keyboard and Mouse
- Connection to a TV or Monitor, if, not connecting via SSH.
STEP 1 : Update the Pi
Log in to Raspbian and enter the following commands :
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
The steps above will update the software and the raspbian distribution to the latest available.
reboot your pi with
STEP 2 : Connect the USB HDDs
Connect the USB hard disk to the Pi via a powered USB hub. In this tutorial, we are using 2 WD portable drives of 1 TB capacity each. Run the following commands at the terminal
sudo fdisk -l (To list the drives connected to the system. The two USB drives are shown as /dev/sda1 and /dev/sdb1)
STEP 3 : Install Mdadm
To install mdadm, you will need to elevate to root privileges. Enter the following commands at the terminal.
sudo -i(Elevate current login to root level)
apt-get install mdadm(Install mdadm, Choose the default “All” during installation to proceed. )
mdadm -Cv /dev/md0 -l0 -n2 /dev/sd[ab]1( configure mdadm and create a raid array at /dev/md0 using raid0 with 2 disks ; sda1 and sdb1. To create a raid1, replace the line to read mdadm -Cv /dev/md0 -l1 -n2 /dev/sd[ab]1 )
fdisk -l(Use fdisk to check the drives, once the Raid array is created. At the very end you will see a new disk /dev/md0 with the new capacity. )
- once mdadm is done, use fdisk -l to verify the new raid drive
- The new Disk /dev/md0 doesn’t yet contain a valid partition table
cat /proc/mdstatto check the status of the mdadm and drives.
mkfs /dev/md0 -t ext4(To create an ext4 file system at the newly created raid drive)
- use makefs to create an ext4 file system on the raid drive
mdadm --detail /dev/md0to check list the details of the raid array.
Use mdadm –detail /dev/md0 to check the status of the raid
Update : This a top tip from AxisMann in the forum below. Thanks AM!