RAID 0 on Raspberry Pi

How I tried to connect four 8GB flash drives into RAID0 array. It works!

Created
2015
Updated
June 30, 2016

My Hardware

This how-to can be applied on different ranges of computers and operating systems. This is what I was trying it on.

RAID 0 It!

Some inspiration: http://www.tecmint.com/create-raid0-in-linux/ and https://wiki.archlinux.org/index.php/RAID.

Partition Flash Drives

Destroy boot sector, partition table, etc. (see openSUSE Live USB Stick SDB - How to recover flash drive).

$ sudo dd if=/dev/zero of=/dev/sdX count=100

Create partitons. It's better to use partitions of the same size on all drives (yes, even the same flash drives have different number of sectors, at least mine do), leave about 100 MB free at the end. Start with the smallest drive, set last sector -100M and set the same sector number on other drives.

$ sudo gdisk /dev/sda
  1. Create new GPT table: o
  2. Create new partition: n, last sector -100M, HEX code fd00
  3. Write: w

Set Up RAID

First, we need to install mdadm utility on our system.

$ sudo apt-get update && sudo apt-get install mdadm

Create /dev/md0 device.

$ sudo mdadm --create --verbose --level=0 --metadata=1.2 --raid-devices=4 /dev/md0 /dev/sd[a-d]1

Check background resync of the array.

$ cat /proc/mdstat
$ sudo mdadm -E /dev/sd[a-d]1
$ sudo mdadm --detail /dev/md0

Examine created RAID.

$ sudo mdadm --examine /dev/sd[a-d]
$ sudo mdadm --examine /dev/sd[a-d]1

Format

To create f2fs file system on /dev/md0, run this command.

$ sudo mkfs.f2fs /dev/md0

Mount it

Create mount point and mount our raid device.

$ sudo mkdir /mnt/sandisk-raid0
$ sudo mount /dev/md0 /mnt/sandisk-raid0

Make it Permanent

NOTE: There is a problem with Raspberry Pi 2 booting too fast for USB drives to be recognized during boot time. Add rootdelay=5 to the end of cmdline.txt".

Add entry to fstab.

/dev/md0        /mnt/sandisk-raid0 f2fs defaults          0       0

Check mount entry.

$ sudo mount -av

Save mdadm configuration.

$ sudo cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf.zaloha
$ sudo sh -c "mdadm --detail --scan >> /etc/mdadm/mdadm.conf"

Reassemble

If you want to stop RAID and start it again, here is how.

$ sudo mdadm --stop /dev/md0
$ sudo mdadm --assemble --scan
# OR
$ sudo mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1