Ubuntu: USB-stick (thumbdrive) raid

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Ubuntu: USB-stick (thumbdrive) raid

Post by ^rooker »

Since prices of thumbdrives dropped tremendously within the last few months, I thought it would be interesting to buy a bunch of them and fuse them together in order to have a reasonable sized system disk.

Yesterday I bought 3x 2GB (~17EUR each).

The following howto describes the few steps necessary to create a single drive, using linux' awesome software-raid features:

The operating system I did this on was Ubuntu Dapper Drake 6.06 (based on infos from Derek Vadala's article about mdadm) - and since mdadm is *the* tool for this, it should be almost the same on other distros, too.

1) Load the necessary RAID modules:

Code: Select all

modprobe md-mod
modprobe raid0
2) Find out the device names of the thumbdrives.
They should be something like /dev/sd?, - I usually use the output of "dmesg | tail" to find this out.

3) Remove the existing FAT32 (vfat) partitions on the sticks and create a new one of type "0xFD" (Linux Auto Raid). Perform these steps for each USB thumbdrive:

Code: Select all

fdisk /dev/sda
Fdisk uses single letters as commands, so type the following sequence to delete and re-create the primary partition:

Code: Select all

d n p 1
Now you should have a new partition of type "Linux". Type "p" to show the partition table.
Change the type of this partition to "Linux Auto RAID", which has the number "0xFD", by entering:

Code: Select all

t fd
4) Create the RAID:
mdadm can take long (readable) arguments, or their short equivalents. I'll present both - so please do either (a) or (b):

a) readable:

Code: Select all

mdadm --create --verbose --auto /dev/md0 --level 0 --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1
--create: initializes the raid array
--auto: create the node "/dev/md0" if necessary
--verbose: outputs information during the process
--level: defines the raid level to be used. 0 means striping, whereas 1 would be mirroring. (See the article about RAID on Wikipedia for more information about the different levels of raiding)
--raid-devices: The number of devices to be used in this array

b) less typing:

Code: Select all

sudo mdadm -Cv --auto /dev/md0 -l0 -n3 /dev/sd{a,b,c}1
This is exactly the same as the long version above.
C..create, v..verbose, l..level, n..raid-devices
and as you can see, the devicenames support shell-magic.

5) After the raid array has been initialized correctly, you must format it to the desired filesystem. I chose ext2:

Code: Select all

mkfs.ext2 /dev/md0
6) This is it. All you have to do is mount it in order to use it, so either add a new line in /etc/fstab - or do it manually. I prefer the fstab way, because then non-root users can mount it, making it easier accessible later on.

First, create the mountpoint. e.g. "/mnt/raid":

Code: Select all

mkdir /mnt/raid
Now add this line to /etc/fstab:

Code: Select all

/dev/md0        /mnt/raid       ext2    user    0       0
Then mount it:

Code: Select all

sudo mount /mnt/raid
7) That's it. you're done. If you're curious, you can do some benchmarking on this new device:

Code: Select all

hdparm -tT /dev/md0
Here are the results for mine:
/dev/md0:
Timing cached reads: 880 MB in 2.00 seconds = 439.97 MB/sec
Timing buffered disk reads: 74 MB in 3.05 seconds = 24.24 MB/sec
These results can be compared to an UDMA 100 disk - I know that it ain't too fast, but it's super-silent, requires less power and ... I like it.


8) Mounting it again after a reboot:
Either let enter this new raid array in /etc/mdadm/mdadm.conf or re-assemble the array like this:

Code: Select all

sudo mdadm --assemble --auto /dev/md0 /dev/sd{a,b,c}1
The string "/dev/sd{a,b,c}1" must be changed to fit your needs. If you're no fan of regular expressions, you can also simply pass each device as a separate argument.


( APPENDIX )
a) One thing I want to try is, buying a USB-hub for connecting all the USB sticks and then plug it into another linux system that has software RAID support. If I understood the docs correctly, it should be functional there, too (because the array information is stored on the thumbdrives and not on the host system).

b) You can find out which devices belong together by running:

Code: Select all

mdadm --query /dev/sd[a-z][0-9]
This will list all devices matching the regexp /dev/sd[a-z][0-9] and their membership in an array.
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply