RAID and How to Set It Up on Alibaba Cloud

By Hitesh Jethva, Alibaba Cloud Community Blog author.

RAID, or Redundant Array of Inexpensive Disks, is a data storage technology that combines multiple physical hard disk drive into one or more logical units to protect data in the case of a drive failure. RAID works by replicating data across two or more physical hard drives linked together by a RAID Controller. The RAID controller can be either hardware based or software based. RAID stores data on multiple disk drive and allow I/O operations to overlap in a balanced way to improve performance and increase fault tolerance. The disks can be combined into the array in different ways which are known as RAID levels. RAID technology can be used to prevent data loss, disk failure and also enhances business performance. You can also use RAID technology for SATA, SAS and SSD Drives.

RAID Storage Techniques

  • Striping: It is a method of splitting the flow of data into blocks and spreading the data blocks across multiple storage devices. This will increase the read/write performance of data.
  • Mirroring: It replicates the data into two or more disks. This method is very good for applications that require high performance and high availability.
  • Parity: This method is mainly used for fault tolerance by calculating the data in two drives and storing the results on a third.

Hardware and Software Implementations of RAID

A hardware implementation of RAID uses high-performance RAID Controller that is physically built using PCI express cards. Hardware RAID can be implemented using a complex standalone RAID controller. This controller can be equipped with their own CPU, battery-backed up cache memory, and typically this hardware setup supports hot-swapping. Hardware implementations of RAID allow you to install an operating system on top of it which can increase the uptime of the system. In these sorts of hardware implementations, logical disks are configured and mirrored outside of the system. A physical RAID controller manages the array, applications, and operating systems as logical units.

A software implementation of RAID can be used by the operating system driver. It is supported on most modern operating systems and is less costly and is a relatively more versatile option given a high level of capability with most operating systems out there. Software implementations of RAID perform the processing on the host’s CPU because it does not use the server processor. With the software implementation of RAID, you do not need to install physical hardware in software. Software RAID is much slower than Hardware RAID, because it uses CPU of the host computer manage the extra disk I/O.

RAID Levels

RAID0

RAID1

RAID5

RAID6

RAID10

Setting up RAID0 Array

Building off of what we discussed before, RAID0 provides high performance and zero fault tolerance. If any one of disk fails, you cannot recover the data. RAID0 is an ideal solution for non-critical storage of data where you have to be read/written at a high speed. You will need minimum two drives to implement RAID0 array.

Prerequisites

  • A newly created Alibaba Cloud ECS instance installed with Ubuntu 16.04.
  • A minimum of two hard drives that are attached to your instance.
  • A root password that is set up to your instance.

For reference purposes, see create a new ECS instance and connect to your instance. Also, once you are logged into your Ubuntu 16.04 instance, you can run the apt-get update -y command to update your base system with the latest available packages.

Getting Started

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 20969471 20467714 9.8G 5 Extended
/dev/sda5 501760 20969471 20467712 9.8G 8e Linux LVM
Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk /dev/sdc: 2 GiB, 2147483648 bytes, 4194304 sectors

Install Mdadm

Create RAID0 Array

mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc

The output is as follows:

mdadm: chunk size defaults to 512K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

You can now check the status of RAID array with the following command:

cat /proc/mdstat

You should see the following output:

Personalities : [raid0] 
md0 : active raid0 sdc[1] sdb[0]
4190208 blocks super 1.2 512k chunks

unused devices: <none>

You can also check the detail information about RAID array with the following command:

mdadm -E /dev/sd[b-c]

The output is as follows:

/dev/sdb:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : a4d636f7:eb05e54a:28cdb118:46076be1
Name : Node2:0 (local to host Node2)
Creation Time : Sun Nov 18 12:11:01 2018
Raid Level : raid0
Raid Devices : 2
Avail Dev Size : 4190208 (2046.34 MiB 2145.39 MB)
Data Offset : 4096 sectors
Super Offset : 8 sectors
Unused Space : before=4008 sectors, after=0 sectors
State : clean
Device UUID : 8b79b1f4:d313744a:5559fc18:cff176ba
Update Time : Sun Nov 18 12:11:01 2018
Bad Block Log : 512 entries available at offset 72 sectors
Checksum : 15bc99ce - correct
Events : 0
Chunk Size : 512K Device Role : Active device 0
Array State : AA ('A' == active, '.' == missing, 'R' == replacing)
/dev/sdc:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : a4d636f7:eb05e54a:28cdb118:46076be1
Name : Node2:0 (local to host Node2)
Creation Time : Sun Nov 18 12:11:01 2018
Raid Level : raid0
Raid Devices : 2
Avail Dev Size : 4190208 (2046.34 MiB 2145.39 MB)
Data Offset : 4096 sectors
Super Offset : 8 sectors
Unused Space : before=4008 sectors, after=0 sectors
State : clean
Device UUID : 528b5008:af0043f3:dbb81ab4:01c7cb32
Update Time : Sun Nov 18 12:11:01 2018
Bad Block Log : 512 entries available at offset 72 sectors
Checksum : e59dcd29 - correct
Events : 0
Chunk Size : 512K Device Role : Active device 1
Array State : AA ('A' == active, '.' == missing, 'R' == replacing)

You can also run the following command:

mdadm --detail /dev/md0

The output is as follows:

/dev/md0:
Version : 1.2
Creation Time : Sun Nov 18 12:11:01 2018
Raid Level : raid0
Array Size : 4190208 (4.00 GiB 4.29 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Sun Nov 18 12:11:01 2018
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K Name : Node2:0 (local to host Node2)
UUID : a4d636f7:eb05e54a:28cdb118:46076be1
Events : 0
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc

Create a Filesystem on RAID Array

You can do this by running the following command:

mkfs.ext4 /dev/md0

Next, create a mount point and mount the RAID array on this:

mkdir /opt/raid0
mount /dev/md0 /opt/raid0

Next, check the mounted RAID array with the following command:

df -h

The output is as follows:

Filesystem                  Size  Used Avail Use% Mounted on
udev 478M 0 478M 0% /dev
tmpfs 100M 3.3M 96M 4% /run
/dev/mapper/Node1--vg-root 9.0G 5.8G 2.8G 69% /
tmpfs 497M 4.0K 497M 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 236M 85M 139M 38% /boot
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 100M 0 100M 0% /run/user/0
/dev/md0 3.9G 8.0M 3.7G 1% /opt/raid0

Next, you will need to configure /etc/mdadm/mdadm.conf file to reassembled the RAID array automatically at boot time. You can do this by running the following command:

mdadm --detail --scan | tee -a /etc/mdadm/mdadm.conf

The output will be as so:

ARRAY /dev/md0 metadata=1.2 name=Node2:0 UUID=a4d636f7:eb05e54a:28cdb118:46076be1

Next, update the initramfs to apply the changes with the update-initramfs -u command. Next, you will need to create a mount point for /dev/md0 in /etc/fstab file for automatic mounting at boot:

nano /etc/fstab

Add the following command:

/dev/md0  /opt/raid0     ext4    defaults,nofail,discard   0  0

Save and close the file, when you are finished.

Delete RAID0 Array

umount /dev/md0

Next, deactivate the RAID device with the following command:

mdadm --stop /dev/md0

The output is as follows:

mdadm: stopped /dev/md0

Finally, remove the superblocks from all disks with the following command:

mdadm --zero-superblock /dev/sdb /dev/sdc

Now, check the status of RAID array with the following command:

cat /proc/mdstat

The output is as follows:

Personalities : [raid0] 
unused devices: <none>

Setting Up RAID6 Array

As discussed before, RAID6 is an upgraded version of RAID5, where the parity data are written to two drives. RAID6 stores two parity records to different disk drives that enable two simultaneous disk drive failures in the same RAID group to be recovered. RAID6 provides high performance in read operations, but poor performance in write operations. RAID6 provides fault tolerance, even after two disk fails. You can rebuilt data from parity after replacing the failed disk. You will need a minimum of four disks to implement RAID6 array.

Prerequisites

  • A fresh Alibaba Cloud Ubuntu 16.04 instance.
  • Minimum four extra hard drives are attached to your instance.
  • A root password is set up to your instance.

For reference, see create a new ECS instance and connect to your instance. Also, once you are logged into your Ubuntu 16.04 instance, run the apt-get update -y command to update your base system with the latest available packages.

Getting Started

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 20969471 20467714 9.8G 5 Extended
/dev/sda5 501760 20969471 20467712 9.8G 8e Linux LVM
Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk /dev/sdc: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk /dev/sdd: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk /dev/sde: 2 GiB, 2147483648 bytes, 4194304 sectors

Install Mdadm

Create RAID6 Array

mdadm --create --verbose /dev/md0 --level=6 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde

The output is as follows:

mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 2095104K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

You can now check the status of RAID array with the following command:

cat /proc/mdstat

You should see the following output:

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid6 sde[3] sdd[2] sdc[1] sdb[0]
4190208 blocks super 1.2 level 6, 512k chunk, algorithm 2 [4/4] [UUUU]

unused devices: <none>

You can also check the detail information about RAID array with the following command:

mdadm --detail /dev/md0

The output is as follows:

/dev/md0:
Version : 1.2
Creation Time : Sun Nov 18 13:03:32 2018
Raid Level : raid6
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sun Nov 18 13:04:35 2018
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : Node2:0 (local to host Node2)
UUID : e7d5fc59:661516bc:3b1001a4:8cd03659
Events : 17
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
2 8 48 2 active sync /dev/sdd
3 8 64 3 active sync /dev/sde

Create a Filesystem on RAID Array

You can do this by running the following command:

mkfs.ext4 /dev/md0

Next, create a mount point and mount the RAID array on this:

mkdir /opt/raid6
mount /dev/md0 /opt/raid6

Next, check the mounted RAID array with the following command:

df -h

The output is as follows:

Filesystem                  Size  Used Avail Use% Mounted on
udev 478M 0 478M 0% /dev
tmpfs 100M 3.3M 96M 4% /run
/dev/mapper/Node1--vg-root 9.0G 5.8G 2.8G 69% /
tmpfs 497M 4.0K 497M 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 236M 85M 139M 38% /boot
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 100M 0 100M 0% /run/user/0
/dev/md0 3.9G 8.0M 3.7G 1% /opt/raid6

Next, you will need to configure /etc/mdadm/mdadm.conf file to reassembled the RAID array automatically at boot time. You can do this by running the following command:

mdadm --detail --scan | tee -a /etc/mdadm/mdadm.conf

The output is as follows:

ARRAY /dev/md0 metadata=1.2 name=Node2:0 UUID=e7d5fc59:661516bc:3b1001a4:8cd03659

Next, update the initramfs to apply the changes with the following command:

update-initramfs -u

Next, you will need to create a mount point for /dev/md0 in /etc/fstab file for automatic mounting at boot:

nano /etc/fstab

Add the following command:

/dev/md0  /opt/raid6     ext4    defaults,nofail,discard   0  0

Add a Spare Drives to RAID Array

First, shutdown the system and add a spare drive.

Next, add the spare drive (/dev/sdf) to RAID6 array with the following command:

mdadm --add /dev/md0 /dev/sdf

Next, check the added device with the following command:

mdadm --detail /dev/md0

The output is as follows:

/dev/md0:
Version : 1.2
Creation Time : Sun Nov 18 13:03:32 2018
Raid Level : raid6
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Sun Nov 18 13:20:49 2018
State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : Node2:0 (local to host Node2)
UUID : e7d5fc59:661516bc:3b1001a4:8cd03659
Events : 18
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
2 8 48 2 active sync /dev/sdd
3 8 64 3 active sync /dev/sde
4 8 80 - spare /dev/sdf

Test RAID6 Fault Tolerance

You can mark /dev/sdc as a failed drive with the following command:

mdadm --manage --fail /dev/md0 /dev/sdc

The output is as follows:

mdadm: set /dev/sdc faulty in /dev/md0

Now, check the details of RAID6 array with the following command:

mdadm --detail /dev/md0

You should see the faulty drive and spare rebuilding process in the following output:

/dev/md0:
Version : 1.2
Creation Time : Sun Nov 18 13:03:32 2018
Raid Level : raid6
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Sun Nov 18 13:25:59 2018
State : clean, degraded, recovering
Active Devices : 3
Working Devices : 4
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Rebuild Status : 57% complete Name : Node2:0 (local to host Node2)
UUID : e7d5fc59:661516bc:3b1001a4:8cd03659
Events : 29
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
4 8 80 1 spare rebuilding /dev/sdf
2 8 48 2 active sync /dev/sdd
3 8 64 3 active sync /dev/sde
1 8 32 - faulty /dev/sdc

Original Source

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.