Over the course of recovering my file server, I needed to setup a RAID 0 array real quick, but had no hardware ATA RAID controllers available. Fortunately, Linux has an easy solution.
If you’re using a default distribution kernel, you probably already have support for Linux software RAID. If not, build a kernel with Multi-device support (RAID and LVM) and select all the options therein. Feel free to wade through the help and select only those you want, but it doesn’t hurt to have them all.
Under Debian GNU/Linux, install the raidtools2 package to get access to the commands necessary to build the array.
Now, you can create your array.
nebula:~# cat /proc/mdstat
Personalities : [raid0]
read_ahead 1024 sectors
md0 : active raid0 hdd1[1] hdc1[0]
234436352 blocks 128k chunks
unused devices:
Assuming you already have two or more drives available, create one or more partitions you wish to run RAID 0 on. Linux’s software RAID implementation uses partitions, not whole disks, so you must create partitions on each device according to your tastes. For example I merely created a single partition that encompassed the whole disk for each of my drives. Make sure you set the partition type to ID fd which is Linux raid autodetect.
Now, edit your /etc/raidtab file. Much like /etc/fstab, this file is critical and must be kept in sync with however your array is configured. The tools will often look to this file before performing operations. (For example, if one drive moves to a different controller, the array will be marked as dead. You will need to force mkraid against your /etc/raidtab, which must be updated to reflect this important change.)
raiddev /dev/md0 raid-level 0 nr-raid-disks 2 nr-spare-disks 0 chunk-size 128 persistent-superblock 1 device /dev/hdc1 raid-disk 0 device /dev/hdd1 raid-disk 1
The configuration is fairly self explanatory. Setting up RAID 1, which offers fault tolerance for a single disk, would be configured in a nearly identical fashion. The only difference is you’d raid-level to 1. Linux software RAID also supports RAID 5 and nesting arrays, so you can create a RAID 1+0 if you’d like.
Finally, run mkraid /dev/md0 to create your first software RAID device. This probably won’t work if your distribution does not setup those /dev entries by default, so you’re on your own in that case. If you wish to create more than one, substitute the zero above for the next sequential number. Or, you can pick some other number, such as the partition number returned by fdisk if that’s helpful.
Debian GNU/Linux’s raidtools2 comes with the necessary init scripts for the array to be brought up and down automagically.