How to create software RAID in RHEL 7
When it comes to combining solid performance with reliability and recoverability, RAID is sure to show up. RAID is a widely used technology in mission-critical and enterprise environments. Today we’ll talk about software RAID in Linux.
Disclaimer: I take absolutely no responsibility for what you do following this tutorial, thus it is made only as a reference and for learning purpose.
Hardware or Software RAID?
In case you didn’t, I suggest you to read my introductory article about RAID. If you already have grasped the basics of RAID, feel free to skip it. So, when it comes to Hardware or Software RAID there are many things to consider, since today we’ll understand how to create a Software RAID we’ll briefly look at its advantages:
- Cheaper than Hardware RAID.
- Portable across similar systems.
- No Hardware Controller fault = easier maintenance.
- More manageable.
Many still stay that Hardware is superior to Software RAID, however the latter has improved a lot during the past few years.
Preparing the RAID
Before we start keep in mind the level you want to implement and the RAID level supported by your system. To verify the supported personalities (levels) issue:
$ cat /proc/mdstat Personalities : [raid6] [raid5] [raid4]
As you can see levels 4, 5 and 6 are supported in this system. If you don’t have the /proc/mdstat file it means your system doesn’t support RAID. It mostly depends on the kernel. Next thing you should do is verify that you have the right software installed, let’s check/install it by issuing:
# yum install -y mdadm
Initializing a new RAID
The command itself is simple, before however we truly create the array, we should take a look at the partitions we have. You can either choose to create a RAID on top of the whole disks or inside partitions (that can have almost the same extension as the disk capacity). Without much to say, I suggest you the latter, create a partition on each disk you want to use in the array. Be sure to:
- Specify the same size for each partition on each disk.
- Set the right identifier for the partition: FD00.
If you’re reading this I assume you already know how to partition disks, so we’ll skip directly to the RAID creation. The basic command is:
mdadm --create NAME --level LEVEL --raid-devices N [/dev/sdX1, /dev/vdX1...]
NAME is usually /dev/mdX with X as a number, LEVEL depends on your configuration, N is the number of devices you want to use. The last part of the command adds the disks (partitions in our case) to the raid. If everything goes fine you’ll see:
mdadm: array /dev/mdX started.
That’s it, now everything should be configured, however when you have multiple RAIDs on a machine, ambiguity can be a problem. If that’s the case you can do:
mdadm --detail --scan >> /etc/mdadm.conf
Notice that /etc/mdadm.conf isn’t usually found and should be created on the first occasion.
Managing RAID
Once you’ve create the raid, you will probably need to administer it. So let’s learn the most useful commands
cat /proc/mdstat # List many useful informations on installed RAIDs mdadm --query NAME # Shows brief details on NAME mdadm --detail NAME # Shows detailed information on NAME mdadm NAME -f DEVICE # Sets DEVICE as faulty in NAME array mdadm NAME -a DEVICE # Adds DEVICE to NAME array mdadm NAME -r DEVICE # Remove DEVICE from NAME array
These are the most common/used commands, I purposely avoided rebuild/resync commands which have complicated implications and are to be treated in another article.
Conclusion
You’ve learnt how to create and the basic commands associated with software RAID under Linux. Next time you set one, be sure to follow, messing with RAIDs can potentially compromise lots of data.
Image courtesy of Robert
- 2020 A year in review for Marksei.com - 30 December 2020
- Red Hat pulls the kill switch on CentOS - 16 December 2020
- OpenZFS 2.0 released: unified ZFS for Linux and BSD - 9 December 2020
Nice post – I published a similar blog post not that long ago.
https://fatmin.com/2015/12/29/rhel-7-setup-software-raid-via-mdadm/