Creating RAID 1 Storage

ubuntuIf you are using Ubuntu as a file server, you will probably benefit from creating some RAID storage for your server.  This article describes the process for creating a RAID 1, but RAID 0, 5, 6, 10 etc are all possible.  I've used Ubuntu 14.04 LTS for writing this article.


Prerequisites

This article assumes that you've installed Ubuntu on one hard disk, and have added at least two blank hard drives, to be used for RAID storage.

 

mdadm

We will start by installing mdadm, the RAID configuration tool for Ubuntu.

$ sudo apt-get install mdadm

You can select No configuration for email, unless you require email notifications.

 

Status

A good place to start is by checking the current status of your RAID storage.

$ cat /proc/mdstat

If you haven't yet created any RAIDs you should see the following...

Personalities :
unused devices: <none>

 

Preparing Hard Disk Partitions

In order to create a RAID we first need to prepare the new physical hard drives.  Start by confirming that the hard drives are accessible by Ubuntu.

$ sudo cat /proc/partitions

You should see various partitions for sda, and your two new hard drives as sdb and sdc.

Now we need to create a new partition on each drive.  We'll start with sdb.

$ sudo fdisk /dev/sdb

 Next type the following combination of keys, to create a new (n) primary (p) partition, labelled number 1 (1).  You will also use the default start and end sectors.

n
p
1
Return
Return

Next type the following combination of keys, to change the partition type to Linux RAID autodetect.

t
fd

Finally type the following to write your changes.

w

Repeat this process for any other partitions.

 

Create RAID

Now we are ready to create our RAID.  Type the following command.

$ sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

Type Yes to acknowledge the warning regarding using this RAID device for booting.

You can follow the progress of your RAID creation with the following command

$ cat /proc/mdstat

Once the RAID is completed you should something like this...

Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
5237696 blocks super 1.2 [2/2] [UU]

unused devices: <none>

You can now format the RAID to EXT4.

$ sudo mkfs -t ext4 /dev/md0

You will now need to create a mount point directory, to which the new RAID will be attached.

$ sudo mkdir /mnt/STORAGE1

Finally you can add a new line in the etc/fstab file so that this partition will mount automatically.

$ sudo vi /etc/fstab
/dev/md0 /mnt/STORAGE1 ext4 defaults 1 2

To mount the RAID now type the following

$ sudo mount /mnt/STORAGE1

 

 

Thanks for visiting.