Rackspace Community

Configuring a Software RAID on a Linux General Purpose Cloud Server

Article ID: 3752

Last updated on December 11, 2014

Authored by: Timothy Pownall

This article will demonstrate how to put multiple data disks on a General Purpose server into a RAID level 0. We will mount a single data disk and perform read and write tests, then continue by putting two data disks into a RAID 0.

A RAID 0 stripes (combines) two disks to look like one drive to the system, usually increasing performance (particularly read access). While a RAID level of 0 only stripes the disks and offers no data redundancy, the hypervisor (host server) is backed by a RAID 10. This RAID 10 provides redundancy for your data on the backend.

Prerequisites

Creating a RAID level 0 requires a General Purpose server with at least two data disks.

To configure the RAID we will use the mdadm software RAID utility, which may need to be installed.

Redhat/Centos/Fedora/Scientific Linux mdadm installation

sudo yum install mdadm

Ubuntu/Debian mdadm installation

sudo apt-get update
sudo apt-get install mdadm

Identifying available data disks

Disks on Linux are referenced using their device name. The/dev/xvda device is your system disk and contains your operating system. We will use the fdisk utility to identify your data disk devices (usually /dev/xvde and /dev/xvdf).

sudo fdisk -l

The output will list full details about the disks attached to the system. One disk entry would look like this:

The beginning of the second line in the example shows the device name (md0), which means we can reference the array as /dev/md0.

Partitioning the RAID 0

Once the array is created we can partition it to make a file system. We'll use the fdisk utility to create a single partition on the RAID 0.

sudo fdisk /dev/md0

After displaying some information about the device we're editing (the array), you'll see a command prompt.

We'll need to create a new partition using all available disk space, then write the changes to the array's partition table.

Start by entering "n" for new partition, then "p" for a primary partition, and "1" for the partition number. Just hit enter when asked for the starting and ending cylinders so fdisk will use the defaults, filling the disk with the single partition. Once the partition is created enter "w" to write the changes to the disk.

After writing the partition table, fdisk should exit. Running fdisk again should let you see the array and its new partition (along with the partition's device name).

sudo fdisk -l

Creating the file system on the RAID 0

For the purposes of this article we'll use ext4 for our demonstration and performance testing.

Note: If you use ext4 on your array, make sure your system supports it. Recent distributions support ext4 by default, but if you're using an older base operating system (like CentOS 5.3) the included kernel and disk formatting utility may not support ext4. In this case, it's safer to use ext3 (with the mkfs.ext3 command).

Creating the file system will be easy and seamless. Run the appropriate mkfs command for the file system (mkfs.ext4 to format as ext4, for example) on the array's partition, usually /dev/md0p1.

sudo mkfs.ext4 /dev/md0p1

With the new file system created you are free to mount the array to any mount point that you would like. Edit your /etc/fstab file to add a line for the new disk. If we wanted to mount the disk on our example system on /var/lib/mysql, we would add the following line:

/dev/md0p1 /var/lib/mysql ext4 defaults,noatime 0 2

To mount the RAID 0 after saving the fstab file, run:

sudo mount -a

Performance testing

For the performance testing on our example RAID 0 we ran several read and write tests, with the following results (including commands and output):

Our results from the testing showed a 16% increase in reads while utilizing (2) SSDs in a RAID 0, with a 2% decrease in write performance. The performance gains from the reads is substantial enough to warrant utilizing the RAID 0 for most purposes, but if you're running an application that performs more writes than reads you may benefit more from using the data disks stand-alone instead of going with the RAID 0 option.