How to do it…
Creating an MD device is fairly simple. But before you create the device, you need to plan a few things in advance:
- What type of RAID will you be using? As mentioned previously, the MD kernel driver supports many types of RAID algorithms. You need to pick one before running the command. This maps to the –level option.
- How many drives will you be using in the device? Most RAID types use even numbers of disks, but you still need to know how many disks will be used for data. This maps to the –raid-devices option.
- Will you configure a hot spare device? Hot spares are a great option when systems need to automatically rebuild the data if a device fails. It’s not uncommon in remote locations to have many hot spares. When picking hot spares, balance the required space versus how long it will take for a replacement to be installed. This maps to the –spare-devices option.
- What is the number of the MD device? Traditionally, you start with 0 and work your way up, but track the numbers so you do not accidentally use the wrong device. This maps to /dev/md#.
- What are the paths to the drives that you are going to use? They are normally /dev/sd#, /dev/nvme#, or even /dev/vd#.
In the following example, we will create a RAID-5 array with one hot spare. The device being used is /dev/sd[bcdef] and this will be the /dev/md0 device:
mdadm –create /dev/md0 –level=5 –raid-devices=4 –spare-devices=1 /dev/sd[bcdef]
You can quickly check the status by cating the /proc/mdstat file:
Figure 4.17 – /proc/mdstat
The last step, while optional, is highly recommended. This will save the current config to the mdadm configuration file. This helps the kernel assemble the array at boot. This is done with the following command:
mdadm –examine –scan >> /etc/mdadm.conf
How it works…
Now, let’s look at a few things about the MD device. First, if we use the lsblk command, we will see that the disks used by md0 are now identified as having md0 as children. This is because md0 is a child of the actual disk:
Figure 4.18 – lsblk command output
We can also check the device with the -Q option to the mdamd command. Simply pass the device as a parameter, and the command will give you a short summary:
mdadm -Q /dev/md0
The output is as follows:
Figure 4.19 – mdadm -Q
Optionally, you can pass the –-detail option to get significantly more information about the array:
Figure 4.20 – mdadm –detail
Here, we can see not only the health of the array but also its creation date and lower-level metrics such as block size and layout.
Once the volume is created, you can now use it for filesystems or as storage for a logical volume manager.