RAID uses disc mirroring or disc striping methods, mirroring on more than one drive would copy similar data. Partition striping allows distributing data across many disc drives. The storage capacity of each drive is split into units that range from a sector (512 bytes) up to multiple megabytes. RAID levels higher than RAID 0 offer protection against unrepairable read errors in the field, as well as against entire physical drive failures.
The RAID devices are deployed via the application driver md. The Linux software RAID array currently supports RAID 0 (strip), RAID 1 (mirror), RAID 4, RAID 5, RAID 6, and RAID 10. Mdadm is a Linux utility used to control and manage RAID devices for applications. Several core operating modes of mdadm are assembled, build, create, follow, monitor, grow, incremental and auto-detect. The name derives from the nodes of the multiple devices (md) that it controls or manages. Let’s look at creating different kinds of Raid arrays using mdadm.
Creating a RAID 0 array:
RAID 0 is the mechanism by which data is separated into blocks, and those blocks are scattered through various storage devices like hard drives. Means that each disc holds a portion of the data and while accessing that data, several discs would be referenced. In raid 0, as blocks are striped, its performance is excellent, but due to no mirroring strategy, a single failure of the device would destroy all the data.
In order to get started, you have to first identify the component devices by using the following command:
We have two discs without a filesystem, each 50G in size, as we can see from the screenshot. In this case, the identifiers /dev/ch1 and /dev/ch2 were given to these devices for this session. These are raw components that we are going to use to create the array.
To use these components to create a RAID 0 array, specify them in –create command. You’ll need to define the system name that you want to build (in our case, /dev/mch0), the RAID level, i.e. 0, and the number of devices:
--raid-devices=2 /dev/ch1 /dev/ch2
By testing the /proc/mdstat log, we can guarantee that the RAID was created successfully:
The /dev/mch0 system has been created with the /dev/ch2 and /dev/ch1 devices in the RAID 0 setup. Now mount the file system on that array using the following command:
Now, Create a mount point and mount the filesystem by the following commands:
Check if there is any new space available or not:
Now we have to change the /etc/mdadm/mdadm.conf file to make sure the list is automatically reassembled at boot. You will search the current array automatically, connect the file and update the initial RAM filesystem by the following sequence of commands :
[email protected]:~$ sudo update-initramfs -u
In order to mount automatically at boot, add new file system mount options in etc/fstab file available:
Each boot can now automatically add your RAID 0 array and mount it.
Creating a RAID 5 array:
Raid 5 arrays are created by stripping the data along with various devices. A measured parity block is one part of each stripe. The parity block and the remaining blocks will be used to determine the missing data in case the device fails. The system obtaining the parity block is rotated such that there is a balanced sum of parity information for each device. While the info about parity is shared, the storage value of one disc can be used for parity. When in a damaged state, RAID 5 will suffer from very poor results.
For creating the RAID 5 array, we have to first identify the component devices as we identified in RAID 0. But in RAID 5 we should have at least 3 storage devices. Find the identifiers for these devices by using the following command:
Use the –create command to create a RAID 5 array but use the value 5 for “level” in this case.
--raid-devices=3 /dev/sda /dev/sdb /dev/sdc
This can take a certain time to complete, even during this time, the array may be used. By testing the /proc/mdstat log, you can track the progress of creation:
Now, create and mount the filesystem on the array by executing the following sequence of commands:
[email protected]:~$ sudo mkdir -p /mnt/md0
[email protected]:~$ sudo mount /dev/md0 /mnt/md0
After mounting this, you can confirm whether it is accessible or not::
For automatic assembling and mounting of RAID 5 arrays at each boot, you have to adjust the initramfs and add the recently created filesystem to fstab file by executing these commands:
Conclusion:
RAID provides efficiency and stability by combining multiple hard drives together. In that way, it gives the system one large capacity hard drive with a much better speed than normal partitioned drives. On the other hand, it doesn’t facilitate redundancy and fault tolerance, and in case, one drive fails all of the data is lost.