Ubuntu: USB-stick (thumbdrive) raid
Posted: Thu Aug 23, 2007 3:38 pm
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:
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:
Fdisk uses single letters as commands, so type the following sequence to delete and re-create the primary partition:
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:
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:
--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:
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:
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":
Now add this line to /etc/fstab:
Then mount it:
7) That's it. you're done. If you're curious, you can do some benchmarking on this new device:
Here are the results for mine:
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:
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:
This will list all devices matching the regexp /dev/sd[a-z][0-9] and their membership in an array.
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
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
Code: Select all
d n p 1
Change the type of this partition to "Linux Auto RAID", which has the number "0xFD", by entering:
Code: Select all
t fd
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
--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
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
First, create the mountpoint. e.g. "/mnt/raid":
Code: Select all
mkdir /mnt/raid
Code: Select all
/dev/md0 /mnt/raid ext2 user 0 0
Code: Select all
sudo mount /mnt/raid
Code: Select all
hdparm -tT /dev/md0
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./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
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
( 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]