Linux Software RAIDJune 16, 2022
Hardware RAID has many advantages. However, if you are not running a large infrastructure and don't really need the benefits of HW RAID for an enterprise solution, I prefer a software Linux RAID called mdadm because it offers many practical advantages. I'll describe the benefits and how to use mdadm in this tutorial.
You can find out what a RAID is at wikipedia. I'll just point out that people often confuse different terms and impressions, so it's a good idea to study the exact terms. RAID is not a backup. RAID is used to either consolidate disk space or to provide more service availability or better performance. Some motherboards are sold with RAID, but realistically, it's software RAID + Windows driver. Such a RAID is referred to as a fake RAID.
Which RAID to use? RAID 0, RAID 1, RAID 5, RAID 6, RAID 10. RAID 1 is the most typical choice due to data redundancy, ease of use and the need for only one extra disk. On the other hand, RAID 0 on its own is a completely inappropriate choice for server deployment because it reduces the security of data retention. Its use is only appropriate where we are willing to allow failure or loss of data - i.e. back up data.
You can find a verbal description of what RAID is and is not in this video:
Linux Software RAID
Linux software RAID, called mdadm, is a solution that is at the Linux kernel level.
Its main advantages are:
- stability .
- independence on HW
- ability to migrate between different HW and Linux distributions
By the way, if you need RAID, you can use not only mdadm but also the BTRFS filesystem or LVM technology.
The size of the partition is individual to your needs. You can use the tools fdisk, cfdisk, parted or the graphical gparted to partition.
How to partition? We can safely derive the partitioning from the existing system, but with RAID in mind, it may be more appropriate to choose just one large partition across the entire disk. The reason for a single partition with RAID on each disk is performance. This is because the RAID driver tries to optimize reads from the array and reads either from the first disk that does nothing or from the disk from which it last requested access to the nearest partition. (The situation is described for RAID1) Since the last area accessed is stored in the information about each RAID array, this algorithm will not behave very efficiently with multiple arrays on a single disk.
You can create an identical layout on a second disk simply by using this command:
sfdisk -d /dev/sda | sfdisk /dev/sdb
Creating a RAID
Creating RAID 1 from two disks
mdadm --create /dev/md1 l 1 -n 2 /dev/sda1 /dev/sdb2
You can then create, for example, a JFS filesystem on this newly created block device, mount the device in a directory structure and start saving data.
Create a RAID 5 that is supposed to have three disks, but we only have two so far:
mdadm --create /dev/md/data -l5 -n3 /dev/sdb3 /dev/sdd3 missing
Adding a disk
Add an unused new disk to the RAID:
mdadm /dev/md0 --add /dev/sdc1
The disk can be marked as defective by the system or we can mark it manually:
mdadm /dev/md0 --fail /dev/sdc1
Removing a faulty disk from the RAID:
mdadm /dev/md0 --remove /dev/sdb1 /dev/sdc1
If the disk is physically removed from the server it still needs to be removed from the RAID in the system. Because otherwise it will still be considered as used when connected to a PC.
It is a good idea to save the configuration of all RAIDs in a configuration file.
We can pro-scan the system and leave the output directly at the end of the configuration file:
mdadm --detail --scan >> /etc/mdadm/mdadm.confOr do the same for one specific disk array:
mdadm --detail /dev/md1 --brief >>/etc/mdadm.conf
It is also a good idea to have the mdadm service enabled:
systemctl enable mdadm.service
Swap a RAID
How to swap and RAID?
There are two approaches:
- put swap on RAID
- Put swap on RAID1
It is not advisable to put swap on a software RAID because of the possibility of deadlock that can occur when the system runs out of free memory. This has never happened to me personally.
If you are running a software RAID 1 to provide more availability and you don't put the swap on RAID1, then one disk dying will mean a failure. If you swap to RAID 1 it's fine.
I run swap on RAID1.
Checking RAID status
You can get a list and details of all RAIDs by using the following command:
Start the data check on the RAID:
echo "check" > /sys/block/md1/md/sync_action
Command to start RAID synchronization:
echo repair >/sys/block/md<#>/md/sync_action
The number of errors can be traced in this file of the respective RAID:
If your system does not automatically fold the disk array on boot, for example you are booting from a rescue CD, you can manually fold it with this command:
mdadm --assemble --verbose /dev/md1 /dev/sdb1
Stopping the RAID array:
mdadm --stop /dev/mdXi
Remove the RAID information from the disk:
mdadm --zero-superblock /dev/XDo this if you have invalidated the RAID on the disk. This will delete all RAID metadata and the system will no longer consider the disk to belong to a RAID.
If you are migrating the server to RAID you need to make sure you have updated the configuration in the boot loader, fstab file, and a new initramfs file generated, otherwise you will not be able to successfully boot.
Be sure to set up a boot loader (typically GRUB) and write it to all disks. Otherwise, you may have a problem booting the server if there is no bootloader anywhere.
Video tutorial on how to create a Linux software RAID1:
Other Resources and Topics
For more tutorials on linux servers, check out the ebook.
Next time I will elaborate on the information regarding Logical Volume Management.
Články na podobné téma
Backup: the Proxmox Backup Server
Linux as a router and firewall
How to upload a docker image to the Docker Registry
Linux: logical volume management
Running a web application behind a proxy
Docker multistage build
Importing Windows into Proxmox virtualization
Docker and PHP mail
Docker and Cron
How to address poor file share performance in Docker
How to get started using Docker correctly
GNU/Linux operating system
If you are interested in receiving occasional news by email.
You can register by filling in your email news subscription.