In this article, we will show you how to configure a RAID5 volume on a Linux server.
On a server, it's useful to configure RAID 5 storage to store data. A large storage capacity can be achieved by combining multiple hard drives, and the possibility of losing one drive without data loss is mitigated.
Indeed, whether it's speed or storage, the entire storage volume will operate at the speed and volume of the slowest.
RAID5 configuration
Before starting the configuration, it is necessary to install the package (if this has not already been done):
sudo apt update && sudo apt install mdadm
Once installed, it is necessary to identify the hard drives that will be used to create the RAID.
Type the command below to display the list of disks:
sudo fdisk -l
The list of hard drives connected to the machine is then displayed.
Locate the relevant discs and note their names.
If you want to create a cluster with the boot disk, use a RAID 1 array rather than a RAID 5 array.
We will take as an example 3 hard drives which will be used in the RAID5 array: sdb, sdc, sdd.
It will be necessary to adapt the procedure according to the name of the disks and their number.
Once identified, format the hard drives to clean them of any old configuration.
All data on these disks is irretrievably lost.
Check carefully before formatting the hard drives.
sudo wipefs -a /dev/sdb
sudo wipefs -a /dev/sdc
sudo wipefs -a /dev/sdd
Once that's done, finally create the RAID5 volume with the following command:
udo mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
We will now review the arguments of the command:
- --create /dev/md0
- System location that will contain the RAID5.
- This location will be used for mount points, leave in /dev/, which is the folder for the list of devices available on the machine.
- --level=5
- RAID level specified.
- If RAID6, then enter 6 here.
- --raid-devices=3
- Number of hard drives that will be added to the volume
Sometimes mdadm will ask for confirmation before creating the RAID. If this happens, you can confirm without further action.
To monitor the progress of the RAID initialization, type the following command:
watch -n 2 cat /proc/mdstat
During RAID initialization, it is possible to format the RAID volume.
For formatting, in ext4:
sudo mkfs.ext4 -L RAID5 /dev/md0
For XFS formatting
sudo mkfs.xfs -L RAID5 /dev/md0
Once finished, mount the RAID storage.
In our example, the storage will be mounted in the /mnt/raid5 directory:
sudo mkdir -p /mnt/raid5 sudo mount /dev/md0 /mnt/raid5
Make the configuration permanent
On the next startup, the configuration will be lost, because mdadm does not store the newly created RAID information by default.
To do this, save the configuration with this command:
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u
In fstab (automated disk/partition mounting system under Linux), it is necessary to add a new line so that the RAID5 volume is mounted automatically at boot.
Execute the following command to add the following line:
echo '/dev/md0 /mnt/raid5 ext4 defaults,nofail 0 0' | sudo tee -a /etc/fstab
For the XFS version:
echo '/dev/md0 /mnt/raid5 xfs defaults,nofail 0 0' | sudo tee -a /etc/fstab
Useful commands
Below are some useful commands for working with RAID storage:
Display the RAID status
cat /proc/mdstat
Full details on RAID volume configuration
sudo mdadm --detail /dev/md0
Check the health of the RAID
sudo mdadm --examine /dev/sdb
Stop the RAID volume
sudo mdadm --stop /dev/md0
Start the RAID volume
sudo mdadm --assemble --scan

