Skip to content

How to create a raid array with Raspberry Pi using external USB HDDs

In this tutorial you’ll learn, how to add HDD’s to your raspberry pi and create a raid array with themby using mdadm.

Navigation
  1. Set up hardware
    1. Raspberry PI
    2. HDDs
  2. Make RAID Assembly

What you need

Set up Hardware

Raspberry Pi

  1. Install Raspbian
  2. Update Pi
  3. Setup SSH
  4. Prepare Pi for Raid

For the first three steps, you’ll need an HDMI Monitor, USB Mouse and an USB Keyboard.

And of course the Raspberry Pi and the SD Card. Make sure your Raspberry is connected to the internet (or at least internal network).

Install Raspbian

In order to follow the rest of the steps, you’ll need to install the Raspbian Distribution. You can read how on the official website, or in this tutorial for windows and mac.

Update Pi

Log into your Raspbian and enter the commands to update the Pi:

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get dist-upgrade

Now reboot your Pi using sudo reboot.

Setup SSH Connection

In order to let your “server” work headless, you need to set up SSH. Fortunately there are tutorials for this on the official page:

Prepare Pi for Raid

Add rootdelay=5 to the cmdline.txt file in the /boot directory to prevent issues with the raspberry booting up to fast for the raid.

HDDs

Connect the USB HDDs via the powered USB-Hub to your Pi. To check if your drives are beeing recognized run sudo fdisk -l. They should be called something like /dev/sda1, /dev/sdb1 or similar.

If they are not shown, maybe this superuser post can help you!

Make RAID Assembly

To install run sudo apt-get install mdadm. Then configure it following the steps below:

  1. Run sudo mdadm -Cv /dev/md0 -l0 -n2 /dev/sd[ab]1 (or whatever your drives are called). This will create a raid0 array with the disks sda1 and sdb1. To create an other raid type change the flag -l0 to -l1 for a raid1 and so on. (basicaly -ln = raidn).
  2. As soon as mdadm is done, use sudo fdisk -l to check if the raid drive exists. Look if /dev/md0 is the size of both your drives.
  3. Use sudo mkfs /dev/md0 -t ext4 to create an ext4 filesystem on the raid drive. You can change the type of filesystem according to your needs.
  4. Check the raid with sudo mdadm --detail /dev/md0.

If you liked this tutorial, please check out Project Pi. My Source for this tutorial.

Published inDIYHardwareLinuxTutorials

Be First to Comment

Leave a Reply

%d bloggers like this: