Hello everybody!
In this video, we’ll be creating a software RAID on a Linux platform.
In my previous videos, I have already shown you what is RAID, types of such disk arrays,
and how to build them.
From today’s video, you will learn how to build a RAID system on a Linux platform.
All right, if you want to create a RAID system, you need at least a few hard drives.
When building RAID on several physical drives, pay special attention to using storage devices
of the same capacity, or - ideally - that they should be of the same type and model.
One more thing to decide on before you start is which technology should be used.
There are three main options to choose from: a hardware RAID, a hybrid RAID (a combination
of hardware and software elements), and a software RAID.
The first two types require expensive RAID controllers and have one downside, critical
enough: if a RAID controller breaks down, restoring the array is only possible when
you replace it with the same model (which, as I said, is going to cost you pretty much
- much more than you would have to pay if you lost one of the hard drives in a typical
software RAID system).
In this video, we’ll be building a software RAID on a Linux Ubuntu 20.04 platform.
To create and manage a RAID system, you need a special utility, mdadm, which can be installed
with Synaptic, or with the command apt install mdadm
During the installation, you will be asked for settings required to manage the existing
or the future arrays.
To save yourselves the trouble of going deeper into this topic, leave all settings at their
default values.
Check if the hard drives are present.
Df -h Cat /proc/partitions
Here are the drives.
One of them marked as sda is where the operating system is installed, and others – sdb, sdc,
sdd - are the ones that will make up the RAID system.
Before the system is built, the hard drives need to be prepared for it.
Create partitions in the drives.
Type sudo fdisk /dev/sdb Use the P command to view partitions.
Create a new partition by typing n.
Specify the partition type: primary - press p, or extended - e.
The first partition - 1.
Leave the rest of the settings at default values and press Enter twice.
Now you can see that a new partition has been created.
Type P. Here is the partition I created - sdb1.
To record changes, press w - Enter.
The partition table has been modified, and now drive synchronization begins.
Repeat the same steps for the other two drives.
sudo fdisk /dev/sdс Check if the drive is empty - press P.
Create a new partition by typing n.
Specify that this is a primary partition - type p.
Partition number - 1.
Leave other items at default, press Enter twice.
Check if it was created successfully by pressing p.
Record changes by pressing w.
Now, to the third drive.
sudo fdisk /dev/sdd Press P to check it.
Press N to create a new partition.
Press P to set it as primary.
Partition number - 1.
Enter, enter Press P to check it.
Record changes by pressing w.
After all these actions, it is recommended to run the command sudo partprobe, and it
is especially relevant for Red Hat and centOS.
For Ubuntu, it’s not obligatory, as it is done automatically.
Once more, check for presence of drives, to see if the system registered them.
Cat /proc/partitions All right, you can see everything was successful.
Devices sdb1, sdc1 and sdd1 appeared.
Now we can start creating the array.
Type the command sudo mdadm --create /dev/md0 –a yes –l array level 5 (five) –n – number
of drives – 3 and specify the devices /dev/sdb1 /dev/sdc1 and dev/sdd1 – Enter.
sudo mdadm --create /dev/md0 -a yes -l 5 -n 3 /dev/sdb1 /dev/sdc1 /dev/sdd1
That’s all, the RAID system has been created.
Let’s view the drives Cat /proc/partitions
At the bottom of the list, you can see the partition md0 with the capacity of 200 GB.
The last step to take is to convert it to the file system mkfs
Mkfs.ext2 /dev/md0 The process begins; the table is saved; the
superblocks are written... wait until it is completed.
Ready.
After that, let’s mount the partition.
Mount /dev/md0 /mnt Df –h
Here is the mounted partition of 196 GB. 61 MB is in use and 186 GB is available.
To make sure it works properly, let’s create a file there.
Dd input file=/dev/zero output file=/mnt/file.mp4 block size=4096 and count=100 000
Dd if=/dev/zero of=/mnt/file.mp4 bs=4096 count=100000
Here’s the file we created, the size is 410 MB.
Let’s check the directory.
Go to mnt Cd /mnt/
Type ls to display what’s inside Type ls –l to see the details.
Here is our file of 410 MB, created with root.
Check the capacity of our drives by pressing df –h.
As you can see, 450 MB is used.
You can check the current state of the RAID system with the file /proc/mdstat:
type cat /proc/mdstat
(Eliminate problems and restore arrays)
Sometimes, certain failures make the array become inactive even if there are no drive
errors, but they are marked as being inactive.
Usually, it looks like this:
$ cat /proc/mdstat Personalities: [linear] [multipath] [raid0]
[raid1] [raid6] [raid5] [raid4] [raid10] md0: inactive sdd1[2](S) sdb1[1](S) sdc1[0](S)
2930287616 blocks unused devices:
There’s nothing to worry about, though, just stop the array with this command:
sudo mdadm --stop /dev/md0 And then reassemble it with another command:
sudo mdadm --assemble --scan --force
If a serious failure struck your array, for example, too many drives crashed, the array
will also get the inactive status; in this case, you can’t make it operable again by
reassembling; what is more, it can even harm your drives.
Be attentive, and if any issues arise, check the array condition and the condition of all
of its components in the first place.
In the end, don’t forget to mount the file system, because it won’t be done automatically
when you restart the array.
If your array used the command /etc/fstab, usually you can complete the mount operation
with the command sudo mount –a
(A critical fatal error while drives are in perfect condition)
Sometimes, there may be critical failures that become irreparable.
For example, when two drives within a RAID 5 system crash.
This makes the entire array inoperable, and at first sight, it seems there is no way to
recover the system.
If this disaster happened to your array: First of all, check the status of all array
elements by using this command: sudo mdadm -E /dev/sdc1
Instead of sdc1, type all elements of the RAID system, one after another.
Pay special attention to the last block in each case.
The second step should be checking SMART values for all drives and running surface tests.
It is important to make sure that the drives are physically sound, and that there are no
read errors.
You can test the drives with a special disk utility available in Linux.
Now try reassembling the array.
mdadm --assemble --scan
Summing up, implementation of software RAID on Linux lets you create disk arrays of several
levels, using both physical drives and logical partitions.
The functionality you get with this subsystem is quite sufficient to organize a data storage
system which is good enough in terms of reliability and performance.
That is all for now!
Hopefully, this video was useful.
Remember to click the Like button and subscribe to our channel.
Push the bell button to receive notifications and never miss new videos.
Leave comments to ask questions.
Thank you for watching.
Good luck.