Linux USB Raid HOWTO

This is a proof of concept HOWTO on how to build a RAID array out of USB sticks. This has no real practical application in the real world, but it's pretty cool that you can do it. USB does not make the best transfer method for a speedy filesystem.

Step #1:

Install all the USB sticks you want to build a RAID array on, and verify that the kernel sees all of them. Running fdisk -l should list all available paritions. In my situation I have four USB sticks installed: /dev/sdi, /dev/sdj, /dev/sdk, /dev/sdl.

Step #2:

Create a partition on the smallest disk. Since all the pieces of the RAID array have to be the same size we'll start with the smallest piece. Use fdisk to make the first partition (in my case /dev/sdl1).

Step #3:

Copy the partition scheme to the other USB sticks with sfdisk. You can use sfdisk to dump the partition scheme of the first stick and then use that as a template for the other sticks.

sfdisk -d /dev/sdl | sfdisk /dev/sdi
sfdisk -d /dev/sdl | sfdisk /dev/sdj
sfdisk -d /dev/sdl | sfdisk /dev/sdk

Step #4:

Create the RAID device. In my case I'm creating a RAID5 device (--level 5) with the four partitions that we created in the previous step.

mdadm --create /dev/md8 --raid-devices=4 --level=5 /dev/sdi1 /dev/sdj1 /dev/sdk1 /dev/sdl1

Step #5:

Create a filesystem on your newly created RAID device.

mkfs.ext3 /dev/md8

Step #6:

Mount your newly created RAID array so we can copy some files over to it.

mkdir /mnt/tmp
mount /dev/md8 /mnt/tmp

Step #7:

Test the new RAID by creating some files on the array.

dd if=/dev/urandom of=/mnt/tmp/100mb.bin bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 60.9338 s, 1.7 MB/s

Step #8:


Other fun things to try:
  1. Simulate a disk failure by removing one of the USB sticks
  2. Recover from the failure with: mdadm -a /dev/md8 /dev/sdk1
  3. Check on the health of your array: mdadm --detail /dev/md8 - 2009-08-21