Software RAID 5 on Linux is the best RAID. It's cheaper than hardware RAID with a proper 400$ controller. It has better speed and compatibility than the motherboard's and a cheap controller's FakeRaid. And it's easy, we just need 3 HDDs and a few hours. Let's make a software RAID 5.
We prepared this guide on Ubuntu 14.10 and Linux Mint 17.1. It should also work with recent earlier and later versions, and on most distributions based on Debian/Ubuntu.
If something doesn't work for you, leave us a comment.
- 1 Will a Linux software RAID 5 work in Windows?
- 2 How to Install mdadm
- 3 How to install gparted
- 4 How to create a Software RAID 5 on Linux
- 5 And now we wait
- 6 Format and mount the array
- 7 Auto-mount the software RAID 5 on startup
Will a Linux software RAID 5 work in Windows?
Software RAID in Linux is based on mdadm, which is an application unique to Linux. It's impossible for Windows to recognize or access an mdadm RAID.
On a future guide we will cover the ways to create a software RAID in Windows.
How to Install mdadm
mdadm (Multiple Device ADMinistrator) is the prevalent solution for creating a software RAID on Linux. It's a simple and powerful application. We can use it not only for software RAID 5, but for pretty much any level of RAID, simple or nested.
Before we create our first array, it's always a good idea to do a full update.
We just need to open a terminal with ctrl+alt+T and type:
sudo apt-get update && sudo apt-get dist-upgrade -y
After the update, we reboot the system. Once we log back in, we open a new terminal and type:
sudo apt-get install mdadm -y
As a part of the installation, the mdadm installer will show some pointers about setting up a mail server configuration.
This is mostly used in servers, to automatically email the administrator in case a disk or an array fails. It could be useful at home too, but it is a bit complicated. We will cover the mail configuration in detail on a separate guide.
So, for the time being, we use the Tab button to select OK. On the next screen we choose "No configuration" and Tab to OK.
How to install gparted
The Gnome Partition Editor, or GParted, is the best GUI partitioning tool in Linux. To install it, we type at the terminal:
sudo apt-get install gparted -y
We can start gparted with:
How to create a Software RAID 5 on Linux
Software RAID 5 with mdadm is flexible. We can use full disks, or we can use same sized partitions on different sized disks. We just need to remember that the smallest of the disks or partitions dictates the array's capacity.
The array's capacity in RAID 5
For RAID 5, the formula for the total capacity is:
RAID = (total number of the disks -1) * (smallest disk's capacity)
If we have three 1TB disks, the total array capacity will be:
(3 - 1) *1 = 2TB
If we have three 1TB disks and one 500GB disk, the total array capacity will be:
(4 - 1) * 0,5 = 1,5TB
Preparing the disks
First off, we start GParted and make sure all the disks for the software RAID 5 are visible to the system.
In the example we will create a 2TB software RAID 5 with three 1TB disks, /dev sdb, /dev/sdc, /dev/sdd.
We will use the full disks, but we could also create three equal partitions and select them for the RAID.
If the disks we use are brand new, and have the red exclamation mark next to the "unallocated" label, we need to create a partition table on each, through the Device menu.
For disks less than 2TB we select msdos.
Disks more than 2TB require a gpt partition table.
After we created the partition table, and with the red exclamation mark gone, we right-click and create a new partition on each disk.
The file system we choose is not important, since creating the software RAID 5 will completely wipe-out the selected partitions' content.
Finally, we apply the changes.
We also make sure to remember the partitions names. On disk /dev/sdb the first partition will be /dev/sdb1, on the /dev/sdc it will be /dev/sdc1 etc.
Caution: We don't mount those new disks/partitions. We need them unmounted to create the software RAID 5.
Make sure you have enough time
The array building procedure will take hours. It's automated, so we don't need to sit in front of the PC. But we can't shut down the computer or restart it either. And we can't pause or stop the procedure.
It took mdadm about seven hours to create a 2TB software RAID 5 with three 1TB disks. A bigger array could take more than twenty hours to build.
And, we cannot stress that enough, there is no way to pause or stop the array building. If this happens by force - e.g. we shut down the computer or the power goes out - then we are in trouble.
Recovering the array is more complicated that creating it in the first place. Also, it won't resume from where it was, it will restart from the beginning.
Creating the software RAID 5
A single command is enough to create the array. Ignore that it wraps because of the page width, it's a single-line command.
sudo mdadm --create /dev/md0 --chunk=64 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1
In this command:
- • md0 is the name we selected for the array, always in /dev/
- • --chunk=64 is the stripe size. 64KB is a good value for most uses.
- • --level=5 is the RAID level
- • --raid-devices=3 is the number of disks or partitions
- • /dev/sdb1, /dev/sdc1, /dev/sdd1 are the names of the partitions. If we are using full disks, we treat each of them as a single partition.
Mdadm will show us the size of the selected partitions and ask is if we want to continue creating the array. We type "y" for "yes".
The building of our software RAID 5 has begun.
And now we wait
Even though the software RAID 5 building is under way, mdadm won't show its progress. To watch the procedure, we type:
sudo watch tail /proc/mdstat
This will show the RAID building, and will refresh every 2 seconds.
As we mentioned, for an average array, this could take all night. In the example, on 3:33 it was on 8.2%. With the current speed, it would take nearly four and a half hours.
The thing is, the speed doesn't remain constant for all the array. More than five hours later, on 8:49, the array still wasn't done, with another 20% to go.
The procedure ended at around 10:15, about 7 hours after it started for a 2TB software RAID 5.
Format and mount the array
Once the array is ready, we need to format it with the file system of our choice. We can't format it though GParted, so we need to do it with a command:
sudo mkfs.ext4 /dev/md0
The array will appear on our sidebar.
Now, we must create a folder to mount it. A good choice is the /media/ folder, where the external storage gets mounted.
sudo mkdir /media/Raid
We mount the array with:
sudo mount /dev/md0 /media/Raid
Finally, we take full ownership of the RAID, to get write access.
sudo chown -R (username):(username) /media/Raid
Now we can create files and folders as we wish. We can also delete the lost+found folder.
Auto-mount the software RAID 5 on startup
For the final step, we will set up the software RAID 5 to auto-mount at boot time.
First, we need to find the UUID of our array. We do that with the command:
sudo blkid | grep /dev/md0
This will show a multi-character text, which is unique for our RAID. We select it, right-click and copy it.
Then we open the /etc/fstab file as root with a text editor, e.g. gedit.
sudo gedit /etc/fstab
At the end of the file we add:
UUID=(our UUID) /media/Raid ext4 defaults 0 2
We save the file, and that's it.
Now, on each boot the RAID will already be mounted for us at the /media/Raid folder.